realm_logo: Add fallback for MediaQueryList.addEventListener.

MediaQueryList.addEventListener is missing in Safari < 14:
https://caniuse.com/mdn-api_mediaquerylist_eventtarget_inheritance

Fixes #23915.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-12-24 20:32:51 -08:00 committed by Tim Abbott
parent 5fda9f3439
commit 9dbb43eb71
1 changed files with 9 additions and 3 deletions

View File

@ -105,10 +105,16 @@ export function initialize() {
render();
// Rerender the realm-logo when the browser detects color scheme changes.
const dark_mode_media_query_list = window.matchMedia("(prefers-color-scheme: dark)");
dark_mode_media_query_list.addEventListener("change", () => {
const media_query_list = window.matchMedia("(prefers-color-scheme: dark)");
// MediaQueryList.addEventListener is missing in Safari < 14
const listener = () => {
if ($(":root").hasClass("color-scheme-automatic")) {
render();
}
});
};
if ("addEventListener" in media_query_list) {
media_query_list.addEventListener("change", listener);
} else {
media_query_list.addListener(listener);
}
}