From 165a371f9d668442f61c1cb2a47348e8a15fef8e Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Thu, 22 Nov 2018 22:31:46 +0100 Subject: [PATCH] refactor: improve readibility and add docs in "AccordionMenu.down()" --- js/foundation.accordionMenu.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 -- 2.47.2