Last active
August 29, 2015 14:02
-
-
Save danpette/b30bc533c942ed5a2ff2 to your computer and use it in GitHub Desktop.
Bootstrap ModalAlert Function
This file contains hidden or 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
var modals = 0; | |
function ModalAlert(title, message, confirm, success_function, size, init_ok_disabled) { | |
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; | |
console.log(ok_disabled); | |
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 : modal_ok) + '</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": "absolute", | |
"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--; | |
$(".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 () { | |
modals--; | |
$(".overlay").eq(modals).hide().remove(); | |
$(".overlay-modal").eq(modals).hide().remove(); | |
success_function(); | |
}); | |
$('.overlay').on('click', function () { | |
$(this).hide(); | |
$(".overlay-modal").hide(); | |
}); | |
} | |
Use | |
ModalAlert("Title","Beskrivelse", true, function(){ | |
//Ajax call or other awesomenes | |
}, '', false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated with support for multiple stacking overlays