$(...).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
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);
}
}
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);
}
}
}
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
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();
$(window).off('hashchange', this._checkDeepLink);
}
- $(window).off(this.onLoadListener);
+ if (this.onLoadListener) {
+ $(window).off(this.onLoadListener);
+ }
}
}