DEV: Don't check for ResizeObserver existence (#25419)

We already assume it's there in many other places
This commit is contained in:
Jarek Radosz 2024-01-25 13:47:15 +01:00 committed by GitHub
parent 241eaadc26
commit 4d1ed4a62d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 44 deletions

View File

@ -510,22 +510,20 @@ export default SiteHeaderComponent.extend({
});
}
if ("ResizeObserver" in window) {
this._resizeObserver = new ResizeObserver((entries) => {
for (let entry of entries) {
if (entry.contentRect) {
const headerTop = this.header?.offsetTop;
document.documentElement.style.setProperty(
"--header-top",
`${headerTop}px`
);
this.updateHeaderOffset();
}
this._resizeObserver = new ResizeObserver((entries) => {
for (let entry of entries) {
if (entry.contentRect) {
const headerTop = this.header?.offsetTop;
document.documentElement.style.setProperty(
"--header-top",
`${headerTop}px`
);
this.updateHeaderOffset();
}
});
}
});
this._resizeObserver.observe(this.headerWrap);
}
this._resizeObserver.observe(this.headerWrap);
this._swipeEvents = new SwipeEvents(this.element);
if (this.site.mobileView) {

View File

@ -3,39 +3,31 @@ import NarrowDesktop from "discourse/lib/narrow-desktop";
export default {
initialize(owner) {
NarrowDesktop.init();
let site;
if (!owner.isDestroyed) {
site = owner.lookup("service:site");
site.set("narrowDesktopView", NarrowDesktop.narrowDesktopView);
}
if ("ResizeObserver" in window) {
this._resizeObserver = new ResizeObserver((entries) => {
if (owner.isDestroyed) {
return;
}
for (let entry of entries) {
const oldNarrowDesktopView = site.narrowDesktopView;
const newNarrowDesktopView = NarrowDesktop.isNarrowDesktopView(
entry.contentRect.width
const site = owner.lookup("service:site");
site.set("narrowDesktopView", NarrowDesktop.narrowDesktopView);
this._resizeObserver = new ResizeObserver((entries) => {
if (owner.isDestroyed) {
return;
}
for (let entry of entries) {
const oldNarrowDesktopView = site.narrowDesktopView;
const newNarrowDesktopView = NarrowDesktop.isNarrowDesktopView(
entry.contentRect.width
);
if (oldNarrowDesktopView !== newNarrowDesktopView) {
const applicationController = owner.lookup("controller:application");
site.set("narrowDesktopView", newNarrowDesktopView);
applicationController.set(
"showSidebar",
applicationController.calculateShowSidebar()
);
if (oldNarrowDesktopView !== newNarrowDesktopView) {
const applicationController = owner.lookup(
"controller:application"
);
site.set("narrowDesktopView", newNarrowDesktopView);
applicationController.set(
"showSidebar",
applicationController.calculateShowSidebar()
);
applicationController.appEvents.trigger(
"site-header:force-refresh"
);
}
applicationController.appEvents.trigger("site-header:force-refresh");
}
});
}
});
this._resizeObserver.observe(document.body);
}
this._resizeObserver.observe(document.body);
},
};