From b58d7db63b79c796a2213b9b94c49921c7cfa91c Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Thu, 24 Apr 2014 15:57:01 -0400 Subject: [PATCH] added switch modal method --- src/jquery.simplemodal.js | 61 +++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 19 deletions(-) mode change 100644 => 100755 src/jquery.simplemodal.js diff --git a/src/jquery.simplemodal.js b/src/jquery.simplemodal.js old mode 100644 new mode 100755 index 652b8b0..022486e --- a/src/jquery.simplemodal.js +++ b/src/jquery.simplemodal.js @@ -138,6 +138,13 @@ $.modal.impl.update(height, width); }; + /* + * Transition to another modal without closing the overlay + */ + $.modal.switchModals = function ( newModalObj , options ) { + $.modal.impl.switchModals( newModalObj , options ); + }; + /* * Chained function to create a modal dialog. * @@ -320,21 +327,25 @@ .appendTo(s.o.appendTo); } - // create the overlay - s.d.overlay = $('
') - .attr('id', s.o.overlayId) - .addClass('simplemodal-overlay') - .css($.extend(s.o.overlayCss, { - display: 'none', - opacity: s.o.opacity / 100, - height: s.o.modal ? d[0] : 0, - width: s.o.modal ? d[1] : 0, - position: 'fixed', - left: 0, - top: 0, - zIndex: s.o.zIndex + 1 - })) - .appendTo(s.o.appendTo); + s.d.overlay = $('#' + s.o.overlayId); + + if(s.d.overlay.length == 0 ) { + // create the overlay + s.d.overlay = $('
') + .attr('id', s.o.overlayId) + .addClass('simplemodal-overlay') + .css($.extend(s.o.overlayCss, { + display: 'none', + opacity: s.o.opacity / 100, + height: s.o.modal ? d[0] : 0, + width: s.o.modal ? d[1] : 0, + position: 'fixed', + left: 0, + top: 0, + zIndex: s.o.zIndex + 1 + })) + .appendTo(s.o.appendTo); + } // create the container s.d.container = $('
') @@ -663,7 +674,7 @@ * function was internal or external. If it was external, the * onClose callback will be ignored */ - close: function () { + close: function ( keepOverlay ) { var s = this; // prevent close when dialog does not exist @@ -704,13 +715,25 @@ // remove the remaining elements s.d.container.hide().remove(); - s.d.overlay.hide(); + if(!keepOverlay) + s.d.overlay.hide(); s.d.iframe && s.d.iframe.hide().remove(); - s.d.overlay.remove(); + if(!keepOverlay) + s.d.overlay.remove(); // reset the dialog object s.d = {}; } - } + }, + + /* + * Close the currently open modal and open a new one, keeping + * the overlay in place to create a warm and fuzzy transisiton between modals + */ + switchModals: function( newModalObj , options ) + { + this.close(true); + newModalObj.modal( options ); + } }; }));