@creative-web-solution/front-library 6.2.14 → 6.2.15
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/CHANGELOG.md +5 -0
- package/Modules/DragSlider.js +70 -55
- package/README.md +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/Modules/DragSlider.js
CHANGED
|
@@ -5,9 +5,49 @@ import { gesture, gestureOff } from '@creative-web-solution/front-library/Eve
|
|
|
5
5
|
import { prop } from '@creative-web-solution/front-library/DOM/Styles';
|
|
6
6
|
import { aClass, rClass, tClass } from '@creative-web-solution/front-library/DOM/Class';
|
|
7
7
|
import { on, off } from '@creative-web-solution/front-library/Events/EventsManager';
|
|
8
|
+
import { extend } from '@creative-web-solution/front-library/Helpers/extend';
|
|
8
9
|
|
|
9
10
|
const IS_TOUCH_DEVICE = !window.matchMedia('(hover:hover)').matches;
|
|
10
11
|
|
|
12
|
+
const defaultOptions = {
|
|
13
|
+
swipeTresholdMin: 40,
|
|
14
|
+
swipeTresholdSize: 0.5,
|
|
15
|
+
lockedClass: 'is-locked',
|
|
16
|
+
_animReset: function($list) {
|
|
17
|
+
gsap.set( $list, {
|
|
18
|
+
"x": 0,
|
|
19
|
+
"y": 0,
|
|
20
|
+
"z": 0
|
|
21
|
+
} );
|
|
22
|
+
},
|
|
23
|
+
_animClear: function($list) {
|
|
24
|
+
gsap.set( $list, {
|
|
25
|
+
"clearProps": "all"
|
|
26
|
+
} );
|
|
27
|
+
},
|
|
28
|
+
_animKill: function($list) {
|
|
29
|
+
gsap.killTweensOf( $list );
|
|
30
|
+
},
|
|
31
|
+
_animMoveItem: function($list, x, onUpdate) {
|
|
32
|
+
gsap.to( $list, {
|
|
33
|
+
"duration": 0.3,
|
|
34
|
+
"x": x,
|
|
35
|
+
"y": 0,
|
|
36
|
+
"z": 0,
|
|
37
|
+
"onUpdate": function() {
|
|
38
|
+
onUpdate(gsap.getProperty( this.targets()[ 0 ], 'x' ));
|
|
39
|
+
}
|
|
40
|
+
} );
|
|
41
|
+
},
|
|
42
|
+
_setCoordinates: function($list, x) {
|
|
43
|
+
gsap.set( $list, {
|
|
44
|
+
"x": x,
|
|
45
|
+
"y": 0,
|
|
46
|
+
"z": 0
|
|
47
|
+
} );
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
11
51
|
/**
|
|
12
52
|
* DragSlider
|
|
13
53
|
* @class
|
|
@@ -31,7 +71,7 @@ const IS_TOUCH_DEVICE = !window.matchMedia('(hover:hover)').matches;
|
|
|
31
71
|
* @param {Number} [options.swipeTresholdMin=40] - in px
|
|
32
72
|
* @param {Number} [options.swipeTresholdSize=0.5] - in % (0.5 = 50% of the size of one item)
|
|
33
73
|
*/
|
|
34
|
-
export function DragSlider( $slider,
|
|
74
|
+
export function DragSlider( $slider, userOptions ) {
|
|
35
75
|
let itemMap, itemArray, listDelta, viewportInfo,
|
|
36
76
|
$items, $list, $viewport, startDragCoords, deltaMove,
|
|
37
77
|
currentSnapItem, firstItem,
|
|
@@ -45,9 +85,7 @@ export function DragSlider( $slider, options ) {
|
|
|
45
85
|
|
|
46
86
|
isDraggingActive = false;
|
|
47
87
|
|
|
48
|
-
options
|
|
49
|
-
options.swipeTresholdSize = options.swipeTresholdSize || 0.5;
|
|
50
|
-
options.lockedClass = options.lockedClass || 'is-locked';
|
|
88
|
+
const options = extend( defaultOptions, userOptions );
|
|
51
89
|
|
|
52
90
|
itemArray = [];
|
|
53
91
|
|
|
@@ -79,12 +117,9 @@ export function DragSlider( $slider, options ) {
|
|
|
79
117
|
|
|
80
118
|
if ( !isDraggingActive ) {
|
|
81
119
|
isDragging = false;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
"y": 0,
|
|
86
|
-
"z": 0
|
|
87
|
-
} );
|
|
120
|
+
|
|
121
|
+
options._animKill( $list );
|
|
122
|
+
options._animReset( $list );
|
|
88
123
|
}
|
|
89
124
|
|
|
90
125
|
tClass( $slider, options.lockedClass, !isDraggingActive );
|
|
@@ -148,22 +183,16 @@ export function DragSlider( $slider, options ) {
|
|
|
148
183
|
"isAtEnd": IS_SNAP_TO_END
|
|
149
184
|
} );
|
|
150
185
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
"xPos": deltaMove.x,
|
|
162
|
-
"moveMaxSize": listDelta,
|
|
163
|
-
"isAtStart": IS_SNAP_TO_START,
|
|
164
|
-
"isAtEnd": IS_SNAP_TO_END
|
|
165
|
-
} );
|
|
166
|
-
}
|
|
186
|
+
options._animMoveItem( $list, finalX, (newX) => {
|
|
187
|
+
deltaMove.x = newX;
|
|
188
|
+
|
|
189
|
+
options.onSnapUpdate?.( {
|
|
190
|
+
"item": snapItem,
|
|
191
|
+
"xPos": deltaMove.x,
|
|
192
|
+
"moveMaxSize": listDelta,
|
|
193
|
+
"isAtStart": IS_SNAP_TO_START,
|
|
194
|
+
"isAtEnd": IS_SNAP_TO_END
|
|
195
|
+
} );
|
|
167
196
|
} );
|
|
168
197
|
|
|
169
198
|
currentSnapItem = snapItem;
|
|
@@ -294,7 +323,7 @@ export function DragSlider( $slider, options ) {
|
|
|
294
323
|
|
|
295
324
|
isDragging = true;
|
|
296
325
|
|
|
297
|
-
|
|
326
|
+
options._animKill( $list );
|
|
298
327
|
|
|
299
328
|
startDragCoords = coords;
|
|
300
329
|
listDelta = viewportInfo.width - $list.scrollWidth;
|
|
@@ -337,11 +366,7 @@ export function DragSlider( $slider, options ) {
|
|
|
337
366
|
deltaMove.newX = listDelta;
|
|
338
367
|
}
|
|
339
368
|
|
|
340
|
-
|
|
341
|
-
"x": deltaMove.newX,
|
|
342
|
-
"y": 0,
|
|
343
|
-
"z": 0
|
|
344
|
-
} );
|
|
369
|
+
options._setCoordinates($list, deltaMove.newX);
|
|
345
370
|
|
|
346
371
|
options.onDrag?.( {
|
|
347
372
|
"item": currentSnapItem,
|
|
@@ -450,23 +475,17 @@ export function DragSlider( $slider, options ) {
|
|
|
450
475
|
"isAtEnd": deltaMove.x === listDelta
|
|
451
476
|
} );
|
|
452
477
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
"moveMaxSize": listDelta,
|
|
465
|
-
"isAtStart": deltaMove.x === 0,
|
|
466
|
-
"isAtEnd": deltaMove.x === listDelta
|
|
467
|
-
} );
|
|
468
|
-
}
|
|
469
|
-
} );
|
|
478
|
+
options._animMoveItem($list, -1 * ITEM.info.left + siteOffset, (x) => {
|
|
479
|
+
deltaMove.x = x;
|
|
480
|
+
|
|
481
|
+
options.onSnapUpdate?.( {
|
|
482
|
+
"item": ITEM,
|
|
483
|
+
"xPos": deltaMove.x,
|
|
484
|
+
"moveMaxSize": listDelta,
|
|
485
|
+
"isAtStart": deltaMove.x === 0,
|
|
486
|
+
"isAtEnd": deltaMove.x === listDelta
|
|
487
|
+
} );
|
|
488
|
+
})
|
|
470
489
|
};
|
|
471
490
|
|
|
472
491
|
|
|
@@ -567,12 +586,8 @@ export function DragSlider( $slider, options ) {
|
|
|
567
586
|
"callback": onMouseleave
|
|
568
587
|
} );
|
|
569
588
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
gsap.set( $list, {
|
|
574
|
-
"clearProps": "all"
|
|
575
|
-
} );
|
|
589
|
+
options._animKill( $list );
|
|
590
|
+
options._animClear( $list );
|
|
576
591
|
|
|
577
592
|
rClass( $viewport, options.dragClass );
|
|
578
593
|
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@creative-web-solution/front-library",
|
|
3
3
|
"title": "Frontend library",
|
|
4
4
|
"description": "Frontend functions and modules",
|
|
5
|
-
"version": "6.2.
|
|
5
|
+
"version": "6.2.15",
|
|
6
6
|
"homepage": "https://github.com/creative-web-solution/front-library",
|
|
7
7
|
"author": "Creative Web Solution <contact@cws-studio.com> (https://www.cws-studio.com)",
|
|
8
8
|
"keywords": [],
|