Skip to content

Commit 4fe83f1

Browse files
committed
maint(pat scroll): Use new core.dom.find_scroll_container instead own implementation.
1 parent 20cd8b4 commit 4fe83f1

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

src/pat/scroll/scroll.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "regenerator-runtime/runtime"; // needed for ``await`` support
22
import "../../core/jquery-ext";
33
import $ from "jquery";
44
import Base from "../../core/base";
5+
import dom from "../../core/dom";
56
import logging from "../../core/logging";
67
import Parser from "../../core/parser";
78
import utils from "../../core/utils";
@@ -123,26 +124,6 @@ export default Base.extend({
123124
}
124125
},
125126

126-
findScrollContainer(el) {
127-
const direction = this.options.direction;
128-
let scrollable = $(el)
129-
.parents()
130-
.filter((idx, el) => {
131-
return (
132-
["auto", "scroll"].indexOf($(el).css("overflow")) > -1 ||
133-
(direction === "top" &&
134-
["auto", "scroll"].indexOf($(el).css("overflow-y")) > -1) ||
135-
(direction === "left" &&
136-
["auto", "scroll"].indexOf($(el).css("overflow-x")) > -1)
137-
);
138-
})
139-
.first();
140-
if (typeof scrollable[0] === "undefined") {
141-
scrollable = $("body");
142-
}
143-
return scrollable;
144-
},
145-
146127
_get_selector_target() {
147128
const selector = this.options.selector;
148129
if (!selector && this.el.href?.includes("#")) {
@@ -162,11 +143,21 @@ export default Base.extend({
162143
let scrollable;
163144
if (this.options.selector === "top") {
164145
// Just scroll up or left, period.
165-
scrollable = this.findScrollContainer(this.$el);
146+
scrollable = $(
147+
dom.find_scroll_container(
148+
this.el.parentElement,
149+
this.options.direction === "top" ? "y" : "x"
150+
)
151+
);
166152
options[scroll] = 0;
167153
} else if (this.options.selector === "bottom") {
168154
// Just scroll down or right, period.
169-
scrollable = this.findScrollContainer(this.$el);
155+
scrollable = $(
156+
dom.find_scroll_container(
157+
this.el.parentElement,
158+
this.options.direction === "top" ? "y" : "x"
159+
)
160+
);
170161
if (scroll === "scrollTop") {
171162
options.scrollTop = scrollable[0].scrollHeight;
172163
} else {
@@ -184,7 +175,12 @@ export default Base.extend({
184175
return;
185176
}
186177

187-
scrollable = this.findScrollContainer(target);
178+
scrollable = $(
179+
dom.find_scroll_container(
180+
target[0].parentElement,
181+
this.options.direction === "top" ? "y" : "x"
182+
)
183+
);
188184

189185
if (scrollable[0] === document.body) {
190186
// positioning context is document

src/pat/scroll/scroll.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe("pat-scroll", function () {
122122

123123
it("will scroll to bottom with selector:bottom", async () => {
124124
document.body.innerHTML = `
125-
<div id="scroll-container" style="overflow: scroll">
125+
<div id="scroll-container" style="overflow-y: scroll">
126126
<button class="pat-scroll" data-pat-scroll="selector: bottom; trigger: manual">to bottom</button>
127127
</div>
128128
`;
@@ -149,7 +149,7 @@ describe("pat-scroll", function () {
149149
// Testing with `selector: top`, as this just sets scrollTop to 0
150150

151151
document.body.innerHTML = `
152-
<div id="scroll-container" style="overflow: scroll">
152+
<div id="scroll-container" style="overflow-y: scroll">
153153
<button class="pat-scroll" data-pat-scroll="selector: top; offset: 40; trigger: manual">to bottom</button>
154154
</div>
155155
`;
@@ -173,7 +173,7 @@ describe("pat-scroll", function () {
173173
// Testing with `selector: top`, as this just sets scrollTop to 0
174174

175175
document.body.innerHTML = `
176-
<div id="scroll-container" style="overflow: scroll">
176+
<div id="scroll-container" style="overflow-y: scroll">
177177
<button class="pat-scroll" data-pat-scroll="selector: top; offset: -40; trigger: manual">to bottom</button>
178178
</div>
179179
`;

0 commit comments

Comments
 (0)