-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnotiJ.js
110 lines (89 loc) · 2.78 KB
/
notiJ.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
//NotiJ v1.0.0 by Nalinda Jayasinghe
//URL : https://github.com/nalindaDJ/notiJ
(function( $ )
{
$.notij=function(msg, options, callback) { return $.fn.notij(msg, options, callback); };
$.fn.notij = function(msg, options, callback){
var settings={
'speed': 'fast', // fast, slow, or number eg: 100
'multiple': true,
'autoclose': 5000, //set timeout speed
'onfocusdelay': true, //keep dialog open
'onclose': null, // onclose event
'theme' : 'default', // default, error,info
'msgstyle': null
};
//adding DOM html to msg if dom specified.
if(!msg){msg=this.html();}
//merging settings with given options
if(options){ $.extend(settings,options);}
var display=true;
var isMultiple="no";
var uniquid=Math.floor(Math.random()*99999);
$('.notij-msg').each(function(){
if($(this).html()==msg && $(this).is(':visible')){
isMultiple="yes";
if(!settings['multiple']){
display = false;
}
}
if($(this).attr('id')==uniquid){
uniquid=Math.floor(Math.random()*99999);
}
});
//adding main layout
if($('.notij-que').length==0){
$('body').append('<div class="notij-que '+settings.msgstyle+'"></div>');
}
if(display){
$('.notij-que').prepend('<div class="notij theme_' + settings['theme'] + '" id="' + uniquid + '"></div>');
$('#' + uniquid).append('<span class="notij-close close_' + settings['theme'] + '" rel="' + uniquid + '">x</span>');
$('#' + uniquid).append('<div class="notij-msg" rel="' + uniquid + '">' + msg + '</div>');
var height=$('#'+uniquid).height();
$('#'+uniquid).css('height',height);
$('#'+uniquid).slideDown(settings['speed']);
display=true;
}
$('.notij').ready(function(){
if(settings['autoclose']){
$('#'+uniquid).delay(settings['autoclose']).fadeOut(settings['speed'],function(){
$('#'+uniquid).remove();
closeAction();
});
}
});
//activating onfocus delay
$('.notij').mouseover(function(){
if(settings['onfocusdelay']){
$('#' + $(this).attr('id')).dequeue().stop().show();
}
});
$('.notij').mouseout(function(){
if(settings['autoclose']){
$('#' + $(this).attr('id')).delay(settings['autoclose']).fadeOut(settings['speed'],function(){
$('#' + $(this).attr('id')).remove();
closeAction();
});
}
});
$('.notij-close').click(function(){
$('#' + $(this).attr('rel')).dequeue().fadeOut(settings['speed']);
$('#' + $(this).attr('rel')).remove();
closeAction();
});
var result={
"id": uniquid,
"theme" : settings['theme']
};
if(callback){
callback(result);
} else{
return(result);
}
function closeAction(){
if($.isFunction(settings.onclose)){
return settings.onclose.call(this);
}
}
};
})( jQuery );