From 50d336b0f4fa3785e442b7892d42b07b5fbfe075 Mon Sep 17 00:00:00 2001 From: "Michael N. Lipp" Date: Tue, 29 Aug 2017 18:12:28 +0200 Subject: [PATCH] Fixed closing of open dropdown. Fixes https://github.com/soundasleep/jquery-dropdown/pull/127#issuecomment-325618969 by merging https://github.com/eoghanmurray 's solution (https://github.com/soundasleep/jquery-dropdown/pull/131/commits/4db65fc18f6134b83196ee06ad5e423635a93ba8). --- .../jquery-dropdown-2.0.3/jquery.dropdown.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/org.jgrapes.portal/resources/org/jgrapes/portal/lib/jquery-dropdown-2.0.3/jquery.dropdown.js b/org.jgrapes.portal/resources/org/jgrapes/portal/lib/jquery-dropdown-2.0.3/jquery.dropdown.js index fce019c7e16..976f77ac409 100644 --- a/org.jgrapes.portal/resources/org/jgrapes/portal/lib/jquery-dropdown-2.0.3/jquery.dropdown.js +++ b/org.jgrapes.portal/resources/org/jgrapes/portal/lib/jquery-dropdown-2.0.3/jquery.dropdown.js @@ -75,6 +75,9 @@ if (jQuery) (function ($) { // In some cases we don't hide them var targetGroup = event ? $(event.target).parents().addBack() : null; + // Things to hide, by default every dropdown visible + var toHide = $(document).find('.jq-dropdown:visible'); + // Are we clicking anywhere in a jq-dropdown? if (targetGroup && targetGroup.is('.jq-dropdown')) { // Is it a jq-dropdown menu? @@ -82,23 +85,25 @@ if (jQuery) (function ($) { // Did we click on an option? If so close it. if (!targetGroup.is('A')) return; } else { - // Nope, it's a panel. Leave it open. - return; - } + // Nope, it's a panel. Leave it open, but close others + toHide = $(document).find('.jq-dropdown:visible').not( + $(event.target).parents('.jq-dropdown')); } } - + // Hide any jq-dropdown that may be showing - $(document).find('.jq-dropdown:visible').each(function () { + toHide.each(function () { var jqDropdown = $(this); + // Remove all jq-dropdown-open classes from things to hide... + jqDropdown.find('.jq-dropdown-open').removeClass('jq-dropdown-open'); + // ... and from whatever caused it to be shown + $(document).find('[data-jq-dropdown=\'#' + this.id + '\']'). + removeClass('jq-dropdown-open'); + // Hide and trigger jqDropdown .hide() .removeData('jq-dropdown-trigger') .trigger('hide', { jqDropdown: jqDropdown }); }); - - // Remove all jq-dropdown-open classes - $(document).find('.jq-dropdown-open').removeClass('jq-dropdown-open'); - } function position() {