Last active
February 3, 2016 12:18
-
-
Save danpette/72f8edf73371d9bf005e to your computer and use it in GitHub Desktop.
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
//Requires jquery and bootsteap 3.2+ | |
var modal_ok = 'Confirm'; | |
var modal_abort = 'Abort'; | |
var ok_text = ''; | |
var modals = 0; | |
function ModalAlert(title, message, confirm, success_function, size, init_ok_disabled, ok_text) { | |
modals++; | |
var is_confirm_modal = (confirm !== undefined && confirm != null && confirm === true) ? true : false; | |
var size = (size !== undefined && size != null) ? ' ' + size : ''; | |
var ok_disabled = (init_ok_disabled !== undefined && init_ok_disabled != null) ? init_ok_disabled : false; | |
var ok_text = ok_text == null ? modal_ok : ok_text; | |
jQuery('body').append('<div class="overlay"></div>'); | |
jQuery('body').append('<div class="overlay-modal"><div class="modal"><div class="modal-dialog' + size + '"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h4 class="modal-title">' + title + '</h4></div><div class="modal-body"><p>' + message + '</p></div><div class="modal-footer"><button type="button" class="btn btn-default close-modal-alert" data-dismiss="modal">' + ((is_confirm_modal) ? modal_abort : ok_text) + '</button>' + ((is_confirm_modal) ? '<button type="button" class="btn btn-primary confirm-modal-alert"' + ((ok_disabled) ? ' disabled="disabled" ' : '') + '>' + modal_accept + '</button>' : '') + '</div></div></div></div></div>'); | |
$('.overlay').css({ | |
"width": "100%", | |
"height": "100%", | |
"position": "fixed", | |
"top": "0", | |
"left": "0", | |
"z-index": "1000", | |
"background-color": "#626262", | |
"opacity": "0.5", | |
"filter:": "alpha(opacity=50);" | |
}); | |
$('.overlay-modal .modal').show(); | |
$('.close-modal-alert').on('click', function () { | |
modals--; | |
if (success_function != null && confirm == false) { | |
success_function(); | |
} | |
$(".overlay").eq(modals).hide().remove(); | |
$(".overlay-modal").eq(modals).hide().remove(); | |
return false; | |
}); | |
$('.modal-header .close').on('click', function () { | |
modals--; | |
$(".overlay").eq(modals).hide().remove(); | |
$(".overlay-modal").eq(modals).hide().remove(); | |
return false; | |
}); | |
$('.confirm-modal-alert').on('click', function (e) { | |
e.preventDefault(); | |
modals--; | |
$(".overlay").eq(modals).hide().remove(); | |
$(".overlay-modal").eq(modals).hide().remove(); | |
success_function(); | |
return false; | |
}); | |
$('.overlay').on('click', function () { | |
$(this).hide(); | |
$(".overlay-modal").hide(); | |
}); | |
} | |
//USE Yes/No | |
ModalAlert("Delete user?", "Are you sure you want to delete this user", true, function () { | |
//Run any javascript here. | |
}); | |
//Use OK | |
ModalAlert("Not allowed!", "You dont have access to this page", false, function () { | |
//Run any javascript here. | |
}, 'modal-sm'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment