Skip to content

Commit ca25cc4

Browse files
committed
https://github.com/elmsln/issues/issues/1977
1 parent adc2c80 commit ca25cc4

File tree

16 files changed

+52
-94
lines changed

16 files changed

+52
-94
lines changed

elements/absolute-position-behavior/src/absolute-position-behavior.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const AbsolutePositionBehaviorClass = function (SuperClass) {
146146
constructor() {
147147
super();
148148
this._ticking = false;
149-
this.scrollTarget = window;
149+
this.scrollTarget = globalThis;
150150
this.auto = false;
151151
this.fitToVisibleBounds = false;
152152
this.for = null;

elements/clean-one/clean-one.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,6 @@ class CleanOne extends PrintBranchMixin(
892892
constructor() {
893893
super();
894894
this.searchTerm = "";
895-
this.HAXCMSThemeSettings.autoScroll = true;
896895
// prettier-ignore
897896
import(
898897
"@lrnwebcomponents/haxcms-elements/lib/ui-components/navigation/site-menu-button.js"
@@ -926,11 +925,6 @@ class CleanOne extends PrintBranchMixin(
926925
}
927926
// only way to hit this
928927
document.body.style.overflow = "hidden";
929-
this.HAXCMSThemeSettings.scrollTarget =
930-
this.shadowRoot.querySelector("#body");
931-
window.AbsolutePositionStateManager.requestAvailability().scrollTarget =
932-
this.HAXCMSThemeSettings.scrollTarget;
933-
934928
// hook up the scroll target
935929
this.shadowRoot.querySelector("scroll-button").target =
936930
this.shadowRoot.querySelector("#haxcms-theme-top");

elements/clean-one/src/clean-one.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,6 @@ class CleanOne extends PrintBranchMixin(
892892
constructor() {
893893
super();
894894
this.searchTerm = "";
895-
this.HAXCMSThemeSettings.autoScroll = true;
896895
// prettier-ignore
897896
import(
898897
"@lrnwebcomponents/haxcms-elements/lib/ui-components/navigation/site-menu-button.js"
@@ -926,11 +925,6 @@ class CleanOne extends PrintBranchMixin(
926925
}
927926
// only way to hit this
928927
document.body.style.overflow = "hidden";
929-
this.HAXCMSThemeSettings.scrollTarget =
930-
this.shadowRoot.querySelector("#body");
931-
window.AbsolutePositionStateManager.requestAvailability().scrollTarget =
932-
this.HAXCMSThemeSettings.scrollTarget;
933-
934928
// hook up the scroll target
935929
this.shadowRoot.querySelector("scroll-button").target =
936930
this.shadowRoot.querySelector("#haxcms-theme-top");

elements/clean-two/clean-two.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ class CleanTwo extends HAXCMSOperationButtons(
562562
}
563563
document.body.style.overflow = "hidden";
564564
this.HAXCMSThemeSettings.scrollTarget =
565-
this.shadowRoot.querySelector(".body-wrapper");
566-
window.AbsolutePositionStateManager.requestAvailability().scrollTarget =
565+
this.shadowRoot.querySelector("main");
566+
globalThis.AbsolutePositionStateManager.requestAvailability().scrollTarget =
567567
this.HAXCMSThemeSettings.scrollTarget;
568568
// shadow ready which means we should be able to open this even on a slow load
569569
// if we are the route in question

elements/clean-two/src/clean-two.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ class CleanTwo extends HAXCMSOperationButtons(
562562
}
563563
document.body.style.overflow = "hidden";
564564
this.HAXCMSThemeSettings.scrollTarget =
565-
this.shadowRoot.querySelector(".body-wrapper");
566-
window.AbsolutePositionStateManager.requestAvailability().scrollTarget =
565+
this.shadowRoot.querySelector("main");
566+
globalThis.AbsolutePositionStateManager.requestAvailability().scrollTarget =
567567
this.HAXCMSThemeSettings.scrollTarget;
568568
// shadow ready which means we should be able to open this even on a slow load
569569
// if we are the route in question

elements/hax-body/hax-body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4036,7 +4036,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
40364036
nextScrollY = Math.max(0, Math.min(maxScrollY, nextScrollY));
40374037

40384038
if (nextScrollX !== currentScrollX || nextScrollY !== currentScrollY) {
4039-
window.scrollTo(nextScrollX, nextScrollY);
4039+
globalThis.scrollTo(nextScrollX, nextScrollY);
40404040
return true;
40414041
} else {
40424042
return false;

elements/hax-body/src/hax-body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4036,7 +4036,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
40364036
nextScrollY = Math.max(0, Math.min(maxScrollY, nextScrollY));
40374037

40384038
if (nextScrollX !== currentScrollX || nextScrollY !== currentScrollY) {
4039-
window.scrollTo(nextScrollX, nextScrollY);
4039+
globalThis.scrollTo(nextScrollX, nextScrollY);
40404040
return true;
40414041
} else {
40424042
return false;

elements/haxcms-elements/lib/core/HAXCMSLitElementTheme.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ class HAXCMSLitElementTheme extends HAXCMSTheme(
3636
this.HAXCMSThemeSettings.scrollTarget &&
3737
this.HAXCMSThemeSettings.scrollTarget.scrollIntoView
3838
) {
39-
this.HAXCMSThemeSettings.scrollTarget.scrollIntoView({
40-
block: "start",
41-
inline: "nearest",
42-
behavior: "smooth",
43-
});
39+
const isSafari = globalThis.safari !== undefined;
40+
if (isSafari) {
41+
this.HAXCMSThemeSettings.scrollTarget.scrollIntoView();
42+
} else {
43+
this.HAXCMSThemeSettings.scrollTarget.scrollIntoView({
44+
behavior: "instant",
45+
block: "start",
46+
inline: "nearest",
47+
});
48+
}
4449
}
4550
// delay bc this shouldn't block page load in any way
4651
setTimeout(() => {
@@ -99,7 +104,7 @@ class HAXCMSLitElementTheme extends HAXCMSTheme(
99104
target.scrollIntoView();
100105
} else {
101106
target.scrollIntoView({
102-
behavior: "smooth",
107+
behavior: "instant",
103108
block: "start",
104109
inline: "nearest",
105110
});
@@ -224,7 +229,7 @@ class HAXCMSLitElementTheme extends HAXCMSTheme(
224229
target.scrollIntoView();
225230
} else {
226231
target.scrollIntoView({
227-
behavior: "smooth",
232+
behavior: "instant",
228233
block: "start",
229234
inline: "nearest",
230235
});
@@ -266,7 +271,7 @@ class HAXCMSLitElementTheme extends HAXCMSTheme(
266271
target.scrollIntoView();
267272
} else {
268273
target.scrollIntoView({
269-
behavior: "smooth",
274+
behavior: "instant",
270275
block: "start",
271276
inline: "nearest",
272277
});

elements/haxcms-elements/lib/core/HAXCMSThemeWiring.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const HAXCMSTheme = function (SuperClass) {
3636
// should we scroll to the top when a new page
3737
// is selected
3838
autoScroll: false,
39-
scrollTarget: window,
39+
scrollTarget: globalThis,
4040
};
4141
this.__disposer = this.__disposer ? this.__disposer : [];
4242
this.HAXCMSThemeWiring = new HAXCMSThemeWiring(this);
@@ -144,18 +144,6 @@ const HAXCMSTheme = function (SuperClass) {
144144
// keep activeItemContent in sync globally
145145
autorun((reaction) => {
146146
this.activeItemContent = toJS(store.activeItemContent);
147-
setTimeout(() => {
148-
if (
149-
this.HAXCMSThemeSettings.autoScroll &&
150-
this.shadowRoot &&
151-
this.HAXCMSThemeSettings.scrollTarget
152-
) {
153-
this.HAXCMSThemeSettings.scrollTarget.scrollTo({
154-
top: 0,
155-
left: 0,
156-
});
157-
}
158-
}, 10);
159147
this.__disposer.push(reaction);
160148
});
161149
// keep editMode in sync globally

elements/haxcms-elements/lib/ui-components/navigation/site-menu-content.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,21 @@ class SiteMenuContent extends HAXCMSThemeParts(PageContentsMenu) {
5757
}
5858

5959
backToTop() {
60-
this.contentContainer.HAXCMSThemeSettings.scrollTarget.scrollTo({
61-
top: 0,
62-
left: 0,
63-
behavior: "smooth",
64-
});
60+
if (
61+
this.contentContainer.HAXCMSThemeSettings.scrollTarget &&
62+
this.contentContainer.HAXCMSThemeSettings.scrollTarget.scrollIntoView
63+
) {
64+
const isSafari = globalThis.safari !== undefined;
65+
if (isSafari) {
66+
this.contentContainer.HAXCMSThemeSettings.scrollTarget.scrollIntoView();
67+
} else {
68+
this.contentContainer.HAXCMSThemeSettings.scrollTarget.scrollIntoView({
69+
behavior: "instant",
70+
block: "start",
71+
inline: "nearest",
72+
});
73+
}
74+
}
6575
}
6676
/**
6777
* wrap the base render function in a part that demonstrates edit mode

elements/haxcms-elements/lib/ui-components/navigation/site-menu.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,6 @@ class SiteMenu extends HAXCMSThemeParts(LitElement) {
182182
"Search",
183183
"pages",
184184
"links",
185-
"find",
186-
"look up",
187-
"search",
188-
"site",
189-
"page",
190185
],
191186
eventName: "super-daemon-run-program",
192187
path: "/sources/site-pages",

elements/page-contents-menu/page-contents-menu.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class PageContentsMenu extends DDD {
248248
objItem = this.contentContainer.querySelector(
249249
"#" + this.items[parseInt(target.getAttribute("data-index"))].id,
250250
);
251-
const isSafari = window.safari !== undefined;
251+
const isSafari = globalThis.safari !== undefined;
252252
if (isSafari) {
253253
objItem.scrollIntoView();
254254
} else {
@@ -259,8 +259,8 @@ class PageContentsMenu extends DDD {
259259
});
260260
}
261261
// keep state in history
262-
window.history.pushState({}, null, target.getAttribute("href"));
263-
window.dispatchEvent(new PopStateEvent("popstate"));
262+
globalThis.history.pushState({}, null, target.getAttribute("href"));
263+
globalThis.dispatchEvent(new PopStateEvent("popstate"));
264264
// close menu
265265
this.hideSettings = true;
266266
}
@@ -364,25 +364,11 @@ class PageContentsMenu extends DDD {
364364
// only useful with mobile
365365
this.hideSettings = true;
366366
this.label = "Contents";
367-
// so we can close the menu
368-
window.addEventListener("click", this.checkMenuOpen.bind(this));
369367
// default to all hierarchy tags to obtain mini-menu
370368
// opens the door for us adding OTHER tags in the future
371369
this.hierarchyTags = ["h1", "h2", "h3", "h4", "h5", "h6"];
372370
}
373371

374-
checkMenuOpen(e) {
375-
var target = normalizeEventPath(e)[0];
376-
if (
377-
this.mobile &&
378-
!this.hideSettings &&
379-
target.includes &&
380-
!target.includes(this.__toggleTarget) &&
381-
!target.includes(this.shadowRoot.querySelector("simple-popover"))
382-
) {
383-
this.hideSettings = true;
384-
}
385-
}
386372
firstUpdated(changedProperties) {
387373
if (super.firstUpdated) {
388374
super.firstUpdated(changedProperties);
@@ -610,7 +596,7 @@ class PageContentsMenu extends DDD {
610596
if (super.connectedCallback) {
611597
super.connectedCallback();
612598
}
613-
window.addEventListener("scroll", this._applyScrollDetect.bind(this), {
599+
globalThis.addEventListener("scroll", this._applyScrollDetect.bind(this), {
614600
signal: this.windowControllers.signal,
615601
});
616602
}

elements/page-contents-menu/src/page-contents-menu.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class PageContentsMenu extends DDD {
248248
objItem = this.contentContainer.querySelector(
249249
"#" + this.items[parseInt(target.getAttribute("data-index"))].id,
250250
);
251-
const isSafari = window.safari !== undefined;
251+
const isSafari = globalThis.safari !== undefined;
252252
if (isSafari) {
253253
objItem.scrollIntoView();
254254
} else {
@@ -259,8 +259,8 @@ class PageContentsMenu extends DDD {
259259
});
260260
}
261261
// keep state in history
262-
window.history.pushState({}, null, target.getAttribute("href"));
263-
window.dispatchEvent(new PopStateEvent("popstate"));
262+
globalThis.history.pushState({}, null, target.getAttribute("href"));
263+
globalThis.dispatchEvent(new PopStateEvent("popstate"));
264264
// close menu
265265
this.hideSettings = true;
266266
}
@@ -364,25 +364,11 @@ class PageContentsMenu extends DDD {
364364
// only useful with mobile
365365
this.hideSettings = true;
366366
this.label = "Contents";
367-
// so we can close the menu
368-
window.addEventListener("click", this.checkMenuOpen.bind(this));
369367
// default to all hierarchy tags to obtain mini-menu
370368
// opens the door for us adding OTHER tags in the future
371369
this.hierarchyTags = ["h1", "h2", "h3", "h4", "h5", "h6"];
372370
}
373371

374-
checkMenuOpen(e) {
375-
var target = normalizeEventPath(e)[0];
376-
if (
377-
this.mobile &&
378-
!this.hideSettings &&
379-
target.includes &&
380-
!target.includes(this.__toggleTarget) &&
381-
!target.includes(this.shadowRoot.querySelector("simple-popover"))
382-
) {
383-
this.hideSettings = true;
384-
}
385-
}
386372
firstUpdated(changedProperties) {
387373
if (super.firstUpdated) {
388374
super.firstUpdated(changedProperties);
@@ -610,7 +596,7 @@ class PageContentsMenu extends DDD {
610596
if (super.connectedCallback) {
611597
super.connectedCallback();
612598
}
613-
window.addEventListener("scroll", this._applyScrollDetect.bind(this), {
599+
globalThis.addEventListener("scroll", this._applyScrollDetect.bind(this), {
614600
signal: this.windowControllers.signal,
615601
});
616602
}

elements/polaris-theme/lib/polaris-invent-theme.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ class PolarisInventTheme extends HAXCMSOperationButtons(
534534
${this.HAXCMSMobileMenu()}
535535
</div>
536536
</div>
537-
<main>
537+
<main id="main">
538538
<article id="contentcontainer">
539539
<site-active-title part="page-title"></site-active-title>
540540
<site-active-tags
@@ -691,7 +691,6 @@ class PolarisInventTheme extends HAXCMSOperationButtons(
691691
// this way we can have blocks whos definitions only get
692692
// loaded in when we have a theme that intentionally
693693
// has been designed around them
694-
this.HAXCMSThemeSettings.autoScroll = true;
695694
this.searchTerm = "";
696695
this.imageAlt = "";
697696
this.image = "";
@@ -730,6 +729,7 @@ class PolarisInventTheme extends HAXCMSOperationButtons(
730729
this.__disposer.push(reaction);
731730
});
732731
}
732+
733733
/**
734734
* Delay importing site-search until we click to open it directly
735735
*/

elements/scroll-button/scroll-button.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ScrollButton extends LitElement {
1818
this.t = {
1919
backToTop: "Back to top",
2020
};
21-
window.dispatchEvent(
21+
globalThis.dispatchEvent(
2222
new CustomEvent("i18n-manager-register-element", {
2323
detail: {
2424
context: this,
@@ -144,11 +144,11 @@ class ScrollButton extends LitElement {
144144
if (this.target) {
145145
this.target.scrollIntoView({
146146
behavior: "smooth",
147-
block: "end",
147+
block: "start",
148148
inline: "nearest",
149149
});
150150
} else {
151-
window.scrollTo({
151+
globalThis.scrollTo({
152152
top: 0,
153153
left: 0,
154154
behavior: "smooth",

elements/scroll-button/src/scroll-button.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ScrollButton extends LitElement {
1818
this.t = {
1919
backToTop: "Back to top",
2020
};
21-
window.dispatchEvent(
21+
globalThis.dispatchEvent(
2222
new CustomEvent("i18n-manager-register-element", {
2323
detail: {
2424
context: this,
@@ -144,11 +144,11 @@ class ScrollButton extends LitElement {
144144
if (this.target) {
145145
this.target.scrollIntoView({
146146
behavior: "smooth",
147-
block: "end",
147+
block: "start",
148148
inline: "nearest",
149149
});
150150
} else {
151-
window.scrollTo({
151+
globalThis.scrollTo({
152152
top: 0,
153153
left: 0,
154154
behavior: "smooth",

0 commit comments

Comments
 (0)