@creative-web-solution/front-library 7.0.7 → 7.1.0
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 +15 -0
- package/DOM/Class.ts +10 -12
- package/DOM/DocumentSize.ts +3 -1
- package/DOM/Filter.ts +0 -2
- package/DOM/Index.ts +1 -3
- package/DOM/Manipulation.ts +0 -3
- package/DOM/Matrix.ts +12 -12
- package/DOM/Offset.ts +4 -5
- package/DOM/OuterSize.ts +12 -12
- package/DOM/PageToDOM.ts +2 -2
- package/DOM/Position.ts +3 -3
- package/DOM/Size.ts +3 -7
- package/DOM/StrToDOM.ts +0 -1
- package/DOM/Styles.ts +3 -12
- package/DOM/Traversing.ts +0 -6
- package/DOM/WindowScroll.ts +3 -1
- package/DOM/WindowSize.ts +3 -1
- package/DOM/Wrap.ts +0 -1
- package/Events/DeviceOrientation.ts +27 -31
- package/Events/EventsManager.ts +10 -25
- package/Events/Gesture.ts +36 -37
- package/Events/HistoryController.ts +11 -17
- package/Events/ImageLoad.ts +35 -19
- package/Events/IntersectObserver.ts +15 -19
- package/Events/KeyboardHandler.ts +10 -8
- package/Events/MediaQueriesEvents.ts +53 -51
- package/Events/OnAnimationEnd.ts +2 -3
- package/Events/OnTransitionEnd.ts +3 -3
- package/Events/PubSub.ts +5 -8
- package/Events/TouchHover.ts +18 -21
- package/Events/WindowEvents.ts +26 -30
- package/Helpers/Colors.ts +7 -23
- package/Helpers/Cookie.ts +5 -12
- package/Helpers/Coordinates.ts +0 -7
- package/Helpers/Debounce.ts +3 -7
- package/Helpers/Defer.ts +1 -1
- package/Helpers/GetValue.ts +0 -2
- package/Helpers/Insert.ts +0 -1
- package/Helpers/Sequential.ts +0 -2
- package/Helpers/Slice.ts +0 -3
- package/Helpers/Throttle.ts +0 -1
- package/Helpers/TransitionHelpers.ts +8 -6
- package/Helpers/Type.ts +1 -14
- package/Helpers/Unique.ts +3 -3
- package/Helpers/UrlParser.ts +13 -22
- package/Helpers/Wait.ts +1 -1
- package/Modules/Accordion/Tab.ts +18 -16
- package/Modules/Accordion/index.ts +24 -16
- package/Modules/Autocomplete.ts +95 -101
- package/Modules/DragSlider.ts +72 -63
- package/Modules/GlobalState.ts +60 -53
- package/Modules/LoadGMap.ts +4 -7
- package/Modules/Notifications/Notification.ts +28 -32
- package/Modules/Notifications/index.ts +43 -36
- package/Modules/Popin/Popin.ts +100 -110
- package/Modules/Popin/PopinAccessibility.ts +8 -8
- package/Modules/Popin/PopinBackground.ts +11 -11
- package/Modules/Popin/PopinController.ts +23 -29
- package/Modules/Popin/Tools.ts +18 -19
- package/Modules/QuickTemplate.ts +4 -6
- package/Modules/ScrollSnap.ts +110 -104
- package/Modules/SkinCheckbox.ts +51 -37
- package/Modules/SkinFile.ts +62 -52
- package/Modules/SkinRadio.ts +62 -42
- package/Modules/SkinSelect.ts +116 -100
- package/Modules/Slider/Slide.ts +49 -52
- package/Modules/Slider/Slider.ts +100 -136
- package/Modules/Slider/SliderControls.ts +60 -59
- package/Modules/Tabs/Tab.ts +27 -23
- package/Modules/Tabs/index.ts +35 -25
- package/Modules/Validator/Date.ts +2 -1
- package/Modules/Validator/Equals.ts +1 -1
- package/Modules/Validator/Internal/Input.ts +370 -0
- package/Modules/Validator/Internal/InputValidator.ts +99 -0
- package/Modules/Validator/Internal/ValidatorFunctionsController.ts +58 -0
- package/Modules/Validator/Max.ts +1 -1
- package/Modules/Validator/Min.ts +1 -1
- package/Modules/Validator/MultiRequired.ts +5 -5
- package/Modules/Validator/Number.ts +1 -0
- package/Modules/Validator/Pattern.ts +1 -1
- package/Modules/Validator/Recaptcha.ts +1 -0
- package/Modules/Validator/Required.ts +3 -2
- package/Modules/Validator/ServerCheck.ts +23 -15
- package/Modules/Validator/Tools/GetQueryFromForm.ts +1 -6
- package/Modules/Validator/Tools/IsDate.ts +2 -3
- package/Modules/Validator/Tools/IsEmail.ts +2 -5
- package/Modules/Validator/Tools/IsEmpty.ts +0 -2
- package/Modules/Validator/Tools/IsNumber.ts +0 -2
- package/Modules/Validator/Tools/IsUrl.ts +1 -3
- package/Modules/Validator/Tools/Label.ts +5 -15
- package/Modules/Validator/Tools/RadioButton.ts +4 -10
- package/Modules/Validator/Url.ts +1 -0
- package/Modules/Validator/index.ts +36 -36
- package/Modules/YouTubePlayer.ts +18 -16
- package/README.md +1 -1
- package/Types/Accordion.d.ts +36 -0
- package/Types/Autocomplete.d.ts +95 -0
- package/Types/DOM.d.ts +69 -0
- package/Types/DragSlider.d.ts +56 -0
- package/Types/EventsHelpers.d.ts +390 -0
- package/Types/GLImageTransition.d.ts +47 -43
- package/Types/GlobalState.d.ts +9 -0
- package/Types/Helpers.d.ts +30 -0
- package/Types/Notifications.d.ts +48 -44
- package/Types/Popin.d.ts +95 -0
- package/Types/ScrollSnap.d.ts +66 -0
- package/Types/SkinCheckbox.d.ts +26 -0
- package/Types/SkinFile.d.ts +38 -0
- package/Types/SkinRadio.d.ts +28 -0
- package/Types/SkinSelect.d.ts +59 -0
- package/Types/Slider.d.ts +106 -0
- package/Types/Tabs.d.ts +26 -0
- package/Types/Validator.d.ts +72 -0
- package/Types/YouTubePlayer.d.ts +27 -0
- package/Types/index.d.ts +22 -21
- package/WebGL/GLImageTransition/GLImageTransition.ts +83 -80
- package/WebGL/GLImageTransition/Presets/Cellular.ts +11 -11
- package/WebGL/GLImageTransition/Presets/Fade.ts +2 -3
- package/WebGL/GLImageTransition/Presets/HorizontalMovingGrid.ts +9 -9
- package/WebGL/GLImageTransition/Presets/PresetSample.ts +11 -9
- package/WebGL/GLImageTransition/Presets/Solarisation.ts +7 -12
- package/package.json +1 -1
- package/Modules/Template.ts +0 -209
- package/Types/AccordionTypes.d.ts +0 -29
- package/Types/AutocompleteTypes.d.ts +0 -85
- package/Types/DOMTypes.d.ts +0 -62
- package/Types/DragSliderTypes.d.ts +0 -52
- package/Types/EventsHelpersTypes.d.ts +0 -370
- package/Types/GlobalStateTypes.d.ts +0 -5
- package/Types/HelpersTypes.d.ts +0 -23
- package/Types/MediaPreloaderTypes.d.ts +0 -12
- package/Types/PopinTypes.d.ts +0 -83
- package/Types/ScrollSnapTypes.d.ts +0 -62
- package/Types/SkinCheckboxTypes.d.ts +0 -23
- package/Types/SkinFileTypes.d.ts +0 -34
- package/Types/SkinRadioTypes.d.ts +0 -24
- package/Types/SkinSelectTypes.d.ts +0 -48
- package/Types/SliderTypes.d.ts +0 -97
- package/Types/TabsTypes.d.ts +0 -22
- package/Types/ValidatorTypes.d.ts +0 -61
- package/Types/YouTubePlayerTypes.d.ts +0 -23
package/Modules/SkinSelect.ts
CHANGED
|
@@ -9,33 +9,27 @@ import { rClass } from '../DOM/Class';
|
|
|
9
9
|
import { position } from '../DOM/Position';
|
|
10
10
|
import { height } from '../DOM/Size';
|
|
11
11
|
import { outerHeight } from '../DOM/OuterSize';
|
|
12
|
-
import
|
|
12
|
+
import quickTemplate from './QuickTemplate';
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
const defaultOptions:
|
|
15
|
+
const defaultOptions: FLib.SkinSelect.Options = {
|
|
16
16
|
"full": false,
|
|
17
17
|
"extraClass": [],
|
|
18
18
|
"className": "select-skin",
|
|
19
19
|
"itemClassName": "select-itm",
|
|
20
20
|
"selectWrapClassName": "select",
|
|
21
21
|
"layerClassName": "select-layer",
|
|
22
|
+
"listClassName": "select-list",
|
|
22
23
|
"hoverItemClass": "hover",
|
|
23
24
|
"openedListClass": "show",
|
|
24
25
|
"activeOptionClass": "on",
|
|
25
26
|
"disabledClass": "disabled",
|
|
26
27
|
"invalidClass": "invalid",
|
|
27
28
|
"loadingClass": "loading",
|
|
28
|
-
"listTpl":
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
'<li class="select-itm<%= list[ i ].selected ? " on" : "" %>" data-value="<%= list[ i ].value %>">',
|
|
33
|
-
'<%= list[ i ].text %>',
|
|
34
|
-
'</li>',
|
|
35
|
-
'<% } %>',
|
|
36
|
-
'</ul>',
|
|
37
|
-
'</div>'
|
|
38
|
-
].join('')
|
|
29
|
+
"listTpl": {
|
|
30
|
+
"wrapper": "<div class=\"{{ layerClassName }}\"><ul class=\"{{ listClassName }}\">{{ items }}</ul></div>",
|
|
31
|
+
"item": "<li class=\"{{ itemClassName }}{{ onClass }}\" data-value=\"{{ value }}\">{{ text }}</li>"
|
|
32
|
+
}
|
|
39
33
|
};
|
|
40
34
|
|
|
41
35
|
|
|
@@ -44,19 +38,19 @@ const defaultOptions: SkinSelectOptionsType = {
|
|
|
44
38
|
* You can access the skin API in the __skinAPI property of the $select HTMLElement or its wrapper.
|
|
45
39
|
*/
|
|
46
40
|
export default class SkinSelect {
|
|
47
|
-
#$select:
|
|
41
|
+
#$select: FLib.SkinSelect.CustomSelect;
|
|
48
42
|
#loading!: boolean;
|
|
49
|
-
#options!:
|
|
43
|
+
#options!: FLib.SkinSelect.Options;
|
|
50
44
|
#extraClass!: string;
|
|
51
|
-
#$parent!:
|
|
45
|
+
#$parent!: FLib.SkinSelect.CustomSelectParent;
|
|
52
46
|
#$title!: HTMLElement;
|
|
53
47
|
#isListOpened!: boolean;
|
|
54
48
|
#$options!: NodeList;
|
|
55
|
-
#$lastOption!: HTMLElement |
|
|
49
|
+
#$lastOption!: HTMLElement | null;
|
|
56
50
|
#focusedItemIndex!: number;
|
|
57
51
|
#$layer!: HTMLElement;
|
|
58
52
|
|
|
59
|
-
constructor( $select: HTMLSelectElement, userOptions?:
|
|
53
|
+
constructor( $select: HTMLSelectElement, userOptions?: Partial<FLib.SkinSelect.Options> ) {
|
|
60
54
|
|
|
61
55
|
this.#$select = $select;
|
|
62
56
|
|
|
@@ -77,7 +71,7 @@ export default class SkinSelect {
|
|
|
77
71
|
this.#$parent = $select.parentNode as HTMLElement;
|
|
78
72
|
|
|
79
73
|
// Create skin
|
|
80
|
-
if ( !hClass( this.#$parent, this.#options.className
|
|
74
|
+
if ( !hClass( this.#$parent, this.#options.className ) ) {
|
|
81
75
|
this.#$parent = wrap(
|
|
82
76
|
this.#$select,
|
|
83
77
|
`<span class="${ this.#options.className } ${ this.#extraClass }"></span>`
|
|
@@ -89,7 +83,7 @@ export default class SkinSelect {
|
|
|
89
83
|
|
|
90
84
|
if ( !$TITLE ) {
|
|
91
85
|
this.#$title = document.createElement( 'SPAN' );
|
|
92
|
-
aClass( this.#$title, this.#options.selectWrapClassName
|
|
86
|
+
aClass( this.#$title, this.#options.selectWrapClassName );
|
|
93
87
|
this.#$parent.appendChild( this.#$title );
|
|
94
88
|
}
|
|
95
89
|
else {
|
|
@@ -137,8 +131,8 @@ export default class SkinSelect {
|
|
|
137
131
|
}
|
|
138
132
|
|
|
139
133
|
|
|
140
|
-
#closeList = () => {
|
|
141
|
-
this.#$parent.classList.remove( this.#options.openedListClass
|
|
134
|
+
#closeList = (): void => {
|
|
135
|
+
this.#$parent.classList.remove( this.#options.openedListClass );
|
|
142
136
|
|
|
143
137
|
off( document.body, {
|
|
144
138
|
"eventsName": "click",
|
|
@@ -147,12 +141,11 @@ export default class SkinSelect {
|
|
|
147
141
|
|
|
148
142
|
this.#isListOpened = false;
|
|
149
143
|
|
|
150
|
-
this
|
|
151
|
-
|
|
144
|
+
this.#removeItemFocus();
|
|
152
145
|
}
|
|
153
146
|
|
|
154
147
|
|
|
155
|
-
#openList = () => {
|
|
148
|
+
#openList = (): void => {
|
|
156
149
|
if ( this.#$select.disabled || this.#loading ) {
|
|
157
150
|
return;
|
|
158
151
|
}
|
|
@@ -162,7 +155,7 @@ export default class SkinSelect {
|
|
|
162
155
|
return;
|
|
163
156
|
}
|
|
164
157
|
|
|
165
|
-
this.#$parent.classList.add( this.#options.openedListClass
|
|
158
|
+
this.#$parent.classList.add( this.#options.openedListClass );
|
|
166
159
|
|
|
167
160
|
window.requestAnimationFrame( () => {
|
|
168
161
|
on( document.body, {
|
|
@@ -177,14 +170,14 @@ export default class SkinSelect {
|
|
|
177
170
|
this.#focusedItemIndex = this.#focusedItemIndex > -1 ? this.#focusedItemIndex : 0;
|
|
178
171
|
}
|
|
179
172
|
|
|
180
|
-
this
|
|
173
|
+
this.#focusItem( this.#focusedItemIndex );
|
|
181
174
|
}
|
|
182
175
|
|
|
183
176
|
this.#isListOpened = true;
|
|
184
177
|
}
|
|
185
178
|
|
|
186
179
|
|
|
187
|
-
|
|
180
|
+
#enableDisable = ( fnName: string, disabled: boolean ): void => {
|
|
188
181
|
this.#$select.disabled = disabled;
|
|
189
182
|
this.#$parent.classList[ fnName ]( this.#options.disabledClass );
|
|
190
183
|
}
|
|
@@ -193,20 +186,24 @@ export default class SkinSelect {
|
|
|
193
186
|
/**
|
|
194
187
|
* Force the select to be enable
|
|
195
188
|
*/
|
|
196
|
-
enable() {
|
|
197
|
-
this
|
|
189
|
+
enable(): this {
|
|
190
|
+
this.#enableDisable( 'remove', false );
|
|
191
|
+
|
|
192
|
+
return this
|
|
198
193
|
}
|
|
199
194
|
|
|
200
195
|
|
|
201
196
|
/**
|
|
202
197
|
* Force the select to be disable
|
|
203
198
|
*/
|
|
204
|
-
disable() {
|
|
205
|
-
this
|
|
199
|
+
disable(): this {
|
|
200
|
+
this.#enableDisable( 'add', true );
|
|
201
|
+
|
|
202
|
+
return this
|
|
206
203
|
}
|
|
207
204
|
|
|
208
205
|
|
|
209
|
-
|
|
206
|
+
#loadingStatus = ( fnName: string, isLoading: boolean ): void => {
|
|
210
207
|
this.#loading = isLoading;
|
|
211
208
|
this.#$parent.classList[ fnName ]( this.#options.loadingClass );
|
|
212
209
|
}
|
|
@@ -215,20 +212,24 @@ export default class SkinSelect {
|
|
|
215
212
|
/**
|
|
216
213
|
* Add the loading css class to the main element
|
|
217
214
|
*/
|
|
218
|
-
setLoading() {
|
|
219
|
-
this
|
|
215
|
+
setLoading(): this {
|
|
216
|
+
this.#loadingStatus( 'add', true );
|
|
217
|
+
|
|
218
|
+
return this;
|
|
220
219
|
}
|
|
221
220
|
|
|
222
221
|
|
|
223
222
|
/**
|
|
224
223
|
* Remove the loading css class to the main element
|
|
225
224
|
*/
|
|
226
|
-
unsetLoading() {
|
|
227
|
-
this
|
|
225
|
+
unsetLoading(): this {
|
|
226
|
+
this.#loadingStatus( 'remove', false );
|
|
227
|
+
|
|
228
|
+
return this;
|
|
228
229
|
}
|
|
229
230
|
|
|
230
231
|
|
|
231
|
-
|
|
232
|
+
#validInvalid = ( fnName: string ): void => {
|
|
232
233
|
this.#$parent.classList[ fnName ]( this.#options.invalidClass );
|
|
233
234
|
}
|
|
234
235
|
|
|
@@ -236,52 +237,55 @@ export default class SkinSelect {
|
|
|
236
237
|
/**
|
|
237
238
|
* Force the state of the select to invalid
|
|
238
239
|
*/
|
|
239
|
-
setInvalid() {
|
|
240
|
-
this
|
|
241
|
-
|
|
240
|
+
setInvalid(): this {
|
|
241
|
+
this.#validInvalid( 'add' );
|
|
242
|
+
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
242
245
|
|
|
243
246
|
|
|
244
247
|
/**
|
|
245
248
|
* Force the state of the select to valid
|
|
246
249
|
*/
|
|
247
|
-
setValid() {
|
|
248
|
-
this
|
|
249
|
-
|
|
250
|
+
setValid(): this {
|
|
251
|
+
this.#validInvalid( 'remove' );
|
|
252
|
+
|
|
253
|
+
return this;
|
|
254
|
+
}
|
|
250
255
|
|
|
251
256
|
|
|
252
257
|
/**
|
|
253
258
|
* Force the update of title with the currently selected element text
|
|
254
259
|
*/
|
|
255
|
-
updateTitle() {
|
|
256
|
-
let title;
|
|
260
|
+
updateTitle(): this {
|
|
257
261
|
|
|
258
262
|
if ( this.#$select.selectedIndex < 0 ) {
|
|
259
263
|
this.#$title.innerHTML = '';
|
|
260
264
|
this.#closeList();
|
|
261
|
-
return;
|
|
265
|
+
return this;
|
|
262
266
|
}
|
|
263
267
|
|
|
264
|
-
title = this.#$select.options[ this.#$select.selectedIndex ].text;
|
|
268
|
+
const title = this.#$select.options[ this.#$select.selectedIndex ].text;
|
|
265
269
|
|
|
266
270
|
this.#$title.innerHTML = title;
|
|
267
271
|
|
|
268
272
|
this.#closeList();
|
|
273
|
+
|
|
274
|
+
return this;
|
|
269
275
|
}
|
|
270
276
|
|
|
271
277
|
|
|
272
278
|
/**
|
|
273
279
|
* Select an option
|
|
274
|
-
*
|
|
275
|
-
* @param {HTMLElement|Number} optionOrIndex
|
|
276
280
|
*/
|
|
277
|
-
select( optionOrIndex: HTMLElement | number ) {
|
|
278
|
-
let _index, option
|
|
281
|
+
select( optionOrIndex: HTMLElement | number ): this {
|
|
282
|
+
let _index, option;
|
|
279
283
|
|
|
280
284
|
if ( this.#$select.disabled || this.#loading ) {
|
|
281
|
-
return;
|
|
285
|
+
return this;
|
|
282
286
|
}
|
|
283
287
|
|
|
284
|
-
isParameterANumber = isNumber( optionOrIndex );
|
|
288
|
+
const isParameterANumber = isNumber( optionOrIndex );
|
|
285
289
|
|
|
286
290
|
if ( isParameterANumber ) {
|
|
287
291
|
_index = optionOrIndex;
|
|
@@ -291,7 +295,7 @@ export default class SkinSelect {
|
|
|
291
295
|
}
|
|
292
296
|
|
|
293
297
|
if ( _index < 0 || _index > this.#$select.options.length ) {
|
|
294
|
-
return;
|
|
298
|
+
return this;
|
|
295
299
|
}
|
|
296
300
|
|
|
297
301
|
this.#$select.options[ _index ].selected = true;
|
|
@@ -300,7 +304,7 @@ export default class SkinSelect {
|
|
|
300
304
|
option = this.#$parent.querySelectorAll( `.${ this.#options.itemClassName }` )[ _index ];
|
|
301
305
|
|
|
302
306
|
if ( this.#$lastOption ) {
|
|
303
|
-
this.#$lastOption.classList.remove( this.#options.activeOptionClass
|
|
307
|
+
this.#$lastOption.classList.remove( this.#options.activeOptionClass );
|
|
304
308
|
}
|
|
305
309
|
|
|
306
310
|
if ( option ) {
|
|
@@ -312,15 +316,17 @@ export default class SkinSelect {
|
|
|
312
316
|
fire( this.#$select, {
|
|
313
317
|
"eventsName": "change"
|
|
314
318
|
} );
|
|
319
|
+
|
|
320
|
+
return this;
|
|
315
321
|
}
|
|
316
322
|
|
|
317
323
|
|
|
318
|
-
|
|
319
|
-
let
|
|
324
|
+
#setSelectOptions = ( data: FLib.SkinSelect.OptionArray[] ): void => {
|
|
325
|
+
let hasSelectedOption;
|
|
320
326
|
|
|
321
327
|
this.#$select.options.length = 0;
|
|
322
328
|
|
|
323
|
-
normalizedData = data.map( dt => {
|
|
329
|
+
const normalizedData = data.map( dt => {
|
|
324
330
|
if ( dt.selected ) {
|
|
325
331
|
hasSelectedOption = true;
|
|
326
332
|
}
|
|
@@ -347,24 +353,23 @@ export default class SkinSelect {
|
|
|
347
353
|
/**
|
|
348
354
|
* Update the options list. If optionsArray is not set, only update the html of the skinned options list.
|
|
349
355
|
*
|
|
350
|
-
* @param optionsArray
|
|
351
|
-
*
|
|
352
356
|
* @example
|
|
357
|
+
* ```ts
|
|
353
358
|
* selectAPI.updateOptions( [{"text": "Option 1", "value": "value 1", "selected": true}, ...] )
|
|
359
|
+
* ```
|
|
354
360
|
*/
|
|
355
|
-
updateOptions( optionsArray?:
|
|
356
|
-
let htmlList;
|
|
361
|
+
updateOptions( optionsArray?: FLib.SkinSelect.OptionArray[] ): this {
|
|
357
362
|
|
|
358
363
|
this.#$lastOption = null;
|
|
359
364
|
this.#focusedItemIndex = -1;
|
|
360
365
|
|
|
361
366
|
if ( optionsArray ) {
|
|
362
|
-
this
|
|
367
|
+
this.#setSelectOptions( optionsArray );
|
|
363
368
|
this.updateTitle();
|
|
364
369
|
}
|
|
365
370
|
|
|
366
371
|
if ( !this.#options.full ) {
|
|
367
|
-
return;
|
|
372
|
+
return this;
|
|
368
373
|
}
|
|
369
374
|
|
|
370
375
|
this.#$select.style.display = 'none';
|
|
@@ -375,31 +380,46 @@ export default class SkinSelect {
|
|
|
375
380
|
this.#$layer.parentNode.removeChild( this.#$layer );
|
|
376
381
|
}
|
|
377
382
|
|
|
378
|
-
htmlList = template( this.#options.listTpl
|
|
379
|
-
|
|
383
|
+
// let htmlList = template( this.#options.listTpl, { "list": this.#$select.options } );
|
|
384
|
+
const HTML_LIST: string[] = [];
|
|
385
|
+
|
|
386
|
+
for ( const opt of Array.from( this.#$select.options ) ) {
|
|
387
|
+
HTML_LIST.push( quickTemplate( this.#options.listTpl.item, {
|
|
388
|
+
"onClass": opt.selected ? " on" : "",
|
|
389
|
+
"text": opt.text,
|
|
390
|
+
"value": opt.value
|
|
391
|
+
} ) );
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
this.#$parent.appendChild( strToDOM( quickTemplate( this.#options.listTpl.wrapper, {
|
|
395
|
+
"items": HTML_LIST.join( '' )
|
|
396
|
+
} ) ) );
|
|
397
|
+
|
|
380
398
|
|
|
381
399
|
this.#$layer = this.#$parent.querySelector( `.${ this.#options.layerClassName }` ) as HTMLElement;
|
|
382
400
|
this.#$options = this.#$layer.querySelectorAll( 'li' );
|
|
383
401
|
|
|
384
402
|
this.#$lastOption = this.#$parent.querySelector( `li.${ this.#options.activeOptionClass }` );
|
|
403
|
+
|
|
404
|
+
return this;
|
|
385
405
|
}
|
|
386
406
|
|
|
387
407
|
|
|
388
|
-
#changeHandler = () => {
|
|
408
|
+
#changeHandler = (): void => {
|
|
389
409
|
this.updateTitle();
|
|
390
410
|
}
|
|
391
411
|
|
|
392
412
|
|
|
393
413
|
// Handle click on the skinned ul>li list
|
|
394
|
-
#fakeOptionsClickHandler = ( e ) => {
|
|
395
|
-
if ( !e.target.matches( '.' + this.#options.itemClassName ) ) {
|
|
414
|
+
#fakeOptionsClickHandler = ( e: MouseEvent ): void => {
|
|
415
|
+
if ( !(e.target as HTMLElement).matches( '.' + this.#options.itemClassName ) ) {
|
|
396
416
|
return;
|
|
397
417
|
}
|
|
398
|
-
this.select( e.target );
|
|
418
|
+
this.select( e.target as HTMLElement );
|
|
399
419
|
}
|
|
400
420
|
|
|
401
421
|
|
|
402
|
-
|
|
422
|
+
#focusItem = ( index: number ): void => {
|
|
403
423
|
if ( index < 0 ) {
|
|
404
424
|
index = this.#$options.length - 1;
|
|
405
425
|
}
|
|
@@ -410,24 +430,24 @@ export default class SkinSelect {
|
|
|
410
430
|
return;
|
|
411
431
|
}
|
|
412
432
|
|
|
413
|
-
this
|
|
433
|
+
this.#removeItemFocus();
|
|
414
434
|
|
|
415
|
-
aClass( this.#$options[ index ], this.#options.hoverItemClass
|
|
416
|
-
this
|
|
435
|
+
aClass( this.#$options[ index ], this.#options.hoverItemClass );
|
|
436
|
+
this.#updateListScroll( this.#$options[ index ] as HTMLElement );
|
|
417
437
|
|
|
418
438
|
this.#focusedItemIndex = index;
|
|
419
439
|
}
|
|
420
440
|
|
|
421
441
|
|
|
422
|
-
|
|
442
|
+
#removeItemFocus = (): void => {
|
|
423
443
|
if ( this.#focusedItemIndex !== null && this.#$options && this.#$options[ this.#focusedItemIndex ] ) {
|
|
424
|
-
rClass( this.#$options[ this.#focusedItemIndex ], this.#options.hoverItemClass
|
|
444
|
+
rClass( this.#$options[ this.#focusedItemIndex ], this.#options.hoverItemClass );
|
|
425
445
|
this.#focusedItemIndex = -1;
|
|
426
446
|
}
|
|
427
447
|
}
|
|
428
448
|
|
|
429
449
|
|
|
430
|
-
|
|
450
|
+
#updateListScroll = ( $item: HTMLElement ): void => {
|
|
431
451
|
let itemPos, itemHeight, layerScrollTop, layerHeight;
|
|
432
452
|
|
|
433
453
|
if ( this.#$layer ) {
|
|
@@ -446,7 +466,7 @@ export default class SkinSelect {
|
|
|
446
466
|
}
|
|
447
467
|
|
|
448
468
|
|
|
449
|
-
#onKeydown = ( e ) => {
|
|
469
|
+
#onKeydown = ( e: KeyboardEvent ): void => {
|
|
450
470
|
switch ( e.keyCode ) {
|
|
451
471
|
case 38: // UP
|
|
452
472
|
case 40: // DOWN
|
|
@@ -458,17 +478,17 @@ export default class SkinSelect {
|
|
|
458
478
|
}
|
|
459
479
|
|
|
460
480
|
|
|
461
|
-
#onKeyup = ( e ) => {
|
|
481
|
+
#onKeyup = ( e: KeyboardEvent ): void => {
|
|
462
482
|
switch ( e.keyCode ) {
|
|
463
483
|
case 38: // UP
|
|
464
|
-
this
|
|
484
|
+
this.#focusItem( this.#focusedItemIndex - 1 );
|
|
465
485
|
break;
|
|
466
486
|
case 40: // DOWN
|
|
467
487
|
if ( !this.#isListOpened ) {
|
|
468
488
|
this.#openList();
|
|
469
489
|
break;
|
|
470
490
|
}
|
|
471
|
-
this
|
|
491
|
+
this.#focusItem( this.#focusedItemIndex + 1 );
|
|
472
492
|
break;
|
|
473
493
|
|
|
474
494
|
case 13: // ENTER
|
|
@@ -493,31 +513,29 @@ export default class SkinSelect {
|
|
|
493
513
|
* Skin a select DOM element
|
|
494
514
|
*
|
|
495
515
|
* @example
|
|
516
|
+
* ```ts
|
|
496
517
|
* // Call with default options:
|
|
497
518
|
* skinSelect( $select, {
|
|
498
519
|
* "full": false,
|
|
499
|
-
* "extraClass": [
|
|
520
|
+
* "extraClass": [],
|
|
500
521
|
* "className": "select-skin",
|
|
501
522
|
* "itemClassName": "select-itm",
|
|
502
523
|
* "selectWrapClassName": "select",
|
|
524
|
+
* "layerClassName": "select-layer",
|
|
525
|
+
* "listClassName": "select-list",
|
|
526
|
+
* "hoverItemClass": "hover",
|
|
503
527
|
* "openedListClass": "show",
|
|
504
528
|
* "activeOptionClass": "on",
|
|
505
529
|
* "disabledClass": "disabled",
|
|
530
|
+
* "invalidClass": "invalid",
|
|
506
531
|
* "loadingClass": "loading",
|
|
507
|
-
* "listTpl":
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* '<%= list[ i ].text %>',
|
|
513
|
-
* '</li>',
|
|
514
|
-
* '<% } %>',
|
|
515
|
-
* '</ul>',
|
|
516
|
-
* '</div>'
|
|
517
|
-
* ].join( '' )
|
|
518
|
-
* } );
|
|
532
|
+
* "listTpl": {
|
|
533
|
+
* "wrapper": "<div class=\"{{ layerClassName }}\"><ul class=\"{{ listClassName }}\">{{ items }}</ul></div>",
|
|
534
|
+
* "item": "<li class=\"{{ itemClassName }}{{ onClass }}\" data-value=\"{{ value }}\">{{ text }}</li>"
|
|
535
|
+
* }
|
|
536
|
+
* ```
|
|
519
537
|
*/
|
|
520
|
-
export function skinSelect( $select: HTMLSelectElement, options:
|
|
538
|
+
export function skinSelect( $select: HTMLSelectElement, options: Partial<FLib.SkinSelect.Options> ): SkinSelect {
|
|
521
539
|
return new SkinSelect( $select, options );
|
|
522
540
|
}
|
|
523
541
|
|
|
@@ -528,13 +546,11 @@ export function skinSelect( $select: HTMLSelectElement, options: SkinSelectOptio
|
|
|
528
546
|
* @example
|
|
529
547
|
* // See skinSelect for example of options
|
|
530
548
|
* skinSelectAll( $wrapper, options )
|
|
531
|
-
*
|
|
532
|
-
* @returns {SkinSelect[]}
|
|
533
549
|
*/
|
|
534
|
-
export function skinSelectAll( $wrapper: HTMLElement, userOptions:
|
|
550
|
+
export function skinSelectAll( $wrapper: HTMLElement, userOptions: Partial<FLib.SkinSelect.AllOptions> = {} ): SkinSelect[] {
|
|
535
551
|
const skinList: SkinSelect[] = [];
|
|
536
552
|
|
|
537
|
-
const defaultOptions:
|
|
553
|
+
const defaultOptions: Partial<FLib.SkinSelect.AllOptions> = {
|
|
538
554
|
"full": false,
|
|
539
555
|
"extraClass": []
|
|
540
556
|
};
|