From: Nicolas Coden Date: Thu, 22 Nov 2018 21:31:46 +0000 (+0100) Subject: refactor: improve readibility and add docs in "AccordionMenu.down()" X-Git-Tag: v6.6.0~3^2~55^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11606%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git refactor: improve readibility and add docs in "AccordionMenu.down()" --- diff --git a/js/foundation.accordionMenu.js b/js/foundation.accordionMenu.js index 2a17d4984..7f5614e31 100644 --- a/js/foundation.accordionMenu.js +++ b/js/foundation.accordionMenu.js @@ -233,8 +233,18 @@ class AccordionMenu extends Plugin { * @fires AccordionMenu#down */ down($target) { - if(!this.options.multiOpen) { - this.up(this.$element.find('.is-active').not($target.parentsUntil(this.$element).add($target).add($target.find('.is-active')))); + // If having multiple submenus active is disabled, close all the submenus + // that are not parents or children of the targeted submenu. + if (!this.options.multiOpen) { + // The "branch" of the targetted submenu, from the component root to + // the active submenus nested in it. + const $targetBranch = $target.parentsUntil(this.$element) + .add($target) + .add($target.find('.is-active')); + // All the active submenus that are not in the branch. + const $othersActiveSubmenus = this.$element.find('.is-active').not($targetBranch); + + this.up($othersActiveSubmenus); } $target