-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtikslus_notyrious.js
432 lines (309 loc) · 16.3 KB
/
tikslus_notyrious.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/*
Tikslus notyrious version 1.0.0 by Puspendra Singh Chouhan (www.tikslus.com)
jquery notification plugin
*/
(function($){
$.fn.tikslusnotyrious = function(options){
var skins=new Array();
var timers=[];
var prog=[];
var stayinterval=0;
var msgids=[];
skins['default_left']="<div class='tikslus_wrapper'><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div></div>";
skins['default_center']="<div class='tikslus_wrapper'><div class='tikslus_picture'>@picture</div><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div></div>";
skins['default_right']="<div class='tikslus_wrapper'><div class='tikslus_picture'>@picture</div><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div></div>";
skins['apollo_left']="<div class='tikslus_wrapper'><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div></div>";
skins['apollo_center']="<div class='tikslus_wrapper'><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div></div>";
skins['apollo_right']="<div class='tikslus_wrapper'><div class='tikslus_picture'>@picture</div><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div></div>";
skins['titan_left']="<div class='tikslus_wrapper'><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div></div>";
skins['titan_center']="<div class='tikslus_wrapper'><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div></div>";
skins['titan_right']="<div class='tikslus_wrapper'><div class='tikslus_picture'>@picture</div><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='progress'></div></div>";
skins['demeter_left']="<div class='tikslus_wrapper'><div class='tikslus_content'><div class='title'>@title</div><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='btns'><ul class='user_buttons'>@buttons</ul></div><div class='progress'></div></div>";
skins['demeter_center']="<div class='tikslus_wrapper'><div class='tikslus_content'><div class='title'>@title</div><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='btns'><ul class='user_buttons'>@buttons</ul></div><div class='progress'></div></div>";
skins['demeter_right']="<div class='tikslus_wrapper'><div class='tikslus_picture'>@picture</div><div class='tikslus_content'><div class='title'>@title</div><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div><div class='progress'></div></div>";
skins['hades_left']="<div class='tikslus_wrapper'><div class='tikslus_content'><div class='title'>@title</div><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div></div>";
skins['hades_center']="<div class='tikslus_wrapper'><div class='tikslus_content'><div class='title'>@title</div><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div></div>";
skins['hades_right']="<div class='tikslus_wrapper'><div class='tikslus_picture'>@picture</div><div class='tikslus_content'><div class='title'>@title</div><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul></div></div>";
skins['zeus_left']="<div class='tikslus_wrapper'><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div></div>";
skins['zeus_center']="<div class='tikslus_wrapper'><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div></div>";
skins['zeus_right']="<div class='tikslus_wrapper'><div class='tikslus_picture'>@picture</div><div class='tikslus_content'><span class='title'>@title</span><span class='close'><a href='#' class='close'>x</a></span><p>@content</p></div><div class='progress'></div></div>"
skins['hera_left']="<div class='tikslus_wrapper'><div class='tikslus_content'><div class='title'>@title</div><p>@content </p></div><div class='tikslus_picture'>@picture</div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul><ul><li class='closenotification'><a href='#' class='close'>Close</a></li></ul></div></div>";
skins['hera_center']="<div class='tikslus_wrapper'><div class='tikslus_picture'>@picture</div><div class='tikslus_content'><div class='title'>@title</div><p>@content </p></div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul><ul><li class='closenotification'><a href='#' class='close'>Close</a></li></ul></div></div>";
skins['hera_right']="<div class='tikslus_wrapper'><div class='tikslus_picture'>@picture</div><div class='tikslus_content'><div class='title'>@title</div><p>@content </p></div><div class='progress'></div><div class='btns'><ul class='user_buttons'>@buttons</ul><ul><li class='closenotification'><a href='#' class='close'>Close</a></li></ul></div></div>";
var defaults=
{
skin:'default',
skinPath:'',//include a trailing /
position:'right',
message:null,
animationDuration:500,
sticky:true,
buttons:new Object(),
stayInterval:10000,
picture:null
};
options = $.extend(defaults, options);
var skin;
if(options.skinPath==""){
$("head").append("<link rel='stylesheet' href='"+options.skin+".css' />");
}else{
$("head").append("<link rel='stylesheet' href='"+options.skinPath+options.skin+".css' />");
}
function init_messages(){
switch(options.position){
case "left":
$(".tikslus_notify").find("li.open").css({left:"-120%"});
break;
case "right":
$(".tikslus_notify").find("li.open").css({right:"-120%"});
break;
case 'center':
$(".tikslus_notify").find("li.open").css({width:0});
break;
default:
$(".tikslus_notify").find("li.open").css({left:"-120%"});
break;
}
}
//create buttons
function CreateButtons()
{
var buttonHTML = '';
if(options.buttons)
{
$.each(options.buttons,function(name,obj){
// Generatr markup for the buttons:
buttonHTML += '<li><a href="#" name="'+name+'" class="button '+obj['button_class']+'">'+name+'<span></span></a></li>';
if(!obj['action']){
obj['action'] = function(){};
}
});
}
if(buttonHTML=="" || buttonHTML==undefined || buttonHTML==null)
return(false);
else
return(buttonHTML);
};
function animate_progress(id,ind)
{
// var items=$(".tikslus_notify >li");
var li=$(".tikslus_notify").find("#"+id);
// var num=items.index(li);
if(li.length>0){
var li_width=li.width();
var li_timer=options.stayInterval*(ind+1);
var progress=li.find(".progress");
var current_progress=progress.width();
var sec=li_timer/100;
var p=li_width/sec;
if(current_progress<li_width){
progress.css({width:(current_progress+p)+"px"});
}else{
window.clearInterval(prog[id]);
li.addClass("rotate-out").fadeOut("slow",function(){
li.remove();
msgids.pop(li.attr("id"));
});
}
}
};
function close_message(id){
var li=$(".tikslus_notify").find("#"+id);
var listItem = document.getElementById( id );
var ind=$( "li" ).index( listItem );
var progress=li.find(".progress");
var li_width=li.width();
var progress_width=progress.width();
if(progress_width<li_width){
progress.css({width:li_width + "px"});
}
window.clearInterval(timers[id]);
};
function animate_message(obj,duration){
switch(options.position){
case 'left':
obj.stop().animate({left:10},duration);
break;
case 'right':
obj.stop().animate({right:10},duration);
break;
case 'center':
obj.stop().animate({width:356},duration);
break;
default:
obj.stop().animate({left:10},duration);
}
};
function isImgValid(url,HTML){
HTML = HTML || false;
if(url==null || url==undefined){
if(HTML==true) return "";
if(HTML==false) return false;
}
var arr = [ "jpeg", "jpg", "gif", "png" ];
var rtn=false;
var ext = url.substring(url.lastIndexOf(".")+1);
if($.inArray(ext,arr)){
rtn=true;
}
if(HTML==true && rtn==true){
return "<img src='"+url+"' class='responsive_img' />";
}
if(HTML && rtn==false){return "";};
if(HTML==false && rtn){return true;};
if(HTML==false && rtn==false) {return false;}
};
$.fn.closenotification=function(obj){
var li=obj.closest("li.closed");
li.addClass("rotate-out").fadeOut("slow",function(){
li.remove();
msgids.pop(li.attr("id"));
});
};
function append_message(messagePosition,skinName,skinHTML){
switch(messagePosition){
case 'left':
$(".tikslus_notify_vertical_vleft").append("<li class='open "+skinName+"' >"+skinHTML+"</li>");
break;
case 'right':
$(".tikslus_notify_vertical_vright").append("<li class='open "+skinName+"' >"+skinHTML+"</li>");
break;
case 'center':
$(".tikslus_notify_vertical_vcenter").append("<li class='open "+skinName+"' >"+skinHTML+"</li>");
break;
default:
$(".tikslus_notify_vertical_vright").append("<li class='open "+skinName+"' >"+skinHTML+"</li>");
}
};
if(options.position=="left"){
if($("body").find(".tikslus_notify_vertical_vleft").length==0){
$("body").append('<ul class="tikslus_notify_vertical_vleft tikslus_notify"></ul>');
}
skin=skins[options.skin +"_"+"left"];
}else if(options.position=="right"){
if($("body").find(".tikslus_notify_vertical_vright").length==0){
$("body").append('<ul class="tikslus_notify tikslus_notify_vertical_vright"></ul>');
}
skin=skins[options.skin +"_"+"right"];
}else if(options.position=="center"){
if($("body").find(".tikslus_notify_vertical_vcenter").length==0){
$("body").append('<ul class="tikslus_notify tikslus_notify_vertical_vcenter"></ul>');
}
skin=skins[options.skin +"_"+"center"];
}
else if(options.position=="top"){
if($("body").find(".tikslus_notify_horizontal").length==0){
$("body").append('<ul class="tikslus_notify tikslus_notify_horizontal notify_htop"></ul>');
}
skin=skins[options.skin +"_"+"top"];
}
else if(options.position=="bottom"){
if($("body").find(".tikslus_notify_horizontal").length==0){
$("body").append('<ul class="tikslus_notify tikslus_notify_horizontal notify_hbottom"></ul>');
}
skin=skins[options.skin +"_"+"top"];
}
else{
if($("body").find(".tikslus_notify_vertical_vright").length==0){
$("body").append('<ul class="tikslus_notify tikslus_notify_vertical_vright"></ul>');
}
skin=skins[options.skin +"_"+"left"];
}
if(options.message instanceof Array){
for(var i=0; i<options.message.length;i++)
{
var tempskin=skin;
var m=options.message[i];
if(m instanceof Object){
tempskin=tempskin.replace("@content",m.message);
if(m.hasOwnProperty("title")){
tempskin=tempskin.replace("@title",m['title']);
}else{
tempskin=tempskin.replace("@title","");
}
if(m.hasOwnProperty("picture")){
tempskin=tempskin.replace("@picture","<img src='"+m['picture']+"' class='responsive_img' />");
}else{
tempskin=tempskin.replace("@picture","");
}
if(options.stayInterval>0){
stayinterval=options.stayInterval;
}
append_message(options.position,options.skin,tempskin);
}
}
}else if(options.message instanceof Object){
skin=skin.replace("@content",m['message']);
skin=skin.replace("@title",m['title']);
skin=skin.replace("@picture","<img src='"+m['picture']+"' class='responsive_img' />");
append_message(options.position,options.skin,skin);
}else{
skin=skin.replace("@content",options.message);
skin=skin.replace("@title",'');
skin=skin.replace("@picture",isImgValid(options.picture,true));
if(options.buttons){
var user_buttons=CreateButtons();
skin=skin.replace("@buttons",user_buttons);
}
append_message(options.position,options.skin,skin);
}
$(".tikslus_notify li").each(function(){
var imga=$(this).find(".tikslus_picture img");
var contenta=$(this).find(".tikslus_content");
var usr_buttons=$(this).find(".user_buttons");
var title=$(this).find(".title");
if(imga.length==0){
imga.remove();
contenta.css({maxWidth:"100%",width:'100%'});
}
if(usr_buttons.children().length<=0){
usr_buttons.remove();
}
if(title.text()==""){
title.css({padding:0});
}
});
//create user defined buttons
init_messages();
var total=$(".tikslus_notify").find("li.open").length;
var items=$(".tikslus_notify >li.open");
$($(".tikslus_notify").find("li.open").get().reverse()).each(function(i){
var rnd=Math.random(1);
var rndid="message"+Math.ceil(rnd*100000);
msgids.push(rndid);
$(this).attr("id",rndid);
var ind=items.index($(this))
animate_message($(this),options.animationDuration/(total-i+1)*total);
$(this).removeClass('open').addClass("closed");
if(options.sticky==false){
timers[rndid]=window.setInterval(function(){close_message(rndid);},options.stayInterval*(ind+1));
prog[rndid]=window.setInterval(function(){animate_progress(rndid,ind);},100);
}
});
//event handling for user created buttons
//try to execute callback if any and close the dialog
$.each(options.buttons,function(name,obj){
for(var i=0;i<msgids.length;i++)
{
var btnobj=$("#"+msgids[i]);
btnobj.find(".user_buttons a").click(function(){
var nn=$(this).attr("name");
// Calling the action attribute when a
// click occurs, and hiding the confirm.
if(nn==name){
// obj.action();
obj.action(undefined != arguments[0] ? arguments[0] : '');
return false;
}
});
}
});
$(".closenotification, .btn a.close,.tikslus_wrapper a.close").click(function(e){
e.preventDefault();
$.fn.closenotification($(this));
var id=$(this).closest("li").attr("id");
if(id in prog){window.clearInterval(prog[id]);}
if(id in timers){window.clearInterval(timers[id]);}
});
};
})(jQuery);