From 98523d50abec259082ea13889784e4027ed1412f Mon Sep 17 00:00:00 2001 From: Brian Lenz Date: Thu, 9 Jul 2015 15:21:22 -0700 Subject: [PATCH] Fix to the modal stack implementation so that you can safely close a modal that isn't at the top of the stack. --- js/foundation/foundation.reveal.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/js/foundation/foundation.reveal.js b/js/foundation/foundation.reveal.js index 458ab1f0a..561a57b03 100644 --- a/js/foundation/foundation.reveal.js +++ b/js/foundation/foundation.reveal.js @@ -267,8 +267,24 @@ } if (settings.multiple_opened) { + var isCurrent = modal.is(':not(.toback)'); self.hide(modal, settings.css.close, settings); - openModals.pop(); + if(isCurrent) { + // remove the last modal since it is now closed + openModals.pop(); + } else { + // if this isn't the current modal, then find it in the array and remove it + openModals = $.grep(openModals, function(elt) { + var isThis = elt[0]===modal[0]; + if(isThis) { + // since it's not currently in the front, put it in the front now that it is hidden + // so that if it's re-opened, it won't be .toback + self.to_front(modal); + } + return !isThis; + }); + } + // finally, show the next modal in the stack, if there is one if(openModals.length>0) { self.to_front(openModals[openModals.length - 1]); } -- 2.47.2