-
Notifications
You must be signed in to change notification settings - Fork 0
/
materialNotify.js
65 lines (54 loc) · 1.73 KB
/
materialNotify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var notifyArray = [];
function notify(txt, time, isRed, functionOnDone) {
$('<div style="' + "background-color:" + ((isRed) ? "#ef394e" : "#009688") + '" class="topAlert">' + txt + '<span class="close closeNotify">x</span><p class="alertBottomProgress"></p></div>').appendTo("body");
var el = $(".topAlert:last");
var id = (new Date()).getTime();
var bottomProgress = el.find(".alertBottomProgress");
var obj = { id: id, el: el };
el.find(".closeNotify").click(function () {
removeTopAlert(obj, 200);
if (typeof functionOnDone !== 'undefined') {
functionOnDone();
functionOnDone = undefined;// To impede call it again after
}
})
notifyArray.push(obj);
bottomProgress.animate({ width: "100%" }, time * 1000, function () {
removeTopAlert(obj, 700);
if (typeof functionOnDone !== 'undefined') {
functionOnDone();
}
});
setTopAlertsIndent();
}
function removeTopAlert(obj, speed) {
obj.el.animate({ opacity: "0" }, speed, function () {
removeFromArray(notifyArray, obj);
obj.el.remove();
setTopAlertsIndent();
});
}
function setTopAlertsIndent() {
var lnt = notifyArray.length;
var topIndent = 0;
for (var i = lnt - 1; i >= 0; i--) {
var tempEl = notifyArray[i].el;
tempEl.animate({ top: topIndent + 'px' }, 190);
topIndent += tempEl.height() + 30;
}
}
function removeFromArray(arr, item) {
for (var i = arr.length; i--;) {
if (arr[i] === item) {
arr.splice(i, 1);
}
}
}
notify("Alert text", 10, true);
notify("Success text", 10, false);
setTimeout(function(){
notify("Alert text after 3 seconds ", 7, true);
notify("Success text after 3 seconds", 10, false, function(){
notify("On done function test", 10, false);
});
}, 3000);