-
Notifications
You must be signed in to change notification settings - Fork 39
/
bootstrap-prompts-alert.js
73 lines (66 loc) · 2.47 KB
/
bootstrap-prompts-alert.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
window._originalAlert = window.alert;
window.alert = function(text) {
var bootStrapAlert = function() {
if(! $.fn.modal.Constructor)
return false;
if($('#windowAlertModal').length == 1)
return true;
$('body').append(' \
<div id="windowAlertModal" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true"> \
<div class="modal-body"> \
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> \
<p> alert text </p> \
</div> \
<div class="modal-footer"> \
<button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Close</button> \
</div> \
</div> \
');
return true;
}
if ( bootStrapAlert() ){
$('#windowAlertModal .modal-body p').text(text);
$('#windowAlertModal').modal();
} else {
console.log('bootstrap was not found');
window._originalAlert(text);
}
}
window._originalConfirm = window.confirm;
window.confirm = function(text, cb) {
var initTemplate = function(){
if($('#windowConfirmModal').length == 1)
return true;
$('body').append(' \
<div id="windowConfirmModal" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true"> \
<div class="modal-body"> \
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> \
<p> alert text </p> \
</div> \
<div class="modal-footer"> \
<button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Close</button> \
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Ok</button> \
</div> \
</div> \
');
}
var bootStrapConfirm = function() {
if(! $.fn.modal.Constructor)
return false;
$('body').off('click', '#windowConfirmModal .btn-primary');
$('body').off('click', '#windowConfirmModal .btn-danger');
function confirm() { cb(true); }
function deny() { cb(false); }
$('body').on('click', '#windowConfirmModal .btn-primary', confirm);
$('body').on('click', '#windowConfirmModal .btn-danger', deny);
return true;
}
initTemplate()
if ( bootStrapConfirm() ){
$('#windowConfirmModal .modal-body p').text(text);
$('#windowConfirmModal').modal();
} else {
console.log('bootstrap was not found');
cb(window._originalConfirm(text));
}
}