-
Notifications
You must be signed in to change notification settings - Fork 1
/
notify.js
71 lines (61 loc) · 1.96 KB
/
notify.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
(function($) {
'use strict';
var defaults = {
hide: {
easing: 'linear',
speed: 1000
},
show: {
easing: 'swing',
speed: 300
},
timeout: 5000
};
$.fn.notify = function (options) {
var context = $.extend({}, defaults, options);
this.each(function() {
var $this = $(this);
var data = {
arrow: { right: 0 },
width: parseInt($this.css('width'))
};
var html = '<div class="notify">' +
'<div class="arrow" style="right:{{arrow.right}}px;"/>' +
'<div class="content"/>' +
'</div>';
data.arrow.right = (data.width - 8) / 2;
html = html.replace(/{{arrow.right}}/g, data.arrow.right);
$this.after(html);
});
var $container = $(this).next('div.notify').hide();
$container.children('div.content').click(function(e) {
e.preventDefault();
$(this).parent().hide();
});
function render(message, type) {
type = (type) ? ' ' + type : '';
$container.attr('class', 'notify' + type).
children('div.content').text(message);
$container.fadeIn(context.show.speed, context.show.easing).
delay(context.timeout).
fadeOut(context.hide.speed, context.hide.easing);
}
return {
error: function(message) {
render(message, 'error');
},
info: function(message) {
render(message, 'info');
},
log: function(message) {
render(message);
},
success: function(message) {
render(message, 'success');
},
warn: function(message) {
render(message, 'warn');
}
};
};
}(jQuery));