Skip to content

Commit 844669d

Browse files
committed
Merge branch 'james-em-scrollable-container'
2 parents b9d175f + b7a72da commit 844669d

7 files changed

+32
-49
lines changed

Diff for: dist/handy-scroll.es6.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,21 @@ https://amphiluke.github.io/handy-scroll/
1111

1212
let slice = Array.prototype.slice;
1313

14-
// Precaution to avoid reference errors when imported for SSR (issue #13)
15-
let isDOMAvailable = typeof document === "object" && !!document.documentElement;
16-
1714
let dom = {
18-
isDOMAvailable,
19-
20-
doc: isDOMAvailable ? document : null,
21-
html: isDOMAvailable ? document.documentElement : null,
22-
body: isDOMAvailable ? document.body : null,
15+
// Precaution to avoid reference errors when imported for SSR (issue #13)
16+
isDOMAvailable: typeof document === "object" && !!document.documentElement,
2317

2418
ready(handler) {
25-
if (dom.doc.readyState === "loading") {
26-
dom.doc.addEventListener("DOMContentLoaded", () => void handler(), {once: true});
19+
if (document.readyState === "loading") {
20+
document.addEventListener("DOMContentLoaded", () => void handler(), {once: true});
2721
} else {
2822
handler();
2923
}
3024
},
3125

3226
$(ref) {
3327
if (typeof ref === "string") { // ref is a selector
34-
return dom.body.querySelector(ref);
28+
return document.body.querySelector(ref);
3529
}
3630
return ref; // ref is already an element
3731
},
@@ -44,7 +38,7 @@ https://amphiluke.github.io/handy-scroll/
4438
return [ref];
4539
}
4640
if (typeof ref === "string") { // ref is a selector
47-
return slice.call(dom.body.querySelectorAll(ref));
41+
return slice.call(document.body.querySelectorAll(ref));
4842
}
4943
return slice.call(ref); // ref is an array-like object (NodeList or HTMLCollection)
5044
}
@@ -69,9 +63,9 @@ https://amphiluke.github.io/handy-scroll/
6963

7064
initWidget() {
7165
let instance = this;
72-
let widget = instance.widget = dom.doc.createElement("div");
66+
let widget = instance.widget = document.createElement("div");
7367
widget.classList.add("handy-scroll");
74-
let strut = dom.doc.createElement("div");
68+
let strut = document.createElement("div");
7569
strut.style.width = `${instance.container.scrollWidth}px`;
7670
widget.appendChild(strut);
7771
instance.container.appendChild(widget);
@@ -139,7 +133,7 @@ https://amphiluke.github.io/handy-scroll/
139133
let containerRect = container.getBoundingClientRect();
140134
let maxVisibleY = scrollBody ?
141135
scrollBody.getBoundingClientRect().bottom :
142-
window.innerHeight || dom.html.clientHeight;
136+
window.innerHeight || document.documentElement.clientHeight;
143137
mustHide = ((containerRect.bottom <= maxVisibleY) || (containerRect.top > maxVisibleY));
144138
}
145139
if (instance.visible === mustHide) {
@@ -265,7 +259,7 @@ https://amphiluke.github.io/handy-scroll/
265259
*/
266260
destroyDetached() {
267261
instances = instances.filter(instance => {
268-
if (!dom.body.contains(instance.container)) {
262+
if (!document.body.contains(instance.container)) {
269263
instance.destroy();
270264
return false;
271265
}

Diff for: dist/handy-scroll.es6.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/handy-scroll.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@ https://amphiluke.github.io/handy-scroll/
1010
})(this, (function () { 'use strict';
1111

1212
var slice = Array.prototype.slice;
13-
14-
// Precaution to avoid reference errors when imported for SSR (issue #13)
15-
var isDOMAvailable = typeof document === "object" && !!document.documentElement;
1613
var dom = {
17-
isDOMAvailable: isDOMAvailable,
18-
doc: isDOMAvailable ? document : null,
19-
html: isDOMAvailable ? document.documentElement : null,
20-
body: isDOMAvailable ? document.body : null,
14+
// Precaution to avoid reference errors when imported for SSR (issue #13)
15+
isDOMAvailable: typeof document === "object" && !!document.documentElement,
2116
ready: function ready(handler) {
22-
if (dom.doc.readyState === "loading") {
23-
dom.doc.addEventListener("DOMContentLoaded", function () {
17+
if (document.readyState === "loading") {
18+
document.addEventListener("DOMContentLoaded", function () {
2419
return void handler();
2520
}, {
2621
once: true
@@ -32,7 +27,7 @@ https://amphiluke.github.io/handy-scroll/
3227
$: function $(ref) {
3328
if (typeof ref === "string") {
3429
// ref is a selector
35-
return dom.body.querySelector(ref);
30+
return document.body.querySelector(ref);
3631
}
3732
return ref; // ref is already an element
3833
},
@@ -47,7 +42,7 @@ https://amphiluke.github.io/handy-scroll/
4742
}
4843
if (typeof ref === "string") {
4944
// ref is a selector
50-
return slice.call(dom.body.querySelectorAll(ref));
45+
return slice.call(document.body.querySelectorAll(ref));
5146
}
5247
return slice.call(ref); // ref is an array-like object (NodeList or HTMLCollection)
5348
}
@@ -72,9 +67,9 @@ https://amphiluke.github.io/handy-scroll/
7267
},
7368
initWidget: function initWidget() {
7469
var instance = this;
75-
var widget = instance.widget = dom.doc.createElement("div");
70+
var widget = instance.widget = document.createElement("div");
7671
widget.classList.add("handy-scroll");
77-
var strut = dom.doc.createElement("div");
72+
var strut = document.createElement("div");
7873
strut.style.width = instance.container.scrollWidth + "px";
7974
widget.appendChild(strut);
8075
instance.container.appendChild(widget);
@@ -140,7 +135,7 @@ https://amphiluke.github.io/handy-scroll/
140135
var mustHide = widget.scrollWidth <= widget.offsetWidth;
141136
if (!mustHide) {
142137
var containerRect = container.getBoundingClientRect();
143-
var maxVisibleY = scrollBody ? scrollBody.getBoundingClientRect().bottom : window.innerHeight || dom.html.clientHeight;
138+
var maxVisibleY = scrollBody ? scrollBody.getBoundingClientRect().bottom : window.innerHeight || document.documentElement.clientHeight;
144139
mustHide = containerRect.bottom <= maxVisibleY || containerRect.top > maxVisibleY;
145140
}
146141
if (instance.visible === mustHide) {
@@ -268,7 +263,7 @@ https://amphiluke.github.io/handy-scroll/
268263
*/
269264
destroyDetached: function destroyDetached() {
270265
instances = instances.filter(function (instance) {
271-
if (!dom.body.contains(instance.container)) {
266+
if (!document.body.contains(instance.container)) {
272267
instance.destroy();
273268
return false;
274269
}

0 commit comments

Comments
 (0)