-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap-modal-confirm.js
66 lines (59 loc) · 1.72 KB
/
bootstrap-modal-confirm.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
/*!
* Bootstrap Modal Confirm v0.0.2
* https://github.com/huaxiabuluo/bootstrap-modal-confirm
*
* By: Xiaolong Lu <[email protected]>
* Date: 2016-07-16
*
* A sample plugin, you can extend it
* or write your own confirm dialog based on it.
*
*/
(function($) {
var $modalDOM = $('<div id="modalId" class="modal hide fade" tabindex="-1" role="dialog" data-backdrop="static" aria-hidden="true"></div>');
var modalInnerHtml =
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
'<h3>{title}</h3>' +
'</div>' +
'<div class="modal-body">' +
'<p>{content}</p>' +
'</div>' +
'<div class="modal-footer">' +
'<a href="#" class="btn cancel" data-dismiss="modal">{btnCancel}</a>' +
'<a href="#" class="btn btn-primary ok" data-dismiss="modal">{btnOk}</a>' +
'</div>';
var reg = /{([^{}]*?)}/img;
$('body').append($modalDOM);
var _dialog = function(options) {
var ops = {
title: "title",
content: "content",
btnCancel: "Cancel",
btnOk: "Ok"
};
$.extend(ops, options);
$modalDOM.off('click', '.ok');
$modalDOM.off('click', '.cancel');
// matchedStr: {title}, key: title
$modalDOM.html(modalInnerHtml.replace(reg, function(matchedStr, key){
return ops[key];
}));
};
$.Modal = function(options) {
_dialog(options);
$modalDOM.modal('show');
return {
do: function(OKHandler, CancelHandler) {
if($.isFunction(OKHandler)) {
// do OKHandler when click 'Ok'
$modalDOM.on('click', '.ok', OKHandler);
}
if($.isFunction(CancelHandler)) {
// do CancelHandler when click 'Cancel'
$modalDOM.on('click', '.cancel', CancelHandler);
}
}
};
};
})(jQuery);