-
-
Save NemoPeti/aa92f23bba16e111d71ebbed85f6d59f to your computer and use it in GitHub Desktop.
Bootstrap 3 alert and confirm modals. Overrides window.alert normally, but window.confirm override requires a callback function to be passed to get result. Optional arguments for modal title and confirm button label.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.alert = function(message, title) { | |
if($("#bootstrap-alert-box-modal").length == 0) { | |
$("body").append('<div id="bootstrap-alert-box-modal" class="modal fade">\ | |
<div class="modal-dialog">\ | |
<div class="modal-content">\ | |
<div class="modal-header" style="min-height:40px;">\ | |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>\ | |
<h4 class="modal-title"></h4>\ | |
</div>\ | |
<div class="modal-body"><p></p></div>\ | |
<div class="modal-footer">\ | |
<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>\ | |
</div>\ | |
</div>\ | |
</div>\ | |
</div>'); | |
} | |
$("#bootstrap-alert-box-modal .modal-header h4").text(title || ""); | |
$("#bootstrap-alert-box-modal .modal-body p").text(message || ""); | |
$("#bootstrap-alert-box-modal").modal('show'); | |
}; | |
window.confirm = function(message, title, yes_label, callback) { | |
$("#bootstrap-confirm-box-modal").data('confirm-yes', false); | |
if($("#bootstrap-confirm-box-modal").length == 0) { | |
$("body").append('<div id="bootstrap-confirm-box-modal" class="modal fade">\ | |
<div class="modal-dialog">\ | |
<div class="modal-content">\ | |
<div class="modal-header" style="min-height:40px;">\ | |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>\ | |
<h4 class="modal-title"></h4>\ | |
</div>\ | |
<div class="modal-body"><p></p></div>\ | |
<div class="modal-footer">\ | |
<a href="#" data-dismiss="modal" class="btn btn-default">Cancel</a>\ | |
<a href="#" class="btn btn-primary">' + (yes_label || 'OK') + '</a>\ | |
</div>\ | |
</div>\ | |
</div>\ | |
</div>'); | |
$("#bootstrap-confirm-box-modal .modal-footer .btn-primary").on('click', function () { | |
$("#bootstrap-confirm-box-modal").data('confirm-yes', true); | |
$("#bootstrap-confirm-box-modal").modal('hide'); | |
return false; | |
}); | |
$("#bootstrap-confirm-box-modal").on('hide.bs.modal', function () { | |
if(callback) callback($("#bootstrap-confirm-box-modal").data('confirm-yes')); | |
}); | |
} | |
$("#bootstrap-confirm-box-modal .modal-header h4").text(title || ""); | |
$("#bootstrap-confirm-box-modal .modal-body p").text(message || ""); | |
$("#bootstrap-confirm-box-modal").modal('show'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment