forked from longlostnick/bootstrap-growl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.bootstrap-growl.js
82 lines (64 loc) · 1.88 KB
/
jquery.bootstrap-growl.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
/* https://github.com/ifightcrime/bootstrap-growl */
(function($) {
$.bootstrapGrowl = function(message, options) {
var options = $.extend({}, $.bootstrapGrowl.default_options, options);
var $alert = $('<div>');
$alert.attr('class', 'bootstrap-growl alert');
if (options.type) {
$alert.addClass('alert-' + options.type);
}
if (options.allow_dismiss) {
$alert.append('<a class="close" data-dismiss="alert" href="#">×</a>');
}
$alert.append(message);
var top_offset = options.top_offset;
var current = $('.bootstrap-growl', options.ele);
// calculate any 'stack-up'
$.each(current, function() {
top_offset = top_offset + $(this).outerHeight() + options.stackup_spacing;
});
$alert.css({
'position': 'absolute',
'top': top_offset + 'px',
'border': '1px solid ' + $alert.css('color'),
'margin': 0,
'z-index': '9999',
'display': 'none'
});
if (options.width !== 'auto') {
$alert.css('width', options.width + 'px');
}
// have to append before we can use outerWidth()
$(options.ele).append($alert);
switch(options.align) {
case 'center':
$alert.css({
'left': '50%',
'margin-left': '-' + ($alert.outerWidth() / 2) + 'px'
});
break;
case 'left':
$alert.css('left', '20px');
break;
default:
$alert.css('right', '20px');
}
$alert.fadeIn();
// Only remove after delay if delay is more than 0
if(options.delay >= 0){
$alert.delay(options.delay).fadeOut('slow', function() {
$(this).remove();
});
}
};
$.bootstrapGrowl.default_options = {
ele: 'body',
type: null,
top_offset: 20,
align: 'right', // (left, right, or center)
width: 250,
delay: 4000,
allow_dismiss: true,
stackup_spacing: 10
};
})(jQuery);