From 6f5021f5ab68ccb67e7e0003288f18b0ceba84fd Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Fri, 6 Jul 2018 22:28:24 +0200 Subject: [PATCH] Use pull request #11366 from ncoden/fix/check-listeners-before-unbind-11360 for v6.5.0 2c8485f32 fix: prevent removing all listeners by checking them before unbinding Signed-off-by: Nicolas Coden --- js/foundation.magellan.js | 5 ++--- js/foundation.offcanvas.js | 2 +- js/foundation.reveal.js | 5 ++--- js/foundation.sticky.js | 5 ++--- js/foundation.tabs.js | 4 +++- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/js/foundation.magellan.js b/js/foundation.magellan.js index b37ca40f2..3566b64e8 100644 --- a/js/foundation.magellan.js +++ b/js/foundation.magellan.js @@ -223,9 +223,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); } } diff --git a/js/foundation.offcanvas.js b/js/foundation.offcanvas.js index 3a155692d..a6b65045c 100644 --- a/js/foundation.offcanvas.js +++ b/js/foundation.offcanvas.js @@ -447,7 +447,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); } } diff --git a/js/foundation.reveal.js b/js/foundation.reveal.js index 80444e194..130c59bde 100644 --- a/js/foundation.reveal.js +++ b/js/foundation.reveal.js @@ -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 diff --git a/js/foundation.sticky.js b/js/foundation.sticky.js index 15bd7b140..b9db45f0c 100644 --- a/js/foundation.sticky.js +++ b/js/foundation.sticky.js @@ -403,9 +403,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(); diff --git a/js/foundation.tabs.js b/js/foundation.tabs.js index 48921ee35..0e2140fc6 100644 --- a/js/foundation.tabs.js +++ b/js/foundation.tabs.js @@ -394,7 +394,9 @@ class Tabs extends Plugin { $(window).off('hashchange', this._checkDeepLink); } - $(window).off(this.onLoadListener); + if (this.onLoadListener) { + $(window).off(this.onLoadListener); + } } } -- 2.47.2