forked from CoderLine/alphaTab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added usage of resize observer if available. (CoderLine#516)
- Loading branch information
1 parent
e518b86
commit 7dee4a5
Showing
8 changed files
with
85 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* A very basic polyfill of the ResizeObserver which triggers | ||
* a the callback on window resize for all registered targets. | ||
* @target web | ||
*/ | ||
export class ResizeObserverPolyfill { | ||
private _callback: ResizeObserverCallback; | ||
private _targets = new Set<Element>(); | ||
|
||
public constructor(callback: ResizeObserverCallback) { | ||
this._callback = callback; | ||
window.addEventListener('resize', this.onWindowResize.bind(this), false); | ||
} | ||
|
||
public observe(target: Element) { | ||
this._targets.add(target); | ||
} | ||
|
||
public unobserve(target: Element) { | ||
this._targets.delete(target); | ||
} | ||
|
||
public disconnect() { | ||
this._targets.clear(); | ||
} | ||
|
||
|
||
private onWindowResize() { | ||
const entries: ResizeObserverEntry[] = []; | ||
for (const t of this._targets) { | ||
entries.push({ | ||
target: t, | ||
// not used by alphaTab | ||
contentRect: undefined!, | ||
borderBoxSize: undefined!, | ||
contentBoxSize: [] | ||
}); | ||
} | ||
this._callback(entries, this); | ||
} | ||
} |