-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjquery.notification.js
More file actions
118 lines (106 loc) · 3.04 KB
/
jquery.notification.js
File metadata and controls
118 lines (106 loc) · 3.04 KB
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
111
112
113
114
115
116
117
118
/*
* jQuery Notifications - v1.0
*
* Copyright 2011 Cory LaViska for A Beautiful Site, LLC. (http://abeautifulsite.net/)
*
* Dual licensed under the MIT or GPL Version 2 licenses
*
*/
(function ($) {
$.notification = function (message, settings) {
if (message === undefined || message === null ) return;
// Merge settings with defaults
settings = $.extend(true, {
className: 'jquery-notification',
duration: 2000,
freezeOnHover: false,
hideSpeed: 250,
position: 'center',
showSpeed: 250,
zIndex: 99999
}, settings);
// Variables
var width, height, top, left, windowWidth = $(window).width(),
windowHeight = $(window).height(),
scrollTop = $(window).scrollTop(),
scrollLeft = $(window).scrollLeft(),
timeout, notification = $('<div id="jquery-notification" />');
// Skip the animation if a notification is already showing
if ($('#jquery-notification').length > 0) settings.showSpeed = 0;
// Clear old notifications
$('#jquery-notification').remove();
// Create it
notification.appendTo($('BODY')).addClass(settings.className).text(message).css({
position: 'absolute',
display: 'none',
zIndex: settings.zIndex
}).mouseover(function () {
if (settings.freezeOnHover) clearTimeout(timeout);
$(this).addClass(settings.className + '-hover');
}).mouseout(function () {
$(this).removeClass(settings.className + '-hover');
if (settings.freezeOnHover) {
timeout = setTimeout(function () {
notification.trigger('click');
}, settings.duration);
}
}).click(function () {
clearTimeout(timeout);
notification.fadeOut(settings.hideSpeed, function () {
$(this).remove();
});
}).wrapInner('<div id="jquery-notification-message" />');
// Position it
width = notification.outerWidth();
height = notification.outerHeight();
switch (settings.position) {
case 'top':
top = 0 + scrollTop;
left = windowWidth / 2 - width / 2 + scrollLeft;
break;
case 'top-left':
top = 0 + scrollTop;
left = 0 + scrollLeft;
break;
case 'top-right':
top = 0 + scrollTop;
left = windowWidth - width + scrollLeft;
break;
case 'bottom':
top = windowHeight - height + scrollTop;
left = windowWidth / 2 - width / 2 + scrollLeft;
break;
case 'bottom-left':
top = windowHeight - height + scrollTop;
left = 0 + scrollLeft;
break;
case 'bottom-right':
top = windowHeight - height + scrollTop;
left = windowWidth - width + scrollLeft;
break;
case 'left':
top = windowHeight / 2 - height / 2 + scrollTop;
left = 0 + scrollLeft;
break;
case 'right':
top = windowHeight / 2 - height / 2 + scrollTop;
left = windowWidth - width + scrollLeft;
break;
default:
case 'center':
top = windowHeight / 2 - height / 2 + scrollTop;
left = windowWidth / 2 - width / 2 + scrollLeft;
break;
}
// Show it
notification.css({
top: top,
left: left
}).fadeIn(settings.showSpeed, function () {
// Hide it
timeout = setTimeout(function () {
notification.trigger('click');
}, settings.duration);
});
};
})(jQuery);