diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2022-10-26 21:17:21 +0100 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2022-10-26 21:57:53 +0100 |
| commit | 6f5debe417dbcb4b17be00fa4790b80ed887158c (patch) | |
| tree | ce7550029c606d0357cef3172238a5ce8fd79be2 | |
| parent | 7354790ca40aa648f8ce6a6f0e568b9971a6a42c (diff) | |
| download | puzzles-6f5debe417dbcb4b17be00fa4790b80ed887158c.zip puzzles-6f5debe417dbcb4b17be00fa4790b80ed887158c.tar.gz puzzles-6f5debe417dbcb4b17be00fa4790b80ed887158c.tar.bz2 puzzles-6f5debe417dbcb4b17be00fa4790b80ed887158c.tar.xz | |
js: Make update_pixel_ratio more backward-compatible
Despite my stylistic downgrades, it still used two features not present
in Firefox 48, and hence KaiOS 2.5: passing options to addEventListener,
and calling addEventListener on a MediaQueryList at all. Now it uses
the older addListener method and explicitly removes each listener as
soon as it's called.
| -rw-r--r-- | emccpre.js | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -527,13 +527,16 @@ function initPuzzle() { /* * Arrange to detect changes of device pixel ratio. Adapted from * <https://developer.mozilla.org/en-US/docs/Web/API/Window/ - * devicePixelRatio> (CC0). + * devicePixelRatio> (CC0) to work on older browsers. */ + var mql = null; var update_pixel_ratio = function() { var dpr = window.devicePixelRatio; + if (mql !== null) + mql.removeListener(update_pixel_ratio); resizable_div.style.width = onscreen_canvas.width / dpr + "px"; - matchMedia(`(resolution: ${dpr}dppx)`) - .addEventListener("change", update_pixel_ratio, { once: true }) + mql = window.matchMedia(`(resolution: ${dpr}dppx)`); + mql.addListener(update_pixel_ratio); } update_pixel_ratio(); |