forked from Itsallonly/iao-alert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiao-alert.jquery.js
executable file
·59 lines (59 loc) · 2.88 KB
/
iao-alert.jquery.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
/*
Plugin Name: iao alert
Key: iao-alert
Version: 1.0.7
Author: Prashant Kapoor
Website: http://www.itsallonly.com
Repo: https://github.com/Itsallonly/iao-alert
Issues: https://github.com/Itsallonly/iao-alert/issues
Files: iao-alert.jquery.js, iao-alert.css
Dependency: Jquery
*/
(function( $ ) {
$.fn.iaoAlert = $.iaoAlert = function(arr) {
var opt = $.extend( {
msg: "This is default iao alert message.",
type: "notification",
mode: "light",
autoHide: true,
alertTime: "3000",
fadeTime: "500",
closeButton: true,
closeOnClick: false,
fadeOnHover: true,
position: 'top-right',
zIndex: '999',
roundedCorner: false,
alertClass: ''
}, arr ),
timeStamp = $.now(),
ext = {
chkPosition : (opt.position == 'bottom-right')?'bottom-right':((opt.position == 'bottom-left')?'bottom-left':(opt.position == 'top-left')?'top-left':'top-right'),
closeOption : (opt.closeButton)?'<iao-alert-close></iao-alert-close>':'<style>#iao'+timeStamp+':before,#iao'+timeStamp+':after{display:none}</style>',
chkMsg : (opt.msg.indexOf(" "))?'white-space:pre-wrap;word-wrap:break-word;':''
},
roundedCorner = (opt.roundedCorner)?('round'):'';
if($('iao-alert-box').length==0)
$('body').append('<iao-alert-box position="top-left" style="z-index:'+opt.zIndex+'"><iao-alert-start></iao-alert-start></iao-alert-box><iao-alert-box position="top-right" style="z-index:'+opt.zIndex+'"><iao-alert-start></iao-alert-start></iao-alert-box><iao-alert-box position="bottom-right" style="z-index:'+opt.zIndex+'"><iao-alert-start></iao-alert-start></iao-alert-box><iao-alert-box position="bottom-left" style="z-index:'+opt.zIndex+'"><iao-alert-start></iao-alert-start></iao-alert-box>');
var iaoAlert = $('<iao-alert class="'+opt.alertClass+'" id="iao'+timeStamp+'" close-on-click='+opt.closeOnClick+' fade-on-hover='+opt.fadeOnHover+' mode="'+opt.mode+'"type="'+opt.type+'" style="'+ext.chkMsg+'" corners="'+roundedCorner+'">'+opt.msg+ext.closeOption+'</iao-alert>')
.insertAfter('iao-alert-box[position="'+ext.chkPosition+'"] > iao-alert-start');
if(opt.autoHide)
setTimeout(function(){
iaoAlert.fadeOut(opt.fadeTime, function() {
$(this).remove();
});
}, opt.alertTime);
$('iao-alert[close-on-click="true"]').click(function() {
$(this).fadeOut(opt.fadeTime, function() {
$(this).remove();
});
});
$('iao-alert > iao-alert-close').click(function() {
$(this).parent()
.fadeOut(opt.fadeTime, function() {
$(this).remove();
});
});
return this;
};
}( jQuery ));