-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIDialog.js
More file actions
44 lines (44 loc) · 1.6 KB
/
UIDialog.js
File metadata and controls
44 lines (44 loc) · 1.6 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
(function(factory) {
if (typeof define === "function" && define.amd) {
define(factory);
} else if (typeof module != "undefined" && typeof module.exports != "undefined") {
module.exports = factory();
} else {
window["UIDialog"] = factory();
}
})(function() {
var Dialog = {};
var alert = UIModal();
alert.onshown = function(text) {
this.el.innerHTML = '<div class="ui-dialog"><div class="ui-alert">'
+ '<div>' + (text||'') + '</div>'
+ '<div><a href="javascript:void(0)">确定</a></div>'
+ '</div></div>';
var _this = this;
this.el.addEventListener('click', function(e) {
var el = e.target;
if (el.tagName == 'A') {
_this.close();
}
});
}
var confirm = UIModal();
confirm.onshown = function(text, cb) {
this.el.innerHTML = '<div class="ui-dialog"><div class="ui-confirm">'
+ '<div>' + (text || '') + '</div>'
+ '<div><a href="javascript:void(0)" data-act="close">取消</a><a href="javascript:void(0)" data-act="confirm">确定</a></div>'
+ '</div></div>';
var _this = this;
this.el.addEventListener('click', function(e) {
var el = e.target;
if (el.tagName == 'A') {
var data = el.getAttribute('data-act');
if (data == 'close') _this.close();
if (data == 'confirm') cb();
}
})
}
Dialog.alert = function(text){alert.open(text);}
Dialog.confirm = function(text,cb){confirm.open(text,cb);}
return Dialog;
})