@creative-web-solution/front-library 6.2.6 → 6.2.7
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 +4 -0
- package/Events/EventsManager.js +39 -81
- package/Events/IntersectObserver.js +1 -0
- package/Modules/Slider.js +2 -2
- package/README.md +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/Events/EventsManager.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import { slice } from '
|
|
1
|
+
import { slice } from '../Helpers/Slice';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
let passiveSupported = false,
|
|
5
|
+
createEvt,
|
|
6
|
+
DOMRegistry = [],
|
|
7
|
+
ObjectRegistry = [];
|
|
2
8
|
|
|
3
|
-
let passiveSupported = false, DOMRegistry = [], ObjectRegistry = [], createEvt;
|
|
4
9
|
|
|
5
10
|
(function () {
|
|
6
|
-
if ( typeof window.CustomEvent ===
|
|
7
|
-
return
|
|
11
|
+
if ( typeof window.CustomEvent === 'function' ) {
|
|
12
|
+
return;
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
function CustomEvent ( event, params ) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
params = params || { bubbles: false, cancelable: false, detail: undefined };
|
|
17
|
+
const evt = document.createEvent( 'CustomEvent' );
|
|
18
|
+
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
|
|
19
|
+
return evt;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
CustomEvent.prototype = window.Event.prototype;
|
|
@@ -43,18 +48,20 @@ let passiveSupported = false, DOMRegistry = [], ObjectRegistry = [], createEvt;
|
|
|
43
48
|
}
|
|
44
49
|
}() );
|
|
45
50
|
|
|
51
|
+
function passiveTestFnc() {return;}
|
|
46
52
|
|
|
47
53
|
(function () {
|
|
48
54
|
try {
|
|
49
|
-
|
|
55
|
+
const options = Object.defineProperty( {}, 'passive', {
|
|
50
56
|
"get": () => {
|
|
51
57
|
passiveSupported = true;
|
|
52
58
|
return true;
|
|
53
59
|
}
|
|
54
60
|
} );
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
window.
|
|
62
|
+
|
|
63
|
+
window.addEventListener( 'test', passiveTestFnc, options );
|
|
64
|
+
window.removeEventListener( 'test', passiveTestFnc, options );
|
|
58
65
|
}
|
|
59
66
|
catch( err ) {
|
|
60
67
|
passiveSupported = false;
|
|
@@ -64,13 +71,13 @@ let passiveSupported = false, DOMRegistry = [], ObjectRegistry = [], createEvt;
|
|
|
64
71
|
|
|
65
72
|
function getDelegation( $element, selector, callback ) {
|
|
66
73
|
return e => {
|
|
67
|
-
|
|
74
|
+
const $target = e.target.closest( selector );
|
|
68
75
|
|
|
69
76
|
if ( !$target || !$element.contains( $target ) ) {
|
|
70
77
|
return;
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
callback.call( $target, e );
|
|
80
|
+
callback.call( $target, e, $target );
|
|
74
81
|
};
|
|
75
82
|
}
|
|
76
83
|
|
|
@@ -101,36 +108,20 @@ function _useNativeDOMEvents( $element ) {
|
|
|
101
108
|
|
|
102
109
|
/**
|
|
103
110
|
* Indicate if the browser natively support passive event
|
|
104
|
-
*
|
|
105
|
-
* @name handlePassiveEvents
|
|
106
|
-
* @type {Boolean}
|
|
107
111
|
*/
|
|
108
112
|
export const handlePassiveEvents = passiveSupported;
|
|
109
113
|
|
|
110
114
|
|
|
111
115
|
/**
|
|
112
116
|
* Add an event listener
|
|
113
|
-
*
|
|
114
|
-
* @function on
|
|
115
|
-
*
|
|
116
|
-
* @param { HTMLElement|Object|HTMLElement[]|Object[] } $elements
|
|
117
|
-
* @param { Object } options
|
|
118
|
-
* @param { String } options.eventsName - Name of events separate by a space
|
|
119
|
-
* @param { Function } options.callback - Callback function
|
|
120
|
-
* @param { String } [options.selector] - Css selector used for event delegation
|
|
121
|
-
* @param { Boolean } [options.capture] - Active or not capture event.
|
|
122
|
-
* @param { Object } [options.eventOptions] - Native addEventListener options. Priority to options.capture if it's present.
|
|
123
|
-
* @param { Boolean } [options.eventOptions.capure]
|
|
124
|
-
* @param { Boolean } [options.eventOptions.once]
|
|
125
|
-
* @param { Boolean } [options.eventOptions.passive]
|
|
126
117
|
*/
|
|
127
118
|
export const on = function( $elements, options ) {
|
|
128
119
|
let eventOptions;
|
|
129
120
|
|
|
130
|
-
$
|
|
121
|
+
const $ELEM_ARRAY = normalizeElements( $elements );
|
|
131
122
|
|
|
132
123
|
if ( !options.eventsName ) {
|
|
133
|
-
throw '[EVENT MANAGER]: Missing event
|
|
124
|
+
throw '[EVENT MANAGER]: Missing event name';
|
|
134
125
|
}
|
|
135
126
|
|
|
136
127
|
if ( !options.callback ) {
|
|
@@ -145,15 +136,15 @@ export const on = function( $elements, options ) {
|
|
|
145
136
|
}
|
|
146
137
|
|
|
147
138
|
options.eventsName.split( ' ' ).forEach( eventName => {
|
|
148
|
-
$
|
|
139
|
+
$ELEM_ARRAY.forEach( $element => {
|
|
149
140
|
if ( exists( $element, eventName, options ) ) {
|
|
150
141
|
return;
|
|
151
142
|
}
|
|
152
143
|
|
|
153
|
-
|
|
154
|
-
|
|
144
|
+
const useNativeDOMEvents = _useNativeDOMEvents( $element );
|
|
145
|
+
const cbFunction = options._internalCallback || options.callback;
|
|
155
146
|
|
|
156
|
-
|
|
147
|
+
const data = {
|
|
157
148
|
$element,
|
|
158
149
|
eventName,
|
|
159
150
|
options
|
|
@@ -180,20 +171,6 @@ export const on = function( $elements, options ) {
|
|
|
180
171
|
|
|
181
172
|
/**
|
|
182
173
|
* Add an event listener fired only one time
|
|
183
|
-
*
|
|
184
|
-
* @function one
|
|
185
|
-
*
|
|
186
|
-
* @param { HTMLElement|Object|HTMLElement[]|Object[] } $elements
|
|
187
|
-
* @param { Object } options
|
|
188
|
-
* @param { String } options.eventsName - Name of events separate by a space
|
|
189
|
-
* @param { String } [options.selector] - Css selector used for event delegation
|
|
190
|
-
* @param { Functio } options.callback - Callback function
|
|
191
|
-
* @param { Boolean } [options.capture] - Active or not capture event.
|
|
192
|
-
* @param { Object } [options.eventOptions] - Native addEventListener options. Priority to options.capture if it's present.
|
|
193
|
-
* @param { Boolean } [options.eventOptions.capure]
|
|
194
|
-
* @param { Boolean } [options.eventOptions.once]
|
|
195
|
-
* @param { Boolean } [options.eventOptions.passive]
|
|
196
|
-
*
|
|
197
174
|
*/
|
|
198
175
|
export const one = function( $elements, options ) {
|
|
199
176
|
|
|
@@ -211,26 +188,19 @@ export const one = function( $elements, options ) {
|
|
|
211
188
|
|
|
212
189
|
/**
|
|
213
190
|
* Remove an event
|
|
214
|
-
*
|
|
215
|
-
* @function off
|
|
216
|
-
*
|
|
217
|
-
* @param { HTMLElement|Object|HTMLElement[]|Object[] } $elements
|
|
218
|
-
* @param { Object } options
|
|
219
|
-
* @param { String } options.eventsName - Name of events separate by space
|
|
220
|
-
* @param { Function } [options.callback] - Callback function
|
|
221
|
-
*
|
|
222
191
|
*/
|
|
223
|
-
export const off = function( $elements, options
|
|
224
|
-
|
|
192
|
+
export const off = function( $elements, options) {
|
|
193
|
+
|
|
194
|
+
const $ELEM_ARRAY = normalizeElements( $elements );
|
|
225
195
|
|
|
226
196
|
options.eventsName.split( ' ' ).forEach( eventName => {
|
|
227
|
-
$
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
let
|
|
197
|
+
$ELEM_ARRAY.forEach( $element => {
|
|
198
|
+
const useNativeDOMEvents = _useNativeDOMEvents( $element );
|
|
199
|
+
const removedItem = [];
|
|
200
|
+
let registry = useNativeDOMEvents ? DOMRegistry : ObjectRegistry;
|
|
231
201
|
|
|
232
202
|
registry.forEach( item => {
|
|
233
|
-
|
|
203
|
+
const callback = item.delegate || item.options._internalCallback || item.options.callback;
|
|
234
204
|
|
|
235
205
|
if ( !options.callback || options.callback === item.options.callback ) {
|
|
236
206
|
if ( useNativeDOMEvents ) {
|
|
@@ -257,33 +227,21 @@ export const off = function( $elements, options ) {
|
|
|
257
227
|
|
|
258
228
|
/**
|
|
259
229
|
* Fire an event
|
|
260
|
-
*
|
|
261
|
-
* @function fire
|
|
262
|
-
*
|
|
263
|
-
* @param { HTMLElement|Object|HTMLElement[]|Object[] } $elements
|
|
264
|
-
* @param { Object } options
|
|
265
|
-
* @param { String } options.eventsName - Name of events separate by space
|
|
266
|
-
* @param { Object } [options.detail] - Object to send with the event
|
|
267
|
-
* @param { Boolean } [options.bubbles=true] - Only used for DOMM
|
|
268
|
-
* @param { Boolean } [options.cancelable=true] - Only used for DOMM
|
|
269
|
-
*
|
|
270
230
|
*/
|
|
271
231
|
export const fire = function( $elements, options ) {
|
|
272
|
-
$
|
|
232
|
+
const $ELEM_ARRAY = normalizeElements( $elements );
|
|
273
233
|
|
|
274
234
|
options.eventsName.split(' ').forEach( eventName => {
|
|
275
|
-
$
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if ( useNativeDOMEvents ) {
|
|
235
|
+
$ELEM_ARRAY.forEach( $element => {
|
|
236
|
+
if ( _useNativeDOMEvents( $element ) ) {
|
|
279
237
|
$element.dispatchEvent( createEvt( eventName, options ) );
|
|
280
238
|
return;
|
|
281
239
|
}
|
|
282
240
|
|
|
283
|
-
|
|
241
|
+
const eventData = ObjectRegistry.filter( reg => reg.$element === $element && reg.eventName === eventName );
|
|
284
242
|
|
|
285
243
|
eventData.forEach( reg => {
|
|
286
|
-
reg.options[ reg.options._internalCallback ? '_internalCallback' : 'callback' ]
|
|
244
|
+
reg.options[ reg.options._internalCallback ? '_internalCallback' : 'callback' ]?.call( reg.$element, options.detail );
|
|
287
245
|
} );
|
|
288
246
|
} );
|
|
289
247
|
} );
|
package/Modules/Slider.js
CHANGED
|
@@ -1607,14 +1607,14 @@ export function SliderControls( slider, options ) {
|
|
|
1607
1607
|
"selector": options.paginationItems,
|
|
1608
1608
|
"onPrevious": () => {
|
|
1609
1609
|
one( slider, {
|
|
1610
|
-
"
|
|
1610
|
+
"eventsName": "before",
|
|
1611
1611
|
"callback": updateBulletsFocus
|
|
1612
1612
|
} );
|
|
1613
1613
|
slider.previous();
|
|
1614
1614
|
},
|
|
1615
1615
|
"onNext": () => {
|
|
1616
1616
|
one( slider, {
|
|
1617
|
-
"
|
|
1617
|
+
"eventsName": "before",
|
|
1618
1618
|
"callback": updateBulletsFocus
|
|
1619
1619
|
} );
|
|
1620
1620
|
slider.next();
|
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.7",
|
|
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": [],
|