From 9faccb7e5fa3478385203d100d493092a3d6a4bf Mon Sep 17 00:00:00 2001 From: Marco 'Lubber' Wienkoop Date: Thu, 6 Dec 2018 09:40:17 +0100 Subject: [PATCH] fix(modal): dimmer click closed modal when allowMultiple=true even if onHide()=false Closes #284 --- src/definitions/modules/modal.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/definitions/modules/modal.js b/src/definitions/modules/modal.js index e273fc0e67..0ee0d557cc 100755 --- a/src/definitions/modules/modal.js +++ b/src/definitions/modules/modal.js @@ -292,15 +292,17 @@ $.fn.modal = function(parameters) { isInModal = ($target.closest(selector.modal).length > 0), isInDOM = $.contains(document.documentElement, event.target) ; - if(!isInModal && isInDOM && module.is.active()) { + if(!isInModal && isInDOM && module.is.active() && $module.hasClass(className.top) ) { module.debug('Dimmer clicked, hiding all modals'); - module.remove.clickaway(); if(settings.allowMultiple) { - module.hideAll(); + if(!module.hideAll()) { + return; + } } - else { - module.hide(); + else if(!module.hide()){ + return; } + module.remove.clickaway(); } }, debounce: function(method, delay) { @@ -359,7 +361,7 @@ $.fn.modal = function(parameters) { : function(){} ; module.refreshModals(); - module.hideModal(callback); + return module.hideModal(callback); }, showModal: function(callback) { @@ -441,7 +443,7 @@ $.fn.modal = function(parameters) { module.debug('Hiding modal'); if(settings.onHide.call(element, $(this)) === false) { module.verbose('Hide callback returned false cancelling hide'); - return; + return false; } if( module.is.animating() || module.is.active() ) { @@ -523,10 +525,17 @@ $.fn.modal = function(parameters) { ; if( $visibleModals.length > 0 ) { module.debug('Hiding all visible modals'); - module.hideDimmer(); - $visibleModals - .modal('hide modal', callback, false, true) - ; + var hideOk = true; +//check in reverse order trying to hide most top displayed modal first + $($visibleModals.get().reverse()).each(function(index,element){ + if(hideOk){ + hideOk = $(element).modal('hide modal', callback, false, true); + } + }); + if(hideOk) { + module.hideDimmer(); + } + return hideOk; } },