DEV: Fix some js deprecations (#28915)

1. `MediaQueryList.addListener` is deprecated in favor of `addEventListener`
2. `HTMLStyleElement.type` is deprecated with no replacement
This commit is contained in:
Jarek Radosz 2024-09-16 13:56:54 +02:00 committed by GitHub
parent d7293eafef
commit 8a57e50664
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View File

@ -94,7 +94,7 @@ export default class AceEditor extends Component {
this.appEvents.on("ace:resize", this.resize);
window.addEventListener("resize", this.resize);
this._darkModeListener = window.matchMedia("(prefers-color-scheme: dark)");
this._darkModeListener.addListener(this.setAceTheme);
this._darkModeListener.addEventListener("change", this.setAceTheme);
}
willDestroy() {
@ -102,7 +102,7 @@ export default class AceEditor extends Component {
this.editor?.destroy();
this._darkModeListener?.removeListener(this.setAceTheme);
this._darkModeListener?.removeEventListener("change", this.setAceTheme);
window.removeEventListener("resize", this.resize);
this.appEvents.off("ace:resize", this.resize);
}

View File

@ -12,11 +12,8 @@ export default {
* with the hashtag type via api.registerHashtagType. The default
* ones in core are CategoryHashtagType and TagHashtagType.
*/
initialize(owner) {
this.site = owner.lookup("service:site");
initialize() {
const cssTag = document.createElement("style");
cssTag.type = "text/css";
cssTag.id = "hashtag-css-generator";
cssTag.innerHTML = Object.values(getHashtagTypeClasses())
.map((hashtagType) => hashtagType.generatePreloadedCssClasses())

View File

@ -10,10 +10,17 @@ export default {
if (caps.isAppWebview) {
window
.matchMedia("(prefers-color-scheme: dark)")
.addListener(this.updateAppBackground);
.addEventListener("change", this.updateAppBackground);
this.updateAppBackground();
}
},
teardown() {
window
.matchMedia("(prefers-color-scheme: dark)")
.removeEventListener("change", this.updateAppBackground);
},
updateAppBackground() {
discourseLater(() => {
const header = document.querySelector(".d-header-wrap .d-header");