-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmodal.js
50 lines (39 loc) · 1.02 KB
/
modal.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
var Modal = {};
(function() {
show = function (params) {
// destroy existing modals
$(".modal").remove();
if (params.optional === undefined) {
params.optional = {};
}
var type = params.type;
delete params.type;
var $modal = $(tpl.evaluate(type, params));
$modal.appendTo("body").modal();
return $modal;
};
Modal.info = function (params) {
params.type = "alert";
params.alert_type = "info";
show(params);
};
Modal.error = function (params) {
params.type = "alert";
params.alert_type = "error";
show(params);
};
Modal.prompt = function (params) {
var callback = params.success;
delete params.success;
params.type = "prompt";
var $modal = show(params);
$modal.on("shown", function () {
$modal.find("input")[0].focus();
});
$modal.find(".success").click(function () {
console.log("creating " + $modal.find("input").val());
callback($modal.find("input").val());
$modal.modal('hide');
});
};
}());