issue 2929, support nested modal window.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12743 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-13 07:24:21 +00:00
parent 3ba585c33f
commit acb8e1d509
2 changed files with 116 additions and 80 deletions

View file

@ -325,6 +325,12 @@ jQuery(function($){
// Modal Window
jQuery(function($){
var ESC = 27;
var xeModalStack = new Array();
var xeModalInitailZIndex = 1040;
// modal backdrop
var $xeModalBackdrop = $('<div class="x_modal-backdrop"></div>').appendTo('body').hide();
$.fn.xeModalWindow = function(){
this
.not('.xe-modal-window')
@ -347,13 +353,19 @@ jQuery(function($){
})
.bind('open.mw', function(){
var $this = $(this), $modal, $btnClose, disabled, before_event, duration;
// get modal window
$modal = $( $this.attr('href') );
// if stack top is this modal, ignore
if(xeModalStack.length && xeModalStack[xeModalStack.length - 1].get(0) == $modal.get(0)){
return;
}
if(!$modal.parent('body').length) {
$btnClose = $('<button type="button" class="x_close">&times;</button>');
$btnClose.click(function(){ $modal.data('anchor').trigger('close.mw') });
$modal.find('[data-hide]').click(function(){ $modal.data('anchor').trigger('close.mw') });
$('body').append('<div class="x_modal-backdrop"></div>').append($modal); // append background
$modal.prepend($btnClose); // prepend close button
}
@ -367,9 +379,6 @@ jQuery(function($){
// is event canceled?
if(before_event.isDefaultPrevented()) return false;
// get modal window
$modal = $( $this.attr('href') );
// get duration
duration = $this.data('duration') || 'fast';
@ -388,13 +397,30 @@ jQuery(function($){
$modal
.fadeIn(duration, after)
.find('button.x_close:first').focus().end()
.prev('.x_modal-backdrop').show();
.find('button.x_close:first').focus();
$('body').css('overflow','hidden');
// push to stack
xeModalStack.push($modal);
// show backdrop and adjust z-index
var zIndex = xeModalInitailZIndex + ((xeModalStack.length - 1) * 2);
$xeModalBackdrop.css('z-index', zIndex).show();
$modal.css('z-index', zIndex + 1);
})
.bind('close.mw', function(){
var $this = $(this), before_event, $modal, duration;
// get modal window
$modal = $( $this.attr('href') );
// if stack top is not this modal, ignore
if(xeModalStack.length && xeModalStack[xeModalStack.length - 1].get(0) != $modal.get(0)){
return;
}
// before event trigger
before_event = $.Event('before-close.mw');
$this.trigger(before_event);
@ -402,9 +428,6 @@ jQuery(function($){
// is event canceled?
if(before_event.isDefaultPrevented()) return false;
// get modal window
$modal = $( $this.attr('href') );
// get duration
duration = $this.data('duration') || 'fast';
@ -414,10 +437,22 @@ jQuery(function($){
// after event trigger
function after(){ $this.trigger('after-close.mw') };
$modal.fadeOut(duration, after)
.prev('.x_modal-backdrop').hide();
$modal.fadeOut(duration, after);
$('body').css('overflow','auto');
$this.focus();
// pop from stack
xeModalStack.pop();
// hide backdrop and adjust z-index
var zIndex = xeModalInitailZIndex + ((xeModalStack.length - 1) * 2);
if(xeModalStack.length){
$xeModalBackdrop.css('z-index', zIndex);
}else{
$xeModalBackdrop.hide();
}
});
$('div.x_modal').addClass('x');
};