]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fix: prevent removing all listeners by checking them before unbinding 11366/head
authorNicolas Coden <nicolas@ncoden.fr>
Sat, 30 Jun 2018 21:16:32 +0000 (23:16 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Sat, 30 Jun 2018 21:25:03 +0000 (23:25 +0200)
$(...).off(undefined) removes all the attached event listeners, including those outside Foundation of unrelated to the issue.

This commit fixes #11360 and probably others issues by checking for variables expected to be listeners names before using it to remove the listeners.

[This fix is compatible with v6.5]

Closes https://github.com/zurb/foundation-sites/issues/11360

js/foundation.magellan.js
js/foundation.offcanvas.js
js/foundation.reveal.js
js/foundation.sticky.js
js/foundation.tabs.js

index 68784a7f00ec21bfccaec39d3201db0273e14004..990c1ada19bf184e78ce081c67b380dd6e486587 100644 (file)
@@ -227,9 +227,8 @@ class Magellan extends Plugin {
       window.location.hash.replace(hash, '');
     }
 
-    $(window)
-      .off('hashchange', this._deepLinkScroll)
-      .off(this.onLoadListener);
+    $(window).off('hashchange', this._deepLinkScroll)
+    if (this.onLoadListener) $(window).off(this.onLoadListener);
   }
 }
 
index 3d442f9fa1107e73ed45c0a8d4c7082d2e5aba3f..8558edeef04e5ee98ce6dd38dfd1b37e1c59ca9c 100644 (file)
@@ -480,7 +480,7 @@ class OffCanvas extends Plugin {
     this.close();
     this.$element.off('.zf.trigger .zf.offCanvas');
     this.$overlay.off('.zf.offCanvas');
-    $(window).off(this.onLoadListener);
+    if (this.onLoadListener) $(window).off(this.onLoadListener);
   }
 }
 
index 27875c26659d1319f7cb2a134a877fc20f6e3a23..b11fba388786861d8d421927ab4099bf0103e244 100644 (file)
@@ -502,9 +502,8 @@ class Reveal extends Plugin {
     }
     this.$element.hide().off();
     this.$anchor.off('.zf');
-    $(window)
-      .off(`.zf.reveal:${this.id}`)
-      .off(this.onLoadListener);
+    $(window).off(`.zf.reveal:${this.id}`)
+    if (this.onLoadListener) $(window).off(this.onLoadListener);
 
     if ($('.reveal:visible').length  === 0) {
       this._removeGlobalClasses(); // also remove .is-reveal-open from the html element when there is no opened reveal
index 9997db5a040be35db770f977203795f3853c8bde..3ae09866ba2d2bb6c4568c6dd7b1dc79d492bb20 100644 (file)
@@ -404,9 +404,8 @@ class Sticky extends Plugin {
     if (this.$anchor && this.$anchor.length) {
       this.$anchor.off('change.zf.sticky');
     }
-    $(window)
-      .off(this.scrollListener)
-      .off(this.onLoadListener);
+    if (this.scrollListener) $(window).off(this.scrollListener)
+    if (this.onLoadListener) $(window).off(this.onLoadListener)
 
     if (this.wasWrapped) {
       this.$element.unwrap();
index b946070ed90f6609b290d39d445f1f3f3b99782b..c8013f367db0f91c700137a7c32c49237d2620a2 100644 (file)
@@ -398,7 +398,9 @@ class Tabs extends Plugin {
       $(window).off('hashchange', this._checkDeepLink);
     }
 
-    $(window).off(this.onLoadListener);
+    if (this.onLoadListener) {
+      $(window).off(this.onLoadListener);
+    }
   }
 }