Skip to content

Commit

Permalink
fix Safari 13 addEventListener on MediaQueryList
Browse files Browse the repository at this point in the history
  • Loading branch information
niko-ng committed Jul 28, 2024
1 parent 26f6ea3 commit 59c56cc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/domobserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ export class DOMObserver {

addWindowListeners(win: Window) {
win.addEventListener("resize", this.onResize)
if (this.printQuery) this.printQuery.addEventListener("change", this.onPrint)
if (this.printQuery) {
if (this.printQuery.addEventListener) this.printQuery.addEventListener("change", this.onPrint)
else this.printQuery.addListener(this.onPrint)
}
else win.addEventListener("beforeprint", this.onPrint)
win.addEventListener("scroll", this.onScroll)
win.document.addEventListener("selectionchange", this.onSelectionChange)
Expand All @@ -437,7 +440,10 @@ export class DOMObserver {
removeWindowListeners(win: Window) {
win.removeEventListener("scroll", this.onScroll)
win.removeEventListener("resize", this.onResize)
if (this.printQuery) this.printQuery.removeEventListener("change", this.onPrint)
if (this.printQuery) {
if (this.printQuery.removeEventListener) this.printQuery.removeEventListener("change", this.onPrint)
else this.printQuery.removeListener(this.onPrint)
}
else win.removeEventListener("beforeprint", this.onPrint)
win.document.removeEventListener("selectionchange", this.onSelectionChange)
}
Expand Down

0 comments on commit 59c56cc

Please sign in to comment.