Commit 71d41e5b authored by Fred Chasen's avatar Fred Chasen

Fix removeEventListeners

parent bf266113
...@@ -168,18 +168,20 @@ class Page { ...@@ -168,18 +168,20 @@ class Page {
if (typeof ResizeObserver !== "undefined") { if (typeof ResizeObserver !== "undefined") {
this.addResizeObserver(contents); this.addResizeObserver(contents);
} else { } else {
this.element.addEventListener("overflow", this.checkOverflowAfterResize.bind(this, contents), false); this._checkOverflowAfterResize = this.checkOverflowAfterResize.bind(this, contents);
this.element.addEventListener("underflow", this.checkOverflowAfterResize.bind(this, contents), false); this.element.addEventListener("overflow", this._checkOverflowAfterResize, false);
this.element.addEventListener("underflow", this._checkOverflowAfterResize, false);
} }
// TODO: fall back to mutation observer? // TODO: fall back to mutation observer?
this._onScroll = function() {
// Keep scroll left from changing
this.element.addEventListener("scroll", () => {
if(this.listening) { if(this.listening) {
this.element.scrollLeft = 0; this.element.scrollLeft = 0;
} }
}); }.bind(this);
// Keep scroll left from changing
this.element.addEventListener("scroll", this._onScroll);
this.listening = true; this.listening = true;
...@@ -188,16 +190,16 @@ class Page { ...@@ -188,16 +190,16 @@ class Page {
removeListeners() { removeListeners() {
this.listening = false; this.listening = false;
// clearTimeout(this.timeoutAfterResize);
if (this.element) { if (typeof ResizeObserver !== "undefined" && this.ro) {
this.element.removeEventListener("overflow", this.checkOverflowAfterResize.bind(this), false);
this.element.removeEventListener("underflow", this.checkOverflowAfterResize.bind(this), false);
}
if (this.ro) {
this.ro.disconnect(); this.ro.disconnect();
} else if (this.element) {
this.element.removeEventListener("overflow", this._checkOverflowAfterResize, false);
this.element.removeEventListener("underflow", this._checkOverflowAfterResize, false);
} }
this.element &&this.element.removeEventListener("scroll", this._onScroll);
} }
addResizeObserver(contents) { addResizeObserver(contents) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment