forked from sairam/bootstrap-prompts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-prompts-alert.js
65 lines (65 loc) · 2.27 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
window._originalAlert = window.alert;
window.alert = function(text) {
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) {
bootStrapConfirm = function() {
if(! $.fn.modal.Constructor)
return false;
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> \
');
function unbind() {
$("#windowConfirmModal .btn-primary").unbind('click', confirm);
$("#windowConfirmModal .btn-danger").unbind('click', deny);
}
function confirm() { cb(true); }
function deny() { cb(false); }
$("#windowConfirmModal .btn-primary").bind('click', confirm);
$("#windowConfirmModal .btn-danger").bind('click', deny);
return true;
}
if ( bootStrapConfirm() ){
$('#windowConfirmModal .modal-body p').text(text);
$('#windowConfirmModal').modal();
} else {
console.log('bootstrap was not found');
window._originalConfirm(text);
}
}