-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.modalmsg.js
61 lines (56 loc) · 1.79 KB
/
jquery.modalmsg.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
//args = [title] (title string)
//args = [title,html] (title string, html string)
//args = [{}] (options object)
jQuery.fn.modalmsg = function(options) {
var SELF = this,
doclose = false,
title;
if(arguments.length == 2) {
title = options; //title string
html = arguments[1]; //html string
} else if(typeof options == "string") {
if (options == "close") {
doclose = true;
} else {
title = options;//title string
}
} else {
title = options.title;//title string
html = options.html;
}
//initialize dialog if necessary
if(!SELF.is(":data(dialog)")) {
//create the dialog
SELF.dialog({
modal: true,
resizable: false,
draggable: false,
title: msg,
autoOpen: !doclose //if creating the dialog but msg was "close" dont open it
});
//remove the close link
SELF.prev().find(".ui-dialog-titlebar-close").remove();
}
//if no msg is provided, use "Please wait..." as default
var msg = title || "Please wait...";
//detect if the dialog is open, closed, or undefined
switch (SELF.dialog("isOpen")) {
case true: //if its open
//and msg is "close", then close it
if (doclose) {
SELF.dialog("close");
} else { //else update the msg
SELF.dialog( "option", "title", msg );
}
break;
case false: //if its closed
//and msg is "close", then do nothing
//if msg is not "close", update msg and open it
if (!doclose) {
SELF.dialog( "option", "title", msg )
.dialog("open");
}
break;
}
return SELF;
};