@@ -10,17 +10,12 @@ https://amphiluke.github.io/handy-scroll/
10
10
} ) ( this , ( function ( ) { 'use strict' ;
11
11
12
12
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 ;
16
13
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 ,
21
16
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 ( ) {
24
19
return void handler ( ) ;
25
20
} , {
26
21
once : true
@@ -32,7 +27,7 @@ https://amphiluke.github.io/handy-scroll/
32
27
$ : function $ ( ref ) {
33
28
if ( typeof ref === "string" ) {
34
29
// ref is a selector
35
- return dom . body . querySelector ( ref ) ;
30
+ return document . body . querySelector ( ref ) ;
36
31
}
37
32
return ref ; // ref is already an element
38
33
} ,
@@ -47,7 +42,7 @@ https://amphiluke.github.io/handy-scroll/
47
42
}
48
43
if ( typeof ref === "string" ) {
49
44
// ref is a selector
50
- return slice . call ( dom . body . querySelectorAll ( ref ) ) ;
45
+ return slice . call ( document . body . querySelectorAll ( ref ) ) ;
51
46
}
52
47
return slice . call ( ref ) ; // ref is an array-like object (NodeList or HTMLCollection)
53
48
}
@@ -72,9 +67,9 @@ https://amphiluke.github.io/handy-scroll/
72
67
} ,
73
68
initWidget : function initWidget ( ) {
74
69
var instance = this ;
75
- var widget = instance . widget = dom . doc . createElement ( "div" ) ;
70
+ var widget = instance . widget = document . createElement ( "div" ) ;
76
71
widget . classList . add ( "handy-scroll" ) ;
77
- var strut = dom . doc . createElement ( "div" ) ;
72
+ var strut = document . createElement ( "div" ) ;
78
73
strut . style . width = instance . container . scrollWidth + "px" ;
79
74
widget . appendChild ( strut ) ;
80
75
instance . container . appendChild ( widget ) ;
@@ -140,7 +135,7 @@ https://amphiluke.github.io/handy-scroll/
140
135
var mustHide = widget . scrollWidth <= widget . offsetWidth ;
141
136
if ( ! mustHide ) {
142
137
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 ;
144
139
mustHide = containerRect . bottom <= maxVisibleY || containerRect . top > maxVisibleY ;
145
140
}
146
141
if ( instance . visible === mustHide ) {
@@ -268,7 +263,7 @@ https://amphiluke.github.io/handy-scroll/
268
263
*/
269
264
destroyDetached : function destroyDetached ( ) {
270
265
instances = instances . filter ( function ( instance ) {
271
- if ( ! dom . body . contains ( instance . container ) ) {
266
+ if ( ! document . body . contains ( instance . container ) ) {
272
267
instance . destroy ( ) ;
273
268
return false ;
274
269
}
0 commit comments