@creative-web-solution/front-library 6.2.7 → 6.2.8

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+
4
+ ## 6.2.8
5
+
6
+ * Transition and animation end: Handle properties filter and pseudo elements
7
+
8
+
3
9
  ## 6.2.7
4
10
 
5
11
  * Custom Events: Add target element as param of the callback function on delegated event
@@ -1,32 +1,12 @@
1
- import { defer } from '@creative-web-solution/front-library/Helpers/defer';
2
-
3
- const animationendEventName = ( function() {
4
- let el, animation;
5
-
6
- el = document.createElement( 'fakeelement' );
7
-
8
- animation = {
9
- "animation": "animationend",
10
- "OAnimation": "oAnimationEnd",
11
- "MozAnimation": "animationend",
12
- "WebkitAnimation": "webkitAnimationEnd"
13
- };
14
-
15
- for ( let t in animation ) {
16
- if ( el.style[ t ] !== undefined ) {
17
- return animation[ t ];
18
- }
19
- }
20
- } )();
1
+ import { animationendEventName } from '../Tools/PrefixedProperties';
21
2
 
22
3
 
23
4
  /**
24
5
  * Bind a one time animationend event on a DOM object
25
- * @function onAnimationEnd
26
6
  *
27
- * @param {HTMLElement} $elem
28
- *
29
- * @example onAnimationEnd( $elem ).then( () => {} );
7
+ * @example
8
+ * ```js
9
+ * onAnimationEnd( $elem ).then( () => {} );
30
10
  *
31
11
  * // To remove the event binding, don't chain .then() directly after onAnimationEnd:
32
12
  * let animationEnd = onAnimationEnd( $element );
@@ -34,28 +14,52 @@ const animationendEventName = ( function() {
34
14
  *
35
15
  * animationEnd.off()
36
16
  *
37
- * @returns {Promise} - Return a standard Promise + an .off() function to cancel event
17
+ * // To watch for a animation end:
18
+ * onAnimationEnd( $elem, {
19
+ * "animationName": [ "name-of-my-css-animation" ]
20
+ * } )
21
+ *
22
+ * // To watch a animation end on a pseudo element like "::after":
23
+ * onAnimationEnd( $elem, {
24
+ * "pseudoElement": "after"
25
+ * } )
26
+ * ```
27
+ *
28
+ * @returns Return a standard Promise + an .off() function to cancel event
38
29
  */
39
- export function onAnimationEnd( $elem ) {
40
- let deferred = defer();
30
+ export default function onAnimationEnd( $element, options = {} ) {
31
+ let _resolve;
32
+
33
+ const promise = new Promise( function( resolve ) {
34
+ _resolve = resolve;
35
+ } );
36
+
41
37
 
42
38
  function remove() {
43
- $elem.removeEventListener( animationendEventName, onAnimationEnd );
39
+ $element.removeEventListener( animationendEventName, onAnimationEnd );
44
40
  }
45
41
 
46
42
  function onAnimationEnd( e ) {
47
- if ( e.target !== $elem ) {
43
+ if (
44
+ e.target !== $element ||
45
+ ( options.animationName && !options.animationName.includes( e.animationName ) ) ||
46
+ ( options.pseudoElement === 'after' && e.pseudoElement !== '::after' ) ||
47
+ ( options.pseudoElement === 'before' && e.pseudoElement !== '::before' ) ||
48
+ ( options.pseudoElement === 'both' && !e.pseudoElement ) ||
49
+ ( !options.pseudoElement && e.pseudoElement !== '' )
50
+ ) {
48
51
  return;
49
52
  }
50
53
 
51
54
  remove();
52
55
 
53
- deferred.resolve();
56
+ _resolve( [ e, $element ] );
54
57
  }
55
58
 
56
- $elem.addEventListener( animationendEventName, onAnimationEnd, false );
57
59
 
58
- deferred.off = remove;
60
+ $element.addEventListener( animationendEventName, onAnimationEnd, false );
61
+
62
+ promise.off = remove;
59
63
 
60
- return deferred;
64
+ return promise;
61
65
  }
@@ -1,41 +1,40 @@
1
- import { defer } from '@creative-web-solution/front-library/Helpers/defer';
2
-
3
-
4
- const transitionendEventName = ( function() {
5
- let el = document.createElement( 'fakeelement' );
6
- let transitions = {
7
- "transition": "transitionend",
8
- "OTransition": "oTransitionEnd",
9
- "MozTransition": "transitionend",
10
- "WebkitTransition": "webkitTransitionEnd"
11
- };
12
-
13
- for ( let t in transitions ) {
14
- if ( typeof el.style[ t ] !== 'undefined' ) {
15
- return transitions[ t ];
16
- }
17
- }
18
- } )();
1
+ import { transitionendEventName } from '../Tools/PrefixedProperties';
19
2
 
20
3
 
21
4
  /**
22
5
  * Bind a one time transitionend event on a DOM object
23
- * @function onTransitionEnd
24
- *
25
- * @param {HTMLElement} $element
26
6
  *
27
- * @example onTransitionEnd( $elem ).then( () => {} );
7
+ * @example
8
+ * onTransitionEnd( $elem ).then( () => `{}` );
28
9
  *
10
+ * @example
11
+ * ```js
29
12
  * // To remove the event binding, don't chain .then() directly after onTransitionEnd:
30
13
  * let transitionEnd = onTransitionEnd( $element );
31
14
  * transitionEnd.then( () => {} );
32
15
  *
33
16
  * transitionEnd.off()
34
17
  *
35
- * @returns {Promise} - Return a standard Promise + an .off() function to cancel event
18
+ * // To watch for a specific CSS property transition end:
19
+ * onTransitionEnd( $elem, {
20
+ * "property": "opacity"
21
+ * } )
22
+ *
23
+ * // To watch a transition end on a pseudo element like "::after":
24
+ * onTransitionEnd( $elem, {
25
+ * "pseudoElement": "after"
26
+ * } )
27
+ * ```
28
+ *
29
+ * @returns Return a standard Promise + an .off() function to cancel event
36
30
  */
37
- export function onTransitionEnd( $element ) {
38
- let deferred = defer();
31
+ export default function onTransitionEnd( $element, options = {} ) {
32
+ let _resolve;
33
+
34
+ const promise = new Promise( function( resolve ) {
35
+ _resolve = resolve;
36
+ } );
37
+
39
38
 
40
39
  function remove() {
41
40
  $element.removeEventListener(
@@ -44,23 +43,33 @@ export function onTransitionEnd( $element ) {
44
43
  );
45
44
  }
46
45
 
46
+
47
47
  function onTransitionEnd( e ) {
48
- if ( e.target !== $element ) {
48
+ if (
49
+ e.target !== $element ||
50
+ ( options.property && !options.property.includes( e.propertyName ) ) ||
51
+ ( options.pseudoElement === 'after' && e.pseudoElement !== '::after' ) ||
52
+ ( options.pseudoElement === 'before' && e.pseudoElement !== '::before' ) ||
53
+ ( options.pseudoElement === 'both' && !e.pseudoElement ) ||
54
+ ( !options.pseudoElement && e.pseudoElement !== '' )
55
+ ) {
49
56
  return;
50
57
  }
51
58
 
52
59
  remove();
53
60
 
54
- deferred.resolve();
61
+ _resolve( [ e, $element ] );
55
62
  }
56
63
 
64
+
57
65
  $element.addEventListener(
58
66
  transitionendEventName,
59
67
  onTransitionEnd,
60
68
  false
61
69
  );
62
70
 
63
- deferred.off = remove;
64
71
 
65
- return deferred;
72
+ promise.off = remove;
73
+
74
+ return promise;
66
75
  }
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 6.2.7
3
+ @version: 6.2.8
4
4
 
5
5
 
6
6
  ## Use
@@ -0,0 +1,54 @@
1
+
2
+
3
+ function testPrefix( list, element = 'div' ) {
4
+
5
+ const $ELEMENT = document.createElement( element );
6
+
7
+ for ( const key of Object.keys( list ) ) {
8
+ if ( key in $ELEMENT.style ) {
9
+ return list[ key ];
10
+ }
11
+ }
12
+
13
+ return '';
14
+ }
15
+
16
+
17
+ export const animationendEventName = ( function() {
18
+ return testPrefix( {
19
+ "animation": "animationend",
20
+ "OAnimation": "oAnimationEnd",
21
+ "MozAnimation": "animationend",
22
+ "WebkitAnimation": "webkitAnimationEnd"
23
+ } );
24
+ } )();
25
+
26
+
27
+ export const transitionendEventName = ( function() {
28
+ return testPrefix( {
29
+ "transition": "transitionend",
30
+ "OTransition": "oTransitionEnd",
31
+ "MozTransition": "transitionend",
32
+ "WebkitTransition": "webkitTransitionEnd"
33
+ } );
34
+ } )();
35
+
36
+
37
+ export const transformPropertyName = ( function() {
38
+ return testPrefix( {
39
+ "transform": "transform",
40
+ "WebkitTransform": "WebkitTransform",
41
+ "OTransform": "OTransform",
42
+ "MozTransform": "MozTransform"
43
+ } );
44
+ } )();
45
+
46
+
47
+ export const transitionPropertyName = ( function() {
48
+ return testPrefix( {
49
+ "transition": "transition",
50
+ "WebkitTransition": "WebkitTransition",
51
+ "OTransition": "OTransition",
52
+ "MozTransition": "MozTransition"
53
+ } );
54
+ } )();
@@ -0,0 +1 @@
1
+ export const isTouchDevice = window.matchMedia( '(hover: none)' ).matches;
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.7",
5
+ "version": "6.2.8",
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": [],