]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
refactor: improve readibility and add docs in "AccordionMenu.down()" 11606/head
authorNicolas Coden <nicolas@ncoden.fr>
Thu, 22 Nov 2018 21:31:46 +0000 (22:31 +0100)
committerNicolas Coden <nicolas@ncoden.fr>
Thu, 22 Nov 2018 21:31:46 +0000 (22:31 +0100)
js/foundation.accordionMenu.js

index 2a17d498427eb4905d40dac7d814f7e78bc7d0e6..7f5614e314dbb97fc4b5a6003ef2aac91e9e7e8d 100644 (file)
@@ -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