@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
|
@@ -8,18 +8,26 @@ import { addValidator } from './index';
|
|
|
8
8
|
* data-servercheck-method="get|post"
|
|
9
9
|
*
|
|
10
10
|
* Return JSON format:
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```json
|
|
11
14
|
* {
|
|
12
|
-
*
|
|
15
|
+
* "isValid": true|false
|
|
13
16
|
* }
|
|
17
|
+
* ```
|
|
14
18
|
*
|
|
15
19
|
* Validator parameters:
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```json
|
|
16
23
|
* {
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
24
|
+
* "beforeCall": function( $input, value ),
|
|
25
|
+
* "afterCall": function( $input, value ),
|
|
26
|
+
* "normalize": fuction( response ){ return { "isValid": true|false } },
|
|
27
|
+
* "onFail": function( $input, value ),
|
|
28
|
+
* "allowLiveValidation": true|false,
|
|
22
29
|
* }
|
|
30
|
+
* ```
|
|
23
31
|
*/
|
|
24
32
|
addValidator(
|
|
25
33
|
'servercheck',
|
|
@@ -27,10 +35,10 @@ addValidator(
|
|
|
27
35
|
true,
|
|
28
36
|
( $input, value, isLiveValidation, options = {} ) => {
|
|
29
37
|
|
|
30
|
-
return new Promise<
|
|
31
|
-
let
|
|
38
|
+
return new Promise<FLib.Validator.ValidationState>( resolve => {
|
|
39
|
+
let url, method;
|
|
32
40
|
|
|
33
|
-
|
|
41
|
+
const { beforeCall, afterCall, normalize, onFail } = options;
|
|
34
42
|
|
|
35
43
|
if ( !( "AbortController" in window ) ) {
|
|
36
44
|
throw 'This plugin uses fecth and AbortController. You may need to add a polyfill for this browser.';
|
|
@@ -47,19 +55,19 @@ addValidator(
|
|
|
47
55
|
} );
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
paramName = $input.getAttribute( 'name' );
|
|
58
|
+
const paramName = $input.getAttribute( 'name' );
|
|
51
59
|
url = $input.getAttribute( 'data-servercheck' );
|
|
52
60
|
method = $input.getAttribute( 'data-servercheck-method' ) || 'GET';
|
|
53
61
|
method = method.toUpperCase();
|
|
54
62
|
|
|
55
|
-
data = `${ paramName }=${ value }`;
|
|
63
|
+
const data = `${ paramName }=${ value }`;
|
|
56
64
|
|
|
57
65
|
if ( method === 'GET' ) {
|
|
58
66
|
url = [ url, url.indexOf('?') > -1 ? '&' : '?', data ].join( '' );
|
|
59
67
|
}
|
|
60
68
|
|
|
61
69
|
// Helper to create state
|
|
62
|
-
function state( isValid ):
|
|
70
|
+
function state( isValid ): FLib.Validator.ValidationState {
|
|
63
71
|
return {
|
|
64
72
|
$input,
|
|
65
73
|
value,
|
|
@@ -73,7 +81,7 @@ addValidator(
|
|
|
73
81
|
beforeCall( $input, value );
|
|
74
82
|
}
|
|
75
83
|
|
|
76
|
-
myHeaders = new Headers();
|
|
84
|
+
const myHeaders = new Headers();
|
|
77
85
|
myHeaders.append( 'X-Requested-With', 'XMLHttpRequest' );
|
|
78
86
|
|
|
79
87
|
fetch(
|
|
@@ -89,9 +97,9 @@ addValidator(
|
|
|
89
97
|
return response;
|
|
90
98
|
}
|
|
91
99
|
else {
|
|
92
|
-
|
|
93
|
-
/** @ts-expect-error */
|
|
100
|
+
const error: Error & { response? } = new Error( response.statusText );
|
|
94
101
|
error.response = response;
|
|
102
|
+
|
|
95
103
|
throw error;
|
|
96
104
|
}
|
|
97
105
|
} )
|
|
@@ -5,12 +5,7 @@ import { getValue } from '../../../Helpers/GetValue';
|
|
|
5
5
|
* Create a query with the fields of a form.
|
|
6
6
|
* Use a fallback for browser that doesn't support new URLSearchParams( formData ).toString()
|
|
7
7
|
*
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
* @param $form
|
|
11
|
-
* @param [selector='select,input,textarea'] Only used for browser with no native new URLSearchParams( formData ).toString()
|
|
12
|
-
*
|
|
13
|
-
* @returns {String}
|
|
8
|
+
* @param selector - Only used for browser with no native new URLSearchParams( formData ).toString()
|
|
14
9
|
*/
|
|
15
10
|
export default function getQueryFromForm( $form: HTMLFormElement, selector = 'select,input,textarea' ): string {
|
|
16
11
|
let query;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Test if the value is a date
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param [format="d/m/y"] d for day, m for month and y for year. Only in lowercase. January = 1
|
|
4
|
+
* @param format - d for day, m for month and y for year. Only in lowercase. January = 1
|
|
6
5
|
*
|
|
7
6
|
* @see extra/modules/validator.md for details
|
|
8
7
|
*/
|
|
9
|
-
export default function isDate( value: string, format
|
|
8
|
+
export default function isDate( value: string, format = 'd/m/y' ): boolean {
|
|
10
9
|
const RE_SEPARATOR = ( /[^dmy]/ ).exec( format );
|
|
11
10
|
|
|
12
11
|
if ( !RE_SEPARATOR ) {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
// Regular expression from Symfony
|
|
2
|
-
const RE_EMAIL = /^[a-zA-Z0-9
|
|
3
|
-
const RE_EMAIL_LOOSE =
|
|
2
|
+
const RE_EMAIL = /^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/;
|
|
3
|
+
const RE_EMAIL_LOOSE = /^.+@\S+\.\S+$/;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Test if the value is an email
|
|
7
7
|
*
|
|
8
|
-
* @param value
|
|
9
|
-
* @param [loose]
|
|
10
|
-
*
|
|
11
8
|
* @see extra/modules/validator.md for details
|
|
12
9
|
*/
|
|
13
10
|
export default function isEmail( value: string, loose?: boolean ): boolean {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const urlRe = /^(https?:\/\/)?[\da-z
|
|
1
|
+
const urlRe = /^(https?:\/\/)?[\da-z.-]+\.[a-z.]{2,6}[#&+_?/\w .\-=]*$/i;
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Test if the value is an url
|
|
5
5
|
*
|
|
6
|
-
* @param value
|
|
7
|
-
*
|
|
8
6
|
* @see extra/modules/validator.md for details
|
|
9
7
|
*/
|
|
10
8
|
export default function isUrl( value: string ): boolean {
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @param $input
|
|
5
|
-
* @param [$wrapper=document.body]
|
|
2
|
+
* Return the label, if there is only one, the list of labels if many or null if none
|
|
6
3
|
*
|
|
7
4
|
* @see extra/modules/validator.md for details
|
|
8
|
-
*
|
|
9
|
-
* @return Return the label, if there is only one, the list of labels if many or null if none
|
|
10
5
|
*/
|
|
11
6
|
export function getLabelElement( $input: HTMLElement, $wrapper: HTMLElement = document.body ): HTMLElement | NodeList | null {
|
|
12
|
-
|
|
7
|
+
const $labels = $wrapper.querySelectorAll( `label[for="${ $input.id }"]` );
|
|
13
8
|
|
|
14
9
|
if ( !$labels.length ) {
|
|
15
10
|
return null;
|
|
@@ -23,17 +18,12 @@ export function getLabelElement( $input: HTMLElement, $wrapper: HTMLElement = do
|
|
|
23
18
|
|
|
24
19
|
|
|
25
20
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @param $input
|
|
29
|
-
* @param [$wrapper=document.body]
|
|
21
|
+
* Return the label, if there is only one, the list of labels if many or '' if none
|
|
30
22
|
*
|
|
31
23
|
* @see extra/modules/validator.md for details
|
|
32
|
-
*
|
|
33
|
-
* @return Return the label, if there is only one, the list of labels if many or '' if none
|
|
34
24
|
*/
|
|
35
25
|
export function getLabel( $input: HTMLElement, $wrapper: HTMLElement = document.body ): string | string[] {
|
|
36
|
-
|
|
26
|
+
const $labels = getLabelElement( $input, $wrapper );
|
|
37
27
|
|
|
38
28
|
if ( !$labels ) {
|
|
39
29
|
return '';
|
|
@@ -42,5 +32,5 @@ export function getLabel( $input: HTMLElement, $wrapper: HTMLElement = document.
|
|
|
42
32
|
return Array.from( $labels ).map( $label => $label.textContent || '' );
|
|
43
33
|
}
|
|
44
34
|
|
|
45
|
-
return $labels.textContent ||
|
|
35
|
+
return $labels.textContent || '';
|
|
46
36
|
}
|
|
@@ -3,10 +3,8 @@ import { extend } from '../../../Helpers/Extend';
|
|
|
3
3
|
/**
|
|
4
4
|
* Get all radio with the same name
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param [userOptions.selector=input[name="{NAME}"]] - css selector of the elements with a {GROUP_NAME} tag that will be replace by groupName var.
|
|
9
|
-
* @param [userOptions.othersOnly=false] - if true, return the list without the element in `inputRadioOrInputName`. If `inputRadioOrInputName` is a string (input name), return all radio
|
|
6
|
+
* @param selector - css selector of the elements with a `{`GROUP_NAME`}` tag that will be replace by groupName var.
|
|
7
|
+
* @param othersOnly - if true, return the list without the element in `inputRadioOrInputName`. If `inputRadioOrInputName` is a string (input name), return all radio
|
|
10
8
|
*
|
|
11
9
|
* @see extra/modules/validator.md for details
|
|
12
10
|
*
|
|
@@ -54,16 +52,12 @@ export function getRadioList( inputRadioOrInputName: HTMLElement | string, userO
|
|
|
54
52
|
|
|
55
53
|
|
|
56
54
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @param $iputRadioOrRadioList
|
|
55
|
+
* Return the selected radio button from a group or false
|
|
60
56
|
*
|
|
61
57
|
* @see extra/modules/validator.md for details
|
|
62
|
-
*
|
|
63
|
-
* @return Return the selected radio button from a group or false
|
|
64
58
|
*/
|
|
65
59
|
export function isRadioListChecked( $iputRadioOrRadioList: HTMLElement[] | HTMLElement | NodeList ): false | HTMLInputElement {
|
|
66
|
-
|
|
60
|
+
const $list = ( $iputRadioOrRadioList instanceof NodeList || $iputRadioOrRadioList instanceof Array ) ? $iputRadioOrRadioList : getRadioList( $iputRadioOrRadioList );
|
|
67
61
|
|
|
68
62
|
for ( const $item of Array.from( $list ) ) {
|
|
69
63
|
if ( ($item as HTMLInputElement).checked ) {
|
package/Modules/Validator/Url.ts
CHANGED
|
@@ -33,6 +33,7 @@ const defaultOptions = {
|
|
|
33
33
|
* @see extra/modules/validator.md for details
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
|
+
* ```ts
|
|
36
37
|
* let validator = new Validator( $form, options )
|
|
37
38
|
*
|
|
38
39
|
* on( $form, {
|
|
@@ -56,21 +57,22 @@ const defaultOptions = {
|
|
|
56
57
|
* );
|
|
57
58
|
* }
|
|
58
59
|
* });
|
|
60
|
+
* ```
|
|
59
61
|
*/
|
|
60
62
|
export default class Validator {
|
|
61
|
-
#options:
|
|
63
|
+
#options: FLib.Validator.Options & { hasLiveValidation: boolean };
|
|
62
64
|
#inputsList: Input[];
|
|
63
|
-
#radioDuplicateHash:
|
|
65
|
+
#radioDuplicateHash: Record<string, boolean>;
|
|
64
66
|
#state: string;
|
|
65
67
|
#$form: HTMLElement;
|
|
66
|
-
#validationPromise
|
|
68
|
+
#validationPromise: Promise<FLib.Validator.ValidationReturnType> | undefined | null;
|
|
67
69
|
|
|
68
70
|
|
|
69
71
|
#STATE_IDLE = 'idle';
|
|
70
72
|
#STATE_VALIDATING = 'validating';
|
|
71
73
|
|
|
72
74
|
|
|
73
|
-
constructor( $form: HTMLElement, userOptions:
|
|
75
|
+
constructor( $form: HTMLElement, userOptions: Partial<FLib.Validator.Options> = {} ) {
|
|
74
76
|
this.#$form = $form;
|
|
75
77
|
this.#options = extend( defaultOptions, userOptions );
|
|
76
78
|
this.#options.hasLiveValidation = !!this.#options.liveValidation?.onValidate || !!this.#options.liveValidation?.onInvalidate;
|
|
@@ -81,13 +83,14 @@ export default class Validator {
|
|
|
81
83
|
|
|
82
84
|
$form.setAttribute( 'novalidate', 'novalidate' );
|
|
83
85
|
|
|
84
|
-
this
|
|
86
|
+
this.#refresh();
|
|
85
87
|
}
|
|
86
88
|
|
|
89
|
+
|
|
87
90
|
/*
|
|
88
91
|
* Filter radio button to validate only one button
|
|
89
92
|
*/
|
|
90
|
-
|
|
93
|
+
#filterRadioButton = ( $input: HTMLInputElement ): boolean => {
|
|
91
94
|
if ( $input.type !== 'radio' ) {
|
|
92
95
|
return true;
|
|
93
96
|
}
|
|
@@ -105,7 +108,7 @@ export default class Validator {
|
|
|
105
108
|
/*
|
|
106
109
|
* Call the function cleanup of all inputs and empty the list
|
|
107
110
|
*/
|
|
108
|
-
|
|
111
|
+
#cleanup = (): void => {
|
|
109
112
|
this.#inputsList.forEach( input => input.destroy() );
|
|
110
113
|
this.#inputsList.length = 0;
|
|
111
114
|
this.#radioDuplicateHash = {};
|
|
@@ -115,9 +118,9 @@ export default class Validator {
|
|
|
115
118
|
/*
|
|
116
119
|
* Create and add one input to the list
|
|
117
120
|
*/
|
|
118
|
-
|
|
121
|
+
#addInput = ( $input: HTMLElement ): void => {
|
|
119
122
|
// Check if this input type
|
|
120
|
-
if ( !$input.matches( this.#options.filter
|
|
123
|
+
if ( !$input.matches( this.#options.filter ) && this.#filterRadioButton( $input as HTMLInputElement ) ) {
|
|
121
124
|
this.#inputsList.push( new Input( $input, this.#options ) );
|
|
122
125
|
}
|
|
123
126
|
}
|
|
@@ -126,20 +129,20 @@ export default class Validator {
|
|
|
126
129
|
/*
|
|
127
130
|
* Empty and clean the input list and recreate it
|
|
128
131
|
*/
|
|
129
|
-
|
|
130
|
-
this
|
|
132
|
+
#refresh = (): void => {
|
|
133
|
+
this.#cleanup();
|
|
131
134
|
|
|
132
|
-
const $fieldToAdd = this.#$form.querySelectorAll( this.#options.fields
|
|
135
|
+
const $fieldToAdd = this.#$form.querySelectorAll( this.#options.fields ) as NodeListOf<HTMLElement>;
|
|
133
136
|
|
|
134
|
-
$fieldToAdd.forEach( this
|
|
137
|
+
$fieldToAdd.forEach( this.#addInput.bind( this ) );
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
|
|
138
141
|
/*
|
|
139
142
|
* Validate all fields and return a promise
|
|
140
143
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
#_validate = (): Promise<void[]> => {
|
|
145
|
+
const inputsValid: Promise<void>[] = [];
|
|
143
146
|
|
|
144
147
|
this.#inputsList.forEach( input => {
|
|
145
148
|
inputsValid.push( input.isValid() );
|
|
@@ -149,7 +152,7 @@ export default class Validator {
|
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
|
|
152
|
-
|
|
155
|
+
#filterInputError = ( input: Input ): boolean => {
|
|
153
156
|
return input.hasError;
|
|
154
157
|
}
|
|
155
158
|
|
|
@@ -157,25 +160,25 @@ export default class Validator {
|
|
|
157
160
|
/*
|
|
158
161
|
* Call validation and call callback if needed
|
|
159
162
|
*/
|
|
160
|
-
|
|
163
|
+
#process = (): Promise<FLib.Validator.ValidationReturnType> => {
|
|
161
164
|
if ( this.#validationPromise ) {
|
|
162
165
|
return this.#validationPromise;
|
|
163
166
|
}
|
|
164
|
-
this.#validationPromise = new Promise<
|
|
167
|
+
this.#validationPromise = new Promise<FLib.Validator.ValidationReturnType>( ( resolve, reject ) => {
|
|
165
168
|
this.#state = this.#STATE_VALIDATING;
|
|
166
169
|
|
|
167
|
-
const retObject:
|
|
170
|
+
const retObject: FLib.Validator.ValidationReturnType = {
|
|
168
171
|
"inputs": this.#inputsList,
|
|
169
172
|
"errors": [],
|
|
170
173
|
"$form": this.#$form
|
|
171
174
|
};
|
|
172
175
|
|
|
173
|
-
this
|
|
176
|
+
this.#_validate()
|
|
174
177
|
.then( () => {
|
|
175
178
|
this.#validationPromise = null;
|
|
176
179
|
this.#state = this.#STATE_IDLE;
|
|
177
180
|
|
|
178
|
-
const errors = this.#inputsList.filter( this
|
|
181
|
+
const errors = this.#inputsList.filter( this.#filterInputError );
|
|
179
182
|
|
|
180
183
|
|
|
181
184
|
if ( errors && errors.length ) {
|
|
@@ -212,27 +215,27 @@ export default class Validator {
|
|
|
212
215
|
/**
|
|
213
216
|
* Start the validation of all the form
|
|
214
217
|
*/
|
|
215
|
-
validate(): Promise<
|
|
218
|
+
validate(): Promise<FLib.Validator.ValidationReturnType> {
|
|
216
219
|
if ( this.#state !== this.#STATE_IDLE ) {
|
|
217
|
-
return this.#validationPromise as Promise<
|
|
220
|
+
return this.#validationPromise as Promise<FLib.Validator.ValidationReturnType>;
|
|
218
221
|
}
|
|
219
222
|
|
|
220
|
-
return this
|
|
223
|
+
return this.#process();
|
|
221
224
|
}
|
|
222
225
|
|
|
223
226
|
|
|
224
227
|
/**
|
|
225
228
|
* Bind or rebind all inputs
|
|
226
229
|
*/
|
|
227
|
-
update() {
|
|
228
|
-
this
|
|
230
|
+
update(): this {
|
|
231
|
+
this.#refresh();
|
|
232
|
+
|
|
233
|
+
return this
|
|
229
234
|
}
|
|
230
235
|
|
|
231
236
|
|
|
232
237
|
/**
|
|
233
238
|
* Return the validator object of an input
|
|
234
|
-
*
|
|
235
|
-
* @param $field
|
|
236
239
|
*/
|
|
237
240
|
getFieldValidator( $field: HTMLElement ): Input | void {
|
|
238
241
|
|
|
@@ -241,17 +244,14 @@ export default class Validator {
|
|
|
241
244
|
return input;
|
|
242
245
|
}
|
|
243
246
|
}
|
|
244
|
-
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
|
|
248
250
|
/**
|
|
249
251
|
* Validate one field
|
|
250
|
-
*
|
|
251
|
-
* @param $field
|
|
252
252
|
*/
|
|
253
|
-
validateField( $field: HTMLElement ): Promise<
|
|
254
|
-
return new Promise<
|
|
253
|
+
validateField( $field: HTMLElement ): Promise<FLib.Validator.FieldValidationReturnType | void> {
|
|
254
|
+
return new Promise<FLib.Validator.FieldValidationReturnType | void>( ( resolve, reject ) => {
|
|
255
255
|
const input = this.getFieldValidator( $field );
|
|
256
256
|
|
|
257
257
|
if ( !input ) {
|
|
@@ -260,7 +260,7 @@ export default class Validator {
|
|
|
260
260
|
|
|
261
261
|
this.#state = this.#STATE_VALIDATING;
|
|
262
262
|
|
|
263
|
-
const retObject:
|
|
263
|
+
const retObject: FLib.Validator.FieldValidationReturnType = {
|
|
264
264
|
"input": input,
|
|
265
265
|
"error": null,
|
|
266
266
|
"$form": this.#$form
|
|
@@ -293,7 +293,7 @@ export default class Validator {
|
|
|
293
293
|
* @param onlyValidated - If true, remove all fields without validator
|
|
294
294
|
*/
|
|
295
295
|
getAllFields( onlyValidated: boolean ): HTMLElement[] {
|
|
296
|
-
|
|
296
|
+
const $fields: HTMLElement[] = [];
|
|
297
297
|
|
|
298
298
|
this.#inputsList.forEach( input => {
|
|
299
299
|
if ( !onlyValidated || input.hasValidator ) {
|
|
@@ -325,7 +325,7 @@ export default class Validator {
|
|
|
325
325
|
* Get all inputs (input objects, not DOM elements) with at least one validator
|
|
326
326
|
*/
|
|
327
327
|
getCheckedInputs(): Input[] {
|
|
328
|
-
|
|
328
|
+
const inputs: Input[] = [];
|
|
329
329
|
|
|
330
330
|
this.#inputsList.forEach( input => {
|
|
331
331
|
if ( input.hasValidator ) {
|
package/Modules/YouTubePlayer.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { extend } from '../Helpers/Extend';
|
|
|
4
4
|
let ytAPILoadingPromise;
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
const defaultOptions = {
|
|
7
|
+
const defaultOptions: Partial<FLib.YouTubePlayer.Options> = {
|
|
8
8
|
"apiUrl": "//www.youtube.com/iframe_api",
|
|
9
9
|
"playerVars": {
|
|
10
10
|
"autoplay": 0,
|
|
@@ -22,13 +22,14 @@ const defaultOptions = {
|
|
|
22
22
|
* @see extra/modules/youtube.md
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
|
+
* ```ts
|
|
25
26
|
* let YouTubePlayer = new YouTubePlayer( {
|
|
26
27
|
* "height": 1920,
|
|
27
28
|
* "width": 1080,
|
|
28
29
|
* "videoId": "youtube-video-id-here",
|
|
29
30
|
* "$wrapper": $wrapper,
|
|
30
31
|
* "apiUrl": "//www.youtube.com/iframe_api",
|
|
31
|
-
* "onPlayerStateChange": ( newState )
|
|
32
|
+
* "onPlayerStateChange": ( newState ) => {
|
|
32
33
|
* if ( newState.data === YT.PlayerState.ENDED ) {
|
|
33
34
|
* // Code here for video ended
|
|
34
35
|
* }
|
|
@@ -44,14 +45,15 @@ const defaultOptions = {
|
|
|
44
45
|
* }
|
|
45
46
|
* );
|
|
46
47
|
*
|
|
47
|
-
* YouTubePlayer.load().then( ytPlayerInstance
|
|
48
|
+
* YouTubePlayer.load().then( ytPlayerInstance => {} );
|
|
49
|
+
* ```
|
|
48
50
|
*/
|
|
49
51
|
export default class YouTubePlayer {
|
|
50
52
|
|
|
51
|
-
#options:
|
|
53
|
+
#options: FLib.YouTubePlayer.Options;
|
|
52
54
|
|
|
53
55
|
|
|
54
|
-
constructor( userOptions:
|
|
56
|
+
constructor( userOptions: Partial<FLib.YouTubePlayer.Options> ) {
|
|
55
57
|
this.#options = extend( defaultOptions, userOptions );
|
|
56
58
|
|
|
57
59
|
if ( !this.#options.$wrapper ) {
|
|
@@ -60,8 +62,8 @@ export default class YouTubePlayer {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
let
|
|
65
|
+
#loadYouTubeAPI = (): Promise<void> => {
|
|
66
|
+
let _resolve;
|
|
65
67
|
|
|
66
68
|
if ( ytAPILoadingPromise ) {
|
|
67
69
|
return ytAPILoadingPromise;
|
|
@@ -75,23 +77,23 @@ export default class YouTubePlayer {
|
|
|
75
77
|
_resolve = resolve;
|
|
76
78
|
} );
|
|
77
79
|
|
|
78
|
-
(window as
|
|
80
|
+
(window as FLib.YouTubePlayer.PlayerWindow).onYouTubeIframeAPIReady = function() {
|
|
79
81
|
_resolve();
|
|
80
82
|
|
|
81
|
-
(window as
|
|
83
|
+
(window as FLib.YouTubePlayer.PlayerWindow).onYouTubeIframeAPIReady = null;
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
tag = document.createElement( 'script' );
|
|
85
|
-
tag.src
|
|
86
|
-
firstScriptTag = document.getElementsByTagName( 'script' )[ 0 ];
|
|
86
|
+
const tag = document.createElement( 'script' );
|
|
87
|
+
tag.src = this.#options.apiUrl;
|
|
88
|
+
const firstScriptTag = document.getElementsByTagName( 'script' )[ 0 ] as HTMLScriptElement;
|
|
87
89
|
|
|
88
|
-
firstScriptTag.parentNode
|
|
90
|
+
firstScriptTag.parentNode?.insertBefore( tag, firstScriptTag );
|
|
89
91
|
|
|
90
92
|
return ytAPILoadingPromise;
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
|
|
94
|
-
|
|
96
|
+
#initPlayer = ( $wrapper: FLib.YouTubePlayer.PlayerWrapper ): Promise<YT.Player> => {
|
|
95
97
|
let _resolve;
|
|
96
98
|
|
|
97
99
|
const promise = new Promise( function( resolve ) {
|
|
@@ -126,8 +128,8 @@ export default class YouTubePlayer {
|
|
|
126
128
|
* @returns
|
|
127
129
|
*/
|
|
128
130
|
load(): Promise<YT.Player> {
|
|
129
|
-
return this
|
|
130
|
-
return this
|
|
131
|
+
return this.#loadYouTubeAPI().then( () => {
|
|
132
|
+
return this.#initPlayer( this.#options.$wrapper as FLib.YouTubePlayer.PlayerWrapper );
|
|
131
133
|
} );
|
|
132
134
|
}
|
|
133
135
|
}
|
package/README.md
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
namespace FLib {
|
|
2
|
+
namespace Accordion {
|
|
3
|
+
|
|
4
|
+
type AnimationFunction = ( $tab: HTMLElement, $panel: HTMLElement ) => Promise<void>;
|
|
5
|
+
type Callback = ( $tab: HTMLElement, $panel: HTMLElement ) => void;
|
|
6
|
+
type CloseCallback = ( $tab: HTMLElement, $panel: HTMLElement, autoclose: boolean ) => void;
|
|
7
|
+
|
|
8
|
+
interface AnimationOptions {
|
|
9
|
+
open: AnimationFunction;
|
|
10
|
+
close: AnimationFunction;
|
|
11
|
+
destroy: AnimationFunction;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Options {
|
|
15
|
+
/** @defaultValue 'button[aria-expanded]' */
|
|
16
|
+
tabSelector: string;
|
|
17
|
+
/** @defaultValue false */
|
|
18
|
+
allowMultipleTab: boolean;
|
|
19
|
+
/** @defaultValue false */
|
|
20
|
+
atLeastOneOpen: boolean;
|
|
21
|
+
onOpenAtStart: Callback;
|
|
22
|
+
onOpen: Callback;
|
|
23
|
+
onClose: CloseCallback;
|
|
24
|
+
animations: AnimationOptions;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface OptionsInit extends Partial<Options> {
|
|
28
|
+
animations?: Partial<AnimationOptions>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface TabOptions extends Options {
|
|
32
|
+
onOpenTab: (( tab: Tab ) => void) | null;
|
|
33
|
+
index: number;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|