-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.rustaMsgBox.js
executable file
·166 lines (153 loc) · 4.82 KB
/
jquery.rustaMsgBox.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
(function ( $ ) {
$.rustaMsgBox = function(options) {
// set default options
var settings = $.extend({
closeButton: false,
fadeOut: true,
fadeTimer: 1500,
content: 'Add some content here...',
zindex: 3022,
width: '70%',
maxWidth: '300px',
mode: 'info', /* warning, success, error, info */
bottom: '-90px',
stack: true,
opacity: 0.9
}, options );
// if fadeOut is false then we need to show the closeButton
if (!settings.fadeOut){
settings.closeButton = true;
}
// styles for the delivered modes
if ( settings.mode == 'warning' )
{
settings.backgroundColor = '#fcf8e3';
settings.border = '1px solid #fbeed5';
settings.color = '#c09853';
}
else if ( settings.mode == 'success' )
{
settings.backgroundColor = '#dff0d8';
settings.border = '1px solid #d6e9c6';
settings.color = '#468847';
}
else if ( settings.mode == 'error' )
{
settings.backgroundColor = '#f2dede';
settings.border = '1px solid #eed3d7';
settings.color = '#b94a48';
}
else if ( settings.mode == 'info' )
{
settings.backgroundColor = '#d9edf7';
settings.border = '1px solid #bce8f1';
settings.color = '#3a87ad';
}
// create a unique ID for this message box
var randomNumber = (((1+Math.random())*0x10000)|0).toString(16).substring(1);
var currentDateTime = new Date();
currentDateTime = String(currentDateTime.getDate()) + String(currentDateTime.getMonth() +1) + String(currentDateTime.getFullYear()) + String(currentDateTime.getHours()) + String(currentDateTime.getMinutes()) + String(currentDateTime.getSeconds()) + String(currentDateTime.getMilliseconds());
var msgBoxId = 'rusta-msgBox' + '_' + randomNumber + '_' + currentDateTime;
$('<div/>', {
id: msgBoxId,
css: {
'margin': '0px',
'z-index': settings.zindex,
'position': 'fixed',
'bottom': settings.bottom,
'width': '100%',
'left': '0px',
'opacity': settings.opacity
}
}).appendTo('body');
if (settings.customClass)
{
$('<div/>', {
html: settings.content,
addClass: 'rusta-msgBox ' + settings.customClass
}).appendTo('#'+msgBoxId);
}
else
{
var padding, textAlign;
if (settings.closeButton)
{
padding = '8px 35px 8px 14px';
textAlign = 'left';
} else {
padding = '8px 14px 8px 14px';
textAlign = 'center';
}
$('<div/>', {
html: settings.content,
addClass: 'rusta-msgBox',
css: {
'padding': padding,
'text-align': textAlign,
'text-shadow': '0 1px 0 rgba(255, 255, 255, 0.5)',
'-webkit-border-radius': '4px',
'-moz-border-radius': '4px',
'border-radius': '4px',
'-moz-box-shadow': '10px 10px 5px rgba(0,0,0,0.4)',
'-webkit-box-shadow': '10px 10px 5px rgba(0,0,0,0.4)',
'box-shadow': '10px 10px 5px rgba(0,0,0,0.4)',
'background-color': settings.backgroundColor,
'color': settings.color,
'border': settings.border,
'position': 'relative',
'width': settings.width,
'max-width': settings.maxWidth,
'margin': '0 auto'
}
}).appendTo('#'+msgBoxId);
}
if (settings.closeButton)
{
// add close button
$('<button/>', {
html: 'x',
addClass: 'rusta-msgBox-close',
css: {
'position': 'absolute',
'right': '8px',
'top': '2px',
'line-height': '20px',
'padding': '0',
'cursor': 'pointer',
'background': 'transparent',
'border': '0',
'-webkit-appearance': 'none',
'float': 'right',
'font-size': '16px',
'font-weight': 'bold',
'line-height': '20px',
'color': '#000000',
'text-shadow': '0 1px 0 #ffffff',
'opacity': '0.2',
'filter': 'alpha(opacity=20)'
},
data: { 'rusta-msg-box': msgBoxId }
}).appendTo('#'+msgBoxId + ' .rusta-msgBox');
// add close button click functionality
$('#' + msgBoxId + ' .rusta-msgBox-close').on('click', function(){
var thisMsgBoxId = $(this).data('rusta-msg-box');
$('#' + thisMsgBoxId).fadeOut(400, function(){
$('#' + thisMsgBoxId).remove();
});
});
} // end close button block
// animate message box on to screen
$('#' + msgBoxId).animate({
"bottom": 20 + (parseInt(settings.stack?1:0) * parseInt($(".rusta-msgBox").length - 1))*50
}, 600);
// fade out after set amount of time
if (settings.fadeOut)
{
setTimeout(function(){
$('#' + msgBoxId).fadeOut(400, function(){
$('#' + msgBoxId).remove();
});
}, settings.fadeTimer)
}
}
}( jQuery ));