Skip to content

Commit ee8be18

Browse files
authored
Merge pull request #11366 from ncoden/fix/check-listeners-before-unbind-11360
fix: prevent removing all listeners by checking them before unbinding
2 parents 8a10879 + 2c8485f commit ee8be18

5 files changed

+10
-11
lines changed

js/foundation.magellan.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,8 @@ class Magellan extends Plugin {
227227
window.location.hash.replace(hash, '');
228228
}
229229

230-
$(window)
231-
.off('hashchange', this._deepLinkScroll)
232-
.off(this.onLoadListener);
230+
$(window).off('hashchange', this._deepLinkScroll)
231+
if (this.onLoadListener) $(window).off(this.onLoadListener);
233232
}
234233
}
235234

js/foundation.offcanvas.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ class OffCanvas extends Plugin {
480480
this.close();
481481
this.$element.off('.zf.trigger .zf.offCanvas');
482482
this.$overlay.off('.zf.offCanvas');
483-
$(window).off(this.onLoadListener);
483+
if (this.onLoadListener) $(window).off(this.onLoadListener);
484484
}
485485
}
486486

js/foundation.reveal.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,8 @@ class Reveal extends Plugin {
502502
}
503503
this.$element.hide().off();
504504
this.$anchor.off('.zf');
505-
$(window)
506-
.off(`.zf.reveal:${this.id}`)
507-
.off(this.onLoadListener);
505+
$(window).off(`.zf.reveal:${this.id}`)
506+
if (this.onLoadListener) $(window).off(this.onLoadListener);
508507

509508
if ($('.reveal:visible').length === 0) {
510509
this._removeGlobalClasses(); // also remove .is-reveal-open from the html element when there is no opened reveal

js/foundation.sticky.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,8 @@ class Sticky extends Plugin {
404404
if (this.$anchor && this.$anchor.length) {
405405
this.$anchor.off('change.zf.sticky');
406406
}
407-
$(window)
408-
.off(this.scrollListener)
409-
.off(this.onLoadListener);
407+
if (this.scrollListener) $(window).off(this.scrollListener)
408+
if (this.onLoadListener) $(window).off(this.onLoadListener)
410409

411410
if (this.wasWrapped) {
412411
this.$element.unwrap();

js/foundation.tabs.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ class Tabs extends Plugin {
398398
$(window).off('hashchange', this._checkDeepLink);
399399
}
400400

401-
$(window).off(this.onLoadListener);
401+
if (this.onLoadListener) {
402+
$(window).off(this.onLoadListener);
403+
}
402404
}
403405
}
404406

0 commit comments

Comments
 (0)