Created
October 24, 2014 18:55
-
-
Save zephster/efdf22a4126cce9bed87 to your computer and use it in GitHub Desktop.
twbs modal stacking
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
$(document).on('hidden.bs.modal', '.modal', function(e) | |
{ | |
$(this).removeClass('bs-modal-stack'); | |
$('body').data('bs_open_modals', $('body').data('bs_open_modals') - 1); | |
if ($(this).hasClass('is-clone')) | |
$(this).remove(); | |
}); | |
$(document).on('shown.bs.modal', '.modal', function (e) | |
{ | |
var stack_count = $('body').data('bs_open_modals'), | |
new_z = 0; | |
// set initial count | |
if (typeof(stack_count) == 'undefined') | |
stack_count = 0; | |
// if the z-index of this modal has been set, ignore | |
if ($(this).hasClass('bs-modal-stack')) | |
return; | |
// calculate new z-index | |
new_z = 1040 + (10 * stack_count); | |
// apply to modal | |
$(this).addClass('bs-modal-stack').css('z-index', new_z); | |
// apply to backdrop | |
$('.modal-backdrop') | |
.not('.bs-modal-stack') | |
.css('z-index', 1040 + (10 * stack_count)) | |
.addClass('bs-modal-stack'); | |
// increment stack counter | |
$('body').data('bs_open_modals', ++stack_count); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment