handy-scroll 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handy-scroll.d.ts +10 -0
- package/dist/handy-scroll.es6.js +5 -5
- package/dist/handy-scroll.es6.min.js +2 -2
- package/dist/handy-scroll.js +28 -51
- package/dist/handy-scroll.min.js +2 -2
- package/package.json +23 -13
- package/src/handy-scroll.js +3 -3
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare namespace handyScroll {
|
|
2
|
+
export function mount(containerRef: HTMLElement | NodeList | HTMLCollection | HTMLElement[] | string): void;
|
|
3
|
+
export function mounted(containerRef: HTMLElement | string): boolean;
|
|
4
|
+
export function update(containerRef: HTMLElement | NodeList | HTMLCollection | HTMLElement[] | string): void;
|
|
5
|
+
export function destroy(containerRef: HTMLElement | NodeList | HTMLCollection | HTMLElement[] | string): void;
|
|
6
|
+
export function destroyDetached(): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default handyScroll;
|
|
10
|
+
export as namespace handyScroll;
|
package/dist/handy-scroll.es6.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
handy-scroll v1.1.
|
|
2
|
+
handy-scroll v1.1.2
|
|
3
3
|
https://amphiluke.github.io/handy-scroll/
|
|
4
|
-
(c)
|
|
4
|
+
(c) 2023 Amphiluke
|
|
5
5
|
*/
|
|
6
6
|
(function (global, factory) {
|
|
7
7
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -205,7 +205,7 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
205
205
|
let handyScroll = {
|
|
206
206
|
/**
|
|
207
207
|
* Mount widgets in the given containers
|
|
208
|
-
* @param {HTMLElement|NodeList|HTMLCollection|
|
|
208
|
+
* @param {HTMLElement|NodeList|HTMLCollection|HTMLElement[]|String} containerRef - Widget container reference (either an element, or a list of elements, or a selector)
|
|
209
209
|
*/
|
|
210
210
|
mount(containerRef) {
|
|
211
211
|
dom.$$(containerRef).forEach(container => {
|
|
@@ -230,7 +230,7 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
230
230
|
|
|
231
231
|
/**
|
|
232
232
|
* Update widget parameters and position
|
|
233
|
-
* @param {HTMLElement|NodeList|HTMLCollection|
|
|
233
|
+
* @param {HTMLElement|NodeList|HTMLCollection|HTMLElement[]|String} containerRef - Widget container reference (either an element, or a list of elements, or a selector)
|
|
234
234
|
*/
|
|
235
235
|
update(containerRef) {
|
|
236
236
|
dom.$$(containerRef).forEach(container => {
|
|
@@ -246,7 +246,7 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
246
246
|
|
|
247
247
|
/**
|
|
248
248
|
* Destroy widgets mounted in the given containers
|
|
249
|
-
* @param {HTMLElement|NodeList|HTMLCollection|
|
|
249
|
+
* @param {HTMLElement|NodeList|HTMLCollection|HTMLElement[]|String} containerRef - Widget container reference (either an element, or a list of elements, or a selector)
|
|
250
250
|
*/
|
|
251
251
|
destroy(containerRef) {
|
|
252
252
|
dom.$$(containerRef).forEach(container => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
handy-scroll v1.1.
|
|
2
|
+
handy-scroll v1.1.2
|
|
3
3
|
https://amphiluke.github.io/handy-scroll/
|
|
4
|
-
(c)
|
|
4
|
+
(c) 2023 Amphiluke
|
|
5
5
|
*/
|
|
6
6
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).handyScroll=t()}(this,(function(){"use strict";let e=Array.prototype.slice,t="object"==typeof document&&!!document.documentElement,i={isDOMAvailable:t,doc:t?document:null,html:t?document.documentElement:null,body:t?document.body:null,ready(e){"loading"===i.doc.readyState?i.doc.addEventListener("DOMContentLoaded",(()=>{e()}),{once:!0}):e()},$:e=>"string"==typeof e?i.body.querySelector(e):e,$$:t=>Array.isArray(t)?t:t.nodeType===Node.ELEMENT_NODE?[t]:"string"==typeof t?e.call(i.body.querySelectorAll(t)):e.call(t)},n={init(e){let t=this,n=i.$$(".handy-scroll-body").filter((t=>t.contains(e)));n.length&&(t.scrollBody=n[0]),t.container=e,t.visible=!0,t.initWidget(),t.update(),t.addEventHandlers(),t.skipSyncContainer=t.skipSyncWidget=!1},initWidget(){let e=this,t=e.widget=i.doc.createElement("div");t.classList.add("handy-scroll");let n=i.doc.createElement("div");n.style.width=`${e.container.scrollWidth}px`,t.appendChild(n),e.container.appendChild(t)},addEventHandlers(){let e=this;(e.eventHandlers=[{el:e.scrollBody||window,handlers:{scroll(){e.checkVisibility()},resize(){e.update()}}},{el:e.widget,handlers:{scroll(){e.visible&&!e.skipSyncContainer&&e.syncContainer(),e.skipSyncContainer=!1}}},{el:e.container,handlers:{scroll(){e.skipSyncWidget||e.syncWidget(),e.skipSyncWidget=!1},focusin(){setTimeout((()=>{e.widget&&e.syncWidget()}),0)}}}]).forEach((({el:e,handlers:t})=>{Object.keys(t).forEach((i=>e.addEventListener(i,t[i],!1)))}))},checkVisibility(){let e=this,{widget:t,container:n,scrollBody:l}=e,o=t.scrollWidth<=t.offsetWidth;if(!o){let e=n.getBoundingClientRect(),t=l?l.getBoundingClientRect().bottom:window.innerHeight||i.html.clientHeight;o=e.bottom<=t||e.top>t}e.visible===o&&(e.visible=!o,t.classList.toggle("handy-scroll-hidden"))},syncContainer(){let e=this,{scrollLeft:t}=e.widget;e.container.scrollLeft!==t&&(e.skipSyncWidget=!0,e.container.scrollLeft=t)},syncWidget(){let e=this,{scrollLeft:t}=e.container;e.widget.scrollLeft!==t&&(e.skipSyncContainer=!0,e.widget.scrollLeft=t)},update(){let e=this,{widget:t,container:i,scrollBody:n}=e,{clientWidth:l,scrollWidth:o}=i;t.style.width=`${l}px`,n||(t.style.left=`${i.getBoundingClientRect().left}px`),t.firstElementChild.style.width=`${o}px`,o>l&&(t.style.height=t.offsetHeight-t.clientHeight+1+"px"),e.syncWidget(),e.checkVisibility()},destroy(){let e=this;e.eventHandlers.forEach((({el:e,handlers:t})=>{Object.keys(t).forEach((i=>e.removeEventListener(i,t[i],!1)))})),e.widget.parentNode.removeChild(e.widget),e.eventHandlers=e.widget=e.container=e.scrollBody=null}},l=[],o={mount(e){i.$$(e).forEach((e=>{if(o.mounted(e))return;let t=Object.create(n);l.push(t),t.init(e)}))},mounted(e){let t=i.$(e);return l.some((e=>e.container===t))},update(e){i.$$(e).forEach((e=>{l.some((t=>t.container===e&&(t.update(),!0)))}))},destroy(e){i.$$(e).forEach((e=>{l.some(((t,i)=>t.container===e&&(l.splice(i,1)[0].destroy(),!0)))}))},destroyDetached(){l=l.filter((e=>!!i.body.contains(e.container)||(e.destroy(),!1)))}};return i.isDOMAvailable&&i.ready((()=>{o.mount("[data-handy-scroll]")})),o}));
|
package/dist/handy-scroll.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
handy-scroll v1.1.
|
|
2
|
+
handy-scroll v1.1.2
|
|
3
3
|
https://amphiluke.github.io/handy-scroll/
|
|
4
|
-
(c)
|
|
4
|
+
(c) 2023 Amphiluke
|
|
5
5
|
*/
|
|
6
6
|
(function (global, factory) {
|
|
7
7
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -9,8 +9,9 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
9
9
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.handyScroll = factory());
|
|
10
10
|
})(this, (function () { 'use strict';
|
|
11
11
|
|
|
12
|
-
var slice = Array.prototype.slice;
|
|
12
|
+
var slice = Array.prototype.slice;
|
|
13
13
|
|
|
14
|
+
// Precaution to avoid reference errors when imported for SSR (issue #13)
|
|
14
15
|
var isDOMAvailable = typeof document === "object" && !!document.documentElement;
|
|
15
16
|
var dom = {
|
|
16
17
|
isDOMAvailable: isDOMAvailable,
|
|
@@ -33,7 +34,6 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
33
34
|
// ref is a selector
|
|
34
35
|
return dom.body.querySelector(ref);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
37
|
return ref; // ref is already an element
|
|
38
38
|
},
|
|
39
39
|
$$: function $$(ref) {
|
|
@@ -41,17 +41,14 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
41
41
|
// ref is an array of elements
|
|
42
42
|
return ref;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
44
|
if (ref.nodeType === Node.ELEMENT_NODE) {
|
|
46
45
|
// ref is an element
|
|
47
46
|
return [ref];
|
|
48
47
|
}
|
|
49
|
-
|
|
50
48
|
if (typeof ref === "string") {
|
|
51
49
|
// ref is a selector
|
|
52
50
|
return slice.call(dom.body.querySelectorAll(ref));
|
|
53
51
|
}
|
|
54
|
-
|
|
55
52
|
return slice.call(ref); // ref is an array-like object (NodeList or HTMLCollection)
|
|
56
53
|
}
|
|
57
54
|
};
|
|
@@ -62,18 +59,15 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
62
59
|
var scrollBodies = dom.$$(".handy-scroll-body").filter(function (node) {
|
|
63
60
|
return node.contains(container);
|
|
64
61
|
});
|
|
65
|
-
|
|
66
62
|
if (scrollBodies.length) {
|
|
67
63
|
instance.scrollBody = scrollBodies[0];
|
|
68
64
|
}
|
|
69
|
-
|
|
70
65
|
instance.container = container;
|
|
71
66
|
instance.visible = true;
|
|
72
67
|
instance.initWidget();
|
|
73
68
|
instance.update(); // recalculate scrollbar parameters and set its visibility
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
instance.addEventHandlers();
|
|
70
|
+
// Set skipSync flags to their initial values (because update() above calls syncWidget())
|
|
77
71
|
instance.skipSyncContainer = instance.skipSyncWidget = false;
|
|
78
72
|
},
|
|
79
73
|
initWidget: function initWidget() {
|
|
@@ -103,10 +97,9 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
103
97
|
scroll: function scroll() {
|
|
104
98
|
if (instance.visible && !instance.skipSyncContainer) {
|
|
105
99
|
instance.syncContainer();
|
|
106
|
-
}
|
|
100
|
+
}
|
|
101
|
+
// Resume widget->container syncing after the widget scrolling has finished
|
|
107
102
|
// (it might be temporally disabled by the container while syncing the widget)
|
|
108
|
-
|
|
109
|
-
|
|
110
103
|
instance.skipSyncContainer = false;
|
|
111
104
|
}
|
|
112
105
|
}
|
|
@@ -116,10 +109,9 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
116
109
|
scroll: function scroll() {
|
|
117
110
|
if (!instance.skipSyncWidget) {
|
|
118
111
|
instance.syncWidget();
|
|
119
|
-
}
|
|
112
|
+
}
|
|
113
|
+
// Resume container->widget syncing after the container scrolling has finished
|
|
120
114
|
// (it might be temporally disabled by the widget while syncing the container)
|
|
121
|
-
|
|
122
|
-
|
|
123
115
|
instance.skipSyncWidget = false;
|
|
124
116
|
},
|
|
125
117
|
focusin: function focusin() {
|
|
@@ -134,7 +126,7 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
134
126
|
}];
|
|
135
127
|
eventHandlers.forEach(function (_ref) {
|
|
136
128
|
var el = _ref.el,
|
|
137
|
-
|
|
129
|
+
handlers = _ref.handlers;
|
|
138
130
|
Object.keys(handlers).forEach(function (event) {
|
|
139
131
|
return el.addEventListener(event, handlers[event], false);
|
|
140
132
|
});
|
|
@@ -143,41 +135,37 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
143
135
|
checkVisibility: function checkVisibility() {
|
|
144
136
|
var instance = this;
|
|
145
137
|
var widget = instance.widget,
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
container = instance.container,
|
|
139
|
+
scrollBody = instance.scrollBody;
|
|
148
140
|
var mustHide = widget.scrollWidth <= widget.offsetWidth;
|
|
149
|
-
|
|
150
141
|
if (!mustHide) {
|
|
151
142
|
var containerRect = container.getBoundingClientRect();
|
|
152
143
|
var maxVisibleY = scrollBody ? scrollBody.getBoundingClientRect().bottom : window.innerHeight || dom.html.clientHeight;
|
|
153
144
|
mustHide = containerRect.bottom <= maxVisibleY || containerRect.top > maxVisibleY;
|
|
154
145
|
}
|
|
155
|
-
|
|
156
146
|
if (instance.visible === mustHide) {
|
|
157
|
-
instance.visible = !mustHide;
|
|
158
|
-
|
|
147
|
+
instance.visible = !mustHide;
|
|
148
|
+
// We cannot simply hide the scrollbar since its scrollLeft property will not update in that case
|
|
159
149
|
widget.classList.toggle("handy-scroll-hidden");
|
|
160
150
|
}
|
|
161
151
|
},
|
|
162
152
|
syncContainer: function syncContainer() {
|
|
163
153
|
var instance = this;
|
|
164
154
|
var scrollLeft = instance.widget.scrollLeft;
|
|
165
|
-
|
|
166
155
|
if (instance.container.scrollLeft !== scrollLeft) {
|
|
167
156
|
// Prevents container’s “scroll” event handler from syncing back again widget scroll position
|
|
168
|
-
instance.skipSyncWidget = true;
|
|
169
|
-
|
|
157
|
+
instance.skipSyncWidget = true;
|
|
158
|
+
// Note that this makes container’s “scroll” event handlers execute
|
|
170
159
|
instance.container.scrollLeft = scrollLeft;
|
|
171
160
|
}
|
|
172
161
|
},
|
|
173
162
|
syncWidget: function syncWidget() {
|
|
174
163
|
var instance = this;
|
|
175
164
|
var scrollLeft = instance.container.scrollLeft;
|
|
176
|
-
|
|
177
165
|
if (instance.widget.scrollLeft !== scrollLeft) {
|
|
178
166
|
// Prevents widget’s “scroll” event handler from syncing back again container scroll position
|
|
179
|
-
instance.skipSyncContainer = true;
|
|
180
|
-
|
|
167
|
+
instance.skipSyncContainer = true;
|
|
168
|
+
// Note that this makes widget’s “scroll” event handlers execute
|
|
181
169
|
instance.widget.scrollLeft = scrollLeft;
|
|
182
170
|
}
|
|
183
171
|
},
|
|
@@ -185,18 +173,16 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
185
173
|
update: function update() {
|
|
186
174
|
var instance = this;
|
|
187
175
|
var widget = instance.widget,
|
|
188
|
-
|
|
189
|
-
|
|
176
|
+
container = instance.container,
|
|
177
|
+
scrollBody = instance.scrollBody;
|
|
190
178
|
var clientWidth = container.clientWidth,
|
|
191
|
-
|
|
179
|
+
scrollWidth = container.scrollWidth;
|
|
192
180
|
widget.style.width = clientWidth + "px";
|
|
193
|
-
|
|
194
181
|
if (!scrollBody) {
|
|
195
182
|
widget.style.left = container.getBoundingClientRect().left + "px";
|
|
196
183
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
184
|
+
widget.firstElementChild.style.width = scrollWidth + "px";
|
|
185
|
+
// Fit widget height to the native scroll bar height if needed
|
|
200
186
|
if (scrollWidth > clientWidth) {
|
|
201
187
|
widget.style.height = widget.offsetHeight - widget.clientHeight + 1 + "px"; // +1px JIC
|
|
202
188
|
}
|
|
@@ -209,7 +195,7 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
209
195
|
var instance = this;
|
|
210
196
|
instance.eventHandlers.forEach(function (_ref2) {
|
|
211
197
|
var el = _ref2.el,
|
|
212
|
-
|
|
198
|
+
handlers = _ref2.handlers;
|
|
213
199
|
Object.keys(handlers).forEach(function (event) {
|
|
214
200
|
return el.removeEventListener(event, handlers[event], false);
|
|
215
201
|
});
|
|
@@ -224,20 +210,18 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
224
210
|
var handyScroll = {
|
|
225
211
|
/**
|
|
226
212
|
* Mount widgets in the given containers
|
|
227
|
-
* @param {HTMLElement|NodeList|HTMLCollection|
|
|
213
|
+
* @param {HTMLElement|NodeList|HTMLCollection|HTMLElement[]|String} containerRef - Widget container reference (either an element, or a list of elements, or a selector)
|
|
228
214
|
*/
|
|
229
215
|
mount: function mount(containerRef) {
|
|
230
216
|
dom.$$(containerRef).forEach(function (container) {
|
|
231
217
|
if (handyScroll.mounted(container)) {
|
|
232
218
|
return;
|
|
233
219
|
}
|
|
234
|
-
|
|
235
220
|
var instance = Object.create(handyScrollProto);
|
|
236
221
|
instances.push(instance);
|
|
237
222
|
instance.init(container);
|
|
238
223
|
});
|
|
239
224
|
},
|
|
240
|
-
|
|
241
225
|
/**
|
|
242
226
|
* Check if a widget is already mounted in the given container
|
|
243
227
|
* @param {HTMLElement|String} containerRef - Widget container reference (either an element, or a selector)
|
|
@@ -249,10 +233,9 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
249
233
|
return instance.container === container;
|
|
250
234
|
});
|
|
251
235
|
},
|
|
252
|
-
|
|
253
236
|
/**
|
|
254
237
|
* Update widget parameters and position
|
|
255
|
-
* @param {HTMLElement|NodeList|HTMLCollection|
|
|
238
|
+
* @param {HTMLElement|NodeList|HTMLCollection|HTMLElement[]|String} containerRef - Widget container reference (either an element, or a list of elements, or a selector)
|
|
256
239
|
*/
|
|
257
240
|
update: function update(containerRef) {
|
|
258
241
|
dom.$$(containerRef).forEach(function (container) {
|
|
@@ -261,15 +244,13 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
261
244
|
instance.update();
|
|
262
245
|
return true;
|
|
263
246
|
}
|
|
264
|
-
|
|
265
247
|
return false;
|
|
266
248
|
});
|
|
267
249
|
});
|
|
268
250
|
},
|
|
269
|
-
|
|
270
251
|
/**
|
|
271
252
|
* Destroy widgets mounted in the given containers
|
|
272
|
-
* @param {HTMLElement|NodeList|HTMLCollection|
|
|
253
|
+
* @param {HTMLElement|NodeList|HTMLCollection|HTMLElement[]|String} containerRef - Widget container reference (either an element, or a list of elements, or a selector)
|
|
273
254
|
*/
|
|
274
255
|
destroy: function destroy(containerRef) {
|
|
275
256
|
dom.$$(containerRef).forEach(function (container) {
|
|
@@ -278,12 +259,10 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
278
259
|
instances.splice(index, 1)[0].destroy();
|
|
279
260
|
return true;
|
|
280
261
|
}
|
|
281
|
-
|
|
282
262
|
return false;
|
|
283
263
|
});
|
|
284
264
|
});
|
|
285
265
|
},
|
|
286
|
-
|
|
287
266
|
/**
|
|
288
267
|
* Destroy handyScroll widgets whose containers are not in the document anymore
|
|
289
268
|
*/
|
|
@@ -293,12 +272,10 @@ https://amphiluke.github.io/handy-scroll/
|
|
|
293
272
|
instance.destroy();
|
|
294
273
|
return false;
|
|
295
274
|
}
|
|
296
|
-
|
|
297
275
|
return true;
|
|
298
276
|
});
|
|
299
277
|
}
|
|
300
278
|
};
|
|
301
|
-
|
|
302
279
|
if (dom.isDOMAvailable) {
|
|
303
280
|
dom.ready(function () {
|
|
304
281
|
handyScroll.mount("[data-handy-scroll]");
|
package/dist/handy-scroll.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
handy-scroll v1.1.
|
|
2
|
+
handy-scroll v1.1.2
|
|
3
3
|
https://amphiluke.github.io/handy-scroll/
|
|
4
|
-
(c)
|
|
4
|
+
(c) 2023 Amphiluke
|
|
5
5
|
*/
|
|
6
6
|
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).handyScroll=n()}(this,(function(){"use strict";var t=Array.prototype.slice,n="object"==typeof document&&!!document.documentElement,e={isDOMAvailable:n,doc:n?document:null,html:n?document.documentElement:null,body:n?document.body:null,ready:function(t){"loading"===e.doc.readyState?e.doc.addEventListener("DOMContentLoaded",(function(){t()}),{once:!0}):t()},$:function(t){return"string"==typeof t?e.body.querySelector(t):t},$$:function(n){return Array.isArray(n)?n:n.nodeType===Node.ELEMENT_NODE?[n]:"string"==typeof n?t.call(e.body.querySelectorAll(n)):t.call(n)}},i={init:function(t){var n=this,i=e.$$(".handy-scroll-body").filter((function(n){return n.contains(t)}));i.length&&(n.scrollBody=i[0]),n.container=t,n.visible=!0,n.initWidget(),n.update(),n.addEventHandlers(),n.skipSyncContainer=n.skipSyncWidget=!1},initWidget:function(){var t=this,n=t.widget=e.doc.createElement("div");n.classList.add("handy-scroll");var i=e.doc.createElement("div");i.style.width=t.container.scrollWidth+"px",n.appendChild(i),t.container.appendChild(n)},addEventHandlers:function(){var t=this;(t.eventHandlers=[{el:t.scrollBody||window,handlers:{scroll:function(){t.checkVisibility()},resize:function(){t.update()}}},{el:t.widget,handlers:{scroll:function(){t.visible&&!t.skipSyncContainer&&t.syncContainer(),t.skipSyncContainer=!1}}},{el:t.container,handlers:{scroll:function(){t.skipSyncWidget||t.syncWidget(),t.skipSyncWidget=!1},focusin:function(){setTimeout((function(){t.widget&&t.syncWidget()}),0)}}}]).forEach((function(t){var n=t.el,e=t.handlers;Object.keys(e).forEach((function(t){return n.addEventListener(t,e[t],!1)}))}))},checkVisibility:function(){var t=this,n=t.widget,i=t.container,o=t.scrollBody,c=n.scrollWidth<=n.offsetWidth;if(!c){var r=i.getBoundingClientRect(),l=o?o.getBoundingClientRect().bottom:window.innerHeight||e.html.clientHeight;c=r.bottom<=l||r.top>l}t.visible===c&&(t.visible=!c,n.classList.toggle("handy-scroll-hidden"))},syncContainer:function(){var t=this,n=t.widget.scrollLeft;t.container.scrollLeft!==n&&(t.skipSyncWidget=!0,t.container.scrollLeft=n)},syncWidget:function(){var t=this,n=t.container.scrollLeft;t.widget.scrollLeft!==n&&(t.skipSyncContainer=!0,t.widget.scrollLeft=n)},update:function(){var t=this,n=t.widget,e=t.container,i=t.scrollBody,o=e.clientWidth,c=e.scrollWidth;n.style.width=o+"px",i||(n.style.left=e.getBoundingClientRect().left+"px"),n.firstElementChild.style.width=c+"px",c>o&&(n.style.height=n.offsetHeight-n.clientHeight+1+"px"),t.syncWidget(),t.checkVisibility()},destroy:function(){var t=this;t.eventHandlers.forEach((function(t){var n=t.el,e=t.handlers;Object.keys(e).forEach((function(t){return n.removeEventListener(t,e[t],!1)}))})),t.widget.parentNode.removeChild(t.widget),t.eventHandlers=t.widget=t.container=t.scrollBody=null}},o=[],c={mount:function(t){e.$$(t).forEach((function(t){if(!c.mounted(t)){var n=Object.create(i);o.push(n),n.init(t)}}))},mounted:function(t){var n=e.$(t);return o.some((function(t){return t.container===n}))},update:function(t){e.$$(t).forEach((function(t){o.some((function(n){return n.container===t&&(n.update(),!0)}))}))},destroy:function(t){e.$$(t).forEach((function(t){o.some((function(n,e){return n.container===t&&(o.splice(e,1)[0].destroy(),!0)}))}))},destroyDetached:function(){o=o.filter((function(t){return!!e.body.contains(t.container)||(t.destroy(),!1)}))}};return e.isDOMAvailable&&e.ready((function(){c.mount("[data-handy-scroll]")})),c}));
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "handy-scroll",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Handy dependency-free floating scrollbar widget",
|
|
5
|
-
"main": "dist/handy-scroll.min.js",
|
|
6
|
-
"module": "src/handy-scroll.js",
|
|
7
|
-
"style": "dist/handy-scroll.css",
|
|
5
|
+
"main": "./dist/handy-scroll.min.js",
|
|
6
|
+
"module": "./src/handy-scroll.js",
|
|
7
|
+
"style": "./dist/handy-scroll.css",
|
|
8
|
+
"types": "./dist/handy-scroll.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/handy-scroll.d.ts",
|
|
12
|
+
"import": "./src/handy-scroll.js",
|
|
13
|
+
"require": "./dist/handy-scroll.js"
|
|
14
|
+
},
|
|
15
|
+
"./dist/*.css": "./dist/*.css"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
8
18
|
"files": [
|
|
9
19
|
"dist",
|
|
10
20
|
"src"
|
|
@@ -31,14 +41,14 @@
|
|
|
31
41
|
},
|
|
32
42
|
"homepage": "https://amphiluke.github.io/handy-scroll/",
|
|
33
43
|
"devDependencies": {
|
|
34
|
-
"@babel/core": "^7.
|
|
35
|
-
"@babel/preset-env": "^7.
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"rollup
|
|
44
|
+
"@babel/core": "^7.22.5",
|
|
45
|
+
"@babel/preset-env": "^7.22.5",
|
|
46
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
47
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
48
|
+
"clean-css-cli": "^5.6.2",
|
|
49
|
+
"eslint": "^8.43.0",
|
|
50
|
+
"husky": "8.0.3",
|
|
51
|
+
"less": "^4.1.3",
|
|
52
|
+
"rollup": "^3.25.2"
|
|
43
53
|
}
|
|
44
54
|
}
|
package/src/handy-scroll.js
CHANGED
|
@@ -6,7 +6,7 @@ let instances = []; // if it were not for IE, it would be better to use Map (con
|
|
|
6
6
|
let handyScroll = {
|
|
7
7
|
/**
|
|
8
8
|
* Mount widgets in the given containers
|
|
9
|
-
* @param {HTMLElement|NodeList|HTMLCollection|
|
|
9
|
+
* @param {HTMLElement|NodeList|HTMLCollection|HTMLElement[]|String} containerRef - Widget container reference (either an element, or a list of elements, or a selector)
|
|
10
10
|
*/
|
|
11
11
|
mount(containerRef) {
|
|
12
12
|
dom.$$(containerRef).forEach(container => {
|
|
@@ -31,7 +31,7 @@ let handyScroll = {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Update widget parameters and position
|
|
34
|
-
* @param {HTMLElement|NodeList|HTMLCollection|
|
|
34
|
+
* @param {HTMLElement|NodeList|HTMLCollection|HTMLElement[]|String} containerRef - Widget container reference (either an element, or a list of elements, or a selector)
|
|
35
35
|
*/
|
|
36
36
|
update(containerRef) {
|
|
37
37
|
dom.$$(containerRef).forEach(container => {
|
|
@@ -47,7 +47,7 @@ let handyScroll = {
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Destroy widgets mounted in the given containers
|
|
50
|
-
* @param {HTMLElement|NodeList|HTMLCollection|
|
|
50
|
+
* @param {HTMLElement|NodeList|HTMLCollection|HTMLElement[]|String} containerRef - Widget container reference (either an element, or a list of elements, or a selector)
|
|
51
51
|
*/
|
|
52
52
|
destroy(containerRef) {
|
|
53
53
|
dom.$$(containerRef).forEach(container => {
|