mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:03:43 +08:00
DEV: Don't check for ResizeObserver existence (#25419)
We already assume it's there in many other places
This commit is contained in:
parent
241eaadc26
commit
4d1ed4a62d
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user