This repository has been archived by the owner on Jul 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.flasher.js
55 lines (49 loc) · 1.77 KB
/
jquery.flasher.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
(function($) {
$.fn.flasher = function( options ) {
var defaults = {
animation : 'fadeIn', // animation used to show/hide the flash
inDuration : 1000, // how long the flash displays in miliseconds
outDuration : 1000, // how long the flash displays in miliseconds
msgDuration : 2000, // how long the flash displays in miliseconds
layout : 'top'
},
o = $.extend( defaults, options );
switch (o.layout) {
case "top":
/*
TODO calculate top position
*/
break;
case "bottom":
/*
TODO calculate bottom position
*/
break;
case "center":
/*
TODO calculate center position
*/
break;
}
return this.each( function( index ) {
var $el = '<div id="flasher" class="' +
o.classNames +
'" style="display:none; position: absolute; z-index: 9999; top: 5%; left: 50%;"' +
/*
TODO apply layout instead of hard-coding left/right
*/
' />';
var $flasher;
if ( !$flasher ) {
$('body').append( $el );
$flasher = $('#flasher');
};
$flasher.text( o.message )
.removeClass()
.addClass( o.classNames );
// show the flash message
$flasher.fadeIn( o.inDuration );
setTimeout( function() { $flasher.fadeOut(o.outDuration); }, o.msgDuration );
});
};
})(jQuery)