-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf_clone_Notify.js
149 lines (113 loc) · 3.4 KB
/
f_clone_Notify.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var sNotify = {
timeOpen: 10, //change this number to the amount of second you want the message opened
queue: new Array(),
closeQueue: new Array(),
addToQueue: function(msg) {
sNotify.queue.push(msg);
},
/* Single time alerts fro the notifications Added By Anil on 18th March 2011 */
alterNotifications: function(msg) {
$.ajax({ url: 'jquery_sub.php',
data: {message : msg},
type: 'post',
success: function(output) {
//alert(output);
}
});
},
/* Single time alerts fro the notifications Added By Anil on 18th March 2011 */
createMessage: function(msg) {
//create HTML + set CSS
var messageBox = $("<div class=\"sNotify_block\" ><span class=\"sNotify_close\"></span>" + msg + "</div>").prependTo("body");
$(messageBox).addClass("sNotify_message");
sNotify.enableActions(messageBox);
sNotify.closeQueue.push(0);
return $(messageBox);
},
loopQueue: function() {
//pop queue
if (sNotify.queue.length > 0) {
var messageBox = sNotify.createMessage(sNotify.queue[0]);
sNotify.popMessage(messageBox);
sNotify.queue.splice(0,1);
}
//close queue
if (sNotify.closeQueue.length > 0) {
var indexes = new Array();
for (var i = 0; i < sNotify.closeQueue.length; i++) {
sNotify.closeQueue[i]++;
if (sNotify.closeQueue[i] > sNotify.timeOpen) {
indexes.push(i);
}
}
//now close them
for (var i = 0; i < indexes.length; i++) {
var buttons = $(".sNotify_close");
sNotify.closeMessage($(buttons[($(buttons).length - indexes[i]) - 1]));
sNotify.closeQueue.splice(indexes[i],1);
}
}
},
enableActions: function(messageBox) {
//reset timer when hovering
$(messageBox).hover(
function() {
var index = ($(this).nextAll().length - 1);
sNotify.closeQueue[index] = -1000;
},
function() {
var index = ($(this).nextAll().length - 1);
sNotify.closeQueue[index] = 0;
}
);
//enable click close button
$(messageBox).find(".sNotify_close").click(function() {
sNotify.closeMessage(this);
});
},
popMessage: function(messageBox) {
$(messageBox).css({
marginRight: "-290px",
opacity: 0.2,
display: "block"
});
var height = parseInt($(messageBox).outerHeight()) + parseInt($(messageBox).css("margin-bottom"));
$(".sNotify_message").next().each(function() {
var topThis = $(this).css("top");
if (topThis == "auto") {
topThis = 0;
}
var newTop = parseInt(topThis) + parseInt(height);
$(this).animate({
top: newTop + "px"
}, {
queue: false,
duration: 600
});
});
$(messageBox).animate({
marginRight: "20px",
opacity: 1.0
}, 800);
},
closeMessage: function(button) {
var height = parseInt($(button).parent().outerHeight()) + parseInt($(button).parent().css("margin-bottom"));
$(button).parent().nextAll().each(function() {
var topThis = $(this).css("top");
if (topThis == "auto") {
topThis = 0;
}
var newTop = parseInt(topThis) - parseInt(height);
$(this).animate({
top: newTop + "px"
}, {
queue: false,
duration: 300
});
});
$(button).parent().hide(200, function() {
$(this).remove();
});
}
}
setInterval("sNotify.loopQueue()", 900);