]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fix: remove dropdownMenu Touch body listener on destroy
authorNicolas Coden <nicolas@ncoden.fr>
Sun, 25 Mar 2018 17:28:15 +0000 (19:28 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Sun, 25 Mar 2018 17:28:15 +0000 (19:28 +0200)
js/foundation.dropdownMenu.js

index 899a2406419ec2749eae78dc48d34b9060798cfc..6282cd2a26791d5984eade6df62afc715b28ddd4 100644 (file)
@@ -272,15 +272,23 @@ class DropdownMenu extends Plugin {
    */
   _addBodyHandler() {
     const $body = $(document.body);
-    $body
-      .off('click.zf.dropdownMenu tap.zf.dropdownMenu')
-      .on('click.zf.dropdownMenu tap.zf.dropdownMenu', (e) => {
-        var $link = this.$element.find(e.target);
-        if ($link.length) return;
-
-        this._hide();
-        $body.off('click.zf.dropdownMenu tap.zf.dropdownMenu');
-      });
+    this._removeBodyHandler();
+    $body.on('click.zf.dropdownMenu tap.zf.dropdownMenu', (e) => {
+      var $link = this.$element.find(e.target);
+      if ($link.length) return;
+
+      this._hide();
+      this._removeBodyHandler();
+    });
+  }
+
+  /**
+   * Remove the body event handler. See `_addBodyHandler`.
+   * @function
+   * @private
+   */
+  _removeBodyHandler() {
+    $(document.body).off('click.zf.dropdownMenu tap.zf.dropdownMenu');
   }
 
   /**
@@ -353,6 +361,8 @@ class DropdownMenu extends Plugin {
                 .addClass(`opens-${oldClass}`);
         this.changed = false;
       }
+      this._removeBodyHandler();
+
       /**
        * Fires when the open menus are closed.
        * @event DropdownMenu#hide