From 3624f8b979c3d2d0b7f7ed73dd5a7104af2c26fb Mon Sep 17 00:00:00 2001
From: IguhSoares Keeps track of the EventListeners associated to a trigger selector Removes the event listener of all elements represented by the A valid CSS selector for the trigger Element. If ommited, '.${CLASS_NAMES.trigger}' will be used instead. The event name. If ommited, 'click' is the default value.Source: animate.js
CUSTOM_CSS_PROPERTIES,
} from './globals.js';
-import { initParentResize, endParentResize } from './resize-parent.js';
+import {
+ initParentResize,
+ endParentResize,
+ setOverflowHidden,
+ removeOverflowHidden,
+} from './resize-parent.js';
import {
removeInlineTransition,
@@ -60,7 +65,7 @@ Source: animate.js
staggerDelay: undefined,
start: undefined,
complete: undefined,
- keepSpace: false,
+ maintainSpace: false,
dimensionsTransition: true,
widthTransition: undefined,
heightTransition: undefined,
@@ -175,6 +180,12 @@ Source: animate.js
stack: {},
};
+/**
+ * Keeps track of the EventListeners associated to a trigger selector
+ * @type {{[x: String]: EventListener[]}}
+ */
+const LISTENERS = {};
+
/**
* Removes the CSS properties customized by the user
* @param {HTMLElement} element - The DOM element with the custom CSS properties
@@ -354,10 +365,12 @@ Source: animate.js
* @returns True if the element has an iteration CSS property set, False otherwise
*/
const hasIterationProp = element => {
+ const iterationProperty = element.style.getPropertyValue(
+ PROPERTY_NAMES.iteration
+ );
return (
- element.style
- .getPropertyValue(PROPERTY_NAMES.iteration)
- .match(/^(infinite|\d+)$/) !== null
+ iterationProperty != '1' &&
+ iterationProperty.match(/^(infinite|\d+)$/) !== null
);
};
@@ -371,17 +384,14 @@ Source: animate.js
* element: HTMLElement,
* parentMeasures: Object,
* action: string,
- * dimension: string | undefined,
- * keepSpace: boolean
+ * dimension: string | undefined
* }} args - All the necessary arguments
*/
const handleVisibilityToggle = (element, args) => {
setTimeout(() => {
if (args.dimension) setParentMaxMeasures(args);
if (args.action === 'show') {
- args.keepSpace
- ? element.classList.remove(CLASS_NAMES.hidden)
- : element.classList.remove(CLASS_NAMES.collapsed);
+ element.classList.remove(CLASS_NAMES.hidden, CLASS_NAMES.collapsed);
}
}, 0);
};
@@ -394,12 +404,14 @@ Source: animate.js
*/
const endVisibilityToggle = (element, opts) => {
if (opts.action === 'hide') {
- opts.keepSpace
+ opts.maintainSpace
? element.classList.add(CLASS_NAMES.hidden)
: element.classList.add(CLASS_NAMES.collapsed);
}
if (opts.heightTransition || opts.widthTransition)
endParentResize(element, opts);
+ else if (opts.overflowHidden && element.parentElement)
+ removeOverflowHidden(element.parentElement);
};
/**
@@ -442,8 +454,8 @@ Source: animate.js
trigger,
start = CONFIG.start,
complete = CONFIG.complete,
- keepSpace = CONFIG.keepSpace,
- dimensionsTransition = keepSpace || isMotion(animType)
+ maintainSpace = CONFIG.maintainSpace,
+ dimensionsTransition = maintainSpace || isMotion(animType)
? false
: CONFIG.dimensionsTransition,
widthTransition = CONFIG.widthTransition ?? dimensionsTransition,
@@ -472,7 +484,8 @@ Source: animate.js
heightTransition,
overflowHidden,
}));
- }
+ } else if (overflowHidden && element.parentElement)
+ setOverflowHidden(element.parentElement);
},
motion: () => {
currentTransition = getCurrentTransition(element);
@@ -487,7 +500,6 @@ Source: animate.js
parentMeasures,
action,
dimension,
- keepSpace,
});
},
motion: () => {
@@ -501,9 +513,10 @@ Source: animate.js
visibility: () => {
endVisibilityToggle(element, {
action,
- keepSpace,
+ maintainSpace,
widthTransition,
heightTransition,
+ overflowHidden,
});
if (!hasIterationProp(element))
element.classList.remove(CLASS_NAMES[action][id]);
@@ -595,7 +608,7 @@ Source: animate.js
* @param {HTMLElement} el - The DOM element being animated
* @param {number} animationId - The ID of the animation in the *_ANIMS_ID
* @param {Object} opts - The options passed by the user
- * @returns A function to be passed to the addEventListener() as a handler
+ * @returns {EventListener} A function to be passed to the addEventListener() as a handler
* @see {@link module:globals.VISIBILITY_ANIMS_ID}
* @see {@link module:globals.MOTION_ANIMS_ID}
*/
@@ -647,24 +660,48 @@ Source: animate.js
btn.setAttribute('target-selector', targetSelector);
}
+ if (!opts.trigger) opts.trigger = trigger;
+ LISTENERS[trigger] = [];
document
.querySelectorAll(getTargetSelector(btn))
.forEach((el, i, queryList) => {
- btn.addEventListener(
- eventType,
- // @ts-ignore
- eventHandler(el, animationId, {
- ...opts,
- totalTargets: queryList.length,
- queryIndex: i,
- })
- );
+ // @ts-ignore
+ const listener = eventHandler(el, animationId, {
+ ...opts,
+ totalTargets: queryList.length,
+ queryIndex: i,
+ });
+
+ LISTENERS[trigger].push(listener);
+ btn.addEventListener(eventType, listener);
});
});
};
+/**
+ * Removes the event listener of all elements represented by the `triggerSelector`
+ * @param {String|null} triggerSelector - A valid CSS selector for the trigger Element. If ommited, '.${CLASS_NAMES.trigger}' will be used instead.
+ * @param {String} eventType - The event name. If ommited, 'click' is the default value.
+ */
+const end = (triggerSelector = null, eventType = 'click') => {
+ const triggerList =
+ typeof triggerSelector === 'string'
+ ? document.querySelectorAll(triggerSelector)
+ : document.querySelectorAll(`.${CLASS_NAMES.trigger}`);
+
+ triggerList.forEach(trigger => {
+ LISTENERS[triggerSelector ?? `.${CLASS_NAMES.trigger}`].forEach(
+ listener => {
+ trigger.removeEventListener(eventType, listener);
+ }
+ );
+ });
+ delete LISTENERS[triggerSelector ?? `.${CLASS_NAMES.trigger}`];
+};
+
export {
init,
+ end,
animate,
preset,
isEnabled,
@@ -688,7 +725,7 @@ JS-CSS Animations
Modules
diff --git a/jsdoc/doc/globals.js.html b/jsdoc/doc/globals.js.html
index 1986313..cfc6d7f 100644
--- a/jsdoc/doc/globals.js.html
+++ b/jsdoc/doc/globals.js.html
@@ -81,7 +81,7 @@ Source: globals.js
*/
export const PROPERTY_NAMES = Object.freeze({
duration: '--js-css-animation--duration',
- timingFunction: '--js-css-animation--timing-function',
+ easing: '--js-css-animation--timing-function',
delay: '--js-css-animation--delay',
fillMode: '--js-css-animation--fill-mode',
cursor: '--js-css-animation--cursor',
@@ -193,7 +193,7 @@ JS-CSS Animations
Modules
diff --git a/jsdoc/doc/index.html b/jsdoc/doc/index.html
index aee39ac..7ba74a2 100644
--- a/jsdoc/doc/index.html
+++ b/jsdoc/doc/index.html
@@ -56,7 +56,7 @@ JS-CSS Animations
Modules
diff --git a/jsdoc/doc/js-css-animations.js.html b/jsdoc/doc/js-css-animations.js.html
index 63c445d..f28039f 100644
--- a/jsdoc/doc/js-css-animations.js.html
+++ b/jsdoc/doc/js-css-animations.js.html
@@ -32,6 +32,7 @@ Source: js-css-animations.js
*/
import {
init,
+ end,
animate,
preset,
isEnabled,
@@ -126,11 +127,11 @@ Source: js-css-animations.js
* duration: number|string|undefined,
* delay: number|string|undefined,
* staggerDelay: number|string|undefined,
- * timingFunction: string|undefined,
+ * easing: string|undefined,
* blur: string|undefined,
* angle: string|undefined,
* iteration: string|undefined,
- * keepSpace: boolean|undefined,
+ * maintainSpace: boolean|undefined,
* overflowHidden: boolean|undefined,
* dimensionsTransition: boolean|undefined,
* widthTransition: boolean|undefined,
@@ -143,13 +144,13 @@ Source: js-css-animations.js
'duration',
'delay',
'staggerDelay',
- 'timingFunction',
+ 'easing',
'blur',
'angle',
'iteration',
'direction',
'transfOrigin',
- 'keepSpace',
+ 'maintainSpace',
'overflowHidden',
'dimensionsTransition',
'widthTransition',
@@ -209,7 +210,7 @@ Source: js-css-animations.js
[
'start',
'complete',
- 'keepSpace',
+ 'maintainSpace',
'overflowHidden',
'staggerDelay',
'widthTransition',
@@ -365,6 +366,7 @@ Source: js-css-animations.js
const animationsHandler = Object.freeze({
config,
reset,
+ end,
init: eventAnimations,
...animationFunctions,
show: showVisibilityAnim,
@@ -403,7 +405,7 @@ JS-CSS Animations
Modules
diff --git a/jsdoc/doc/measurements.js.html b/jsdoc/doc/measurements.js.html
index 99b7a79..9ae037c 100644
--- a/jsdoc/doc/measurements.js.html
+++ b/jsdoc/doc/measurements.js.html
@@ -273,7 +273,7 @@ JS-CSS Animations
Modules
diff --git a/jsdoc/doc/module-animate.html b/jsdoc/doc/module-animate.html
index e0741b3..9d4e6e7 100644
--- a/jsdoc/doc/module-animate.html
+++ b/jsdoc/doc/module-animate.html
@@ -146,7 +146,7 @@ (s
(static, cons
Type:
Type:
(inner, const
(inner, constant) LISTENERS
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Type:
(inner, consta
Type:
(inner) trigg
Parameters:
Parameters:
Parameters:
(inner) end(triggerSelector, eventType)
+
+
+
+
+
+
+triggerSelector
Parameters:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+ Default
+
+
+ Description
+
+
+
+
+
+
+
+
+
+ triggerSelector
+
+
+String
+|
+
+null
+
+
+
+
+
+
+
+
+
+
+ null
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ eventType
+
+
+String
+
+
+
+
+
+
+
+
+
+
+ click
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Parameters:
Parameters:
- (inner) eventHandler(el, animationId, opts)
+ (inner) eventHandler(el, animationId, opts) → {EventListener}
@@ -1541,7 +1780,7 @@ Parameters:
Returns:
+
+
+
@@ -1720,7 +1971,7 @@ Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
(inner) <
Parameters:
Parameters:
JS-CSS Animations
Modules
diff --git a/jsdoc/doc/module-globals.html b/jsdoc/doc/module-globals.html
index 27ded93..bb81f70 100644
--- a/jsdoc/doc/module-globals.html
+++ b/jsdoc/doc/module-globals.html
@@ -508,7 +508,7 @@ JS-CSS Animations
Modules
diff --git a/jsdoc/doc/module-js-css-animations.html b/jsdoc/doc/module-js-css-animations.html
index e4916b7..92f634e 100644
--- a/jsdoc/doc/module-js-css-animations.html
+++ b/jsdoc/doc/module-js-css-animations.html
@@ -159,7 +159,7 @@ Type:
Type:
Type:
Type:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
(inner) reset
Parameters:
Parameters:
Parameters:
JS-CSS Animations
Modules
diff --git a/jsdoc/doc/module-measurements.html b/jsdoc/doc/module-measurements.html
index 3f179c7..484f933 100644
--- a/jsdoc/doc/module-measurements.html
+++ b/jsdoc/doc/module-measurements.html
@@ -2121,7 +2121,7 @@ JS-CSS Animations
Modules
diff --git a/jsdoc/doc/module-resize-parent.html b/jsdoc/doc/module-resize-parent.html
index 2568cca..1f6cc2c 100644
--- a/jsdoc/doc/module-resize-parent.html
+++ b/jsdoc/doc/module-resize-parent.html
@@ -1162,7 +1162,7 @@ JS-CSS Animations
Modules
diff --git a/jsdoc/doc/module-transitions.html b/jsdoc/doc/module-transitions.html
index 5f1b3b6..05de0d6 100644
--- a/jsdoc/doc/module-transitions.html
+++ b/jsdoc/doc/module-transitions.html
@@ -864,7 +864,7 @@ JS-CSS Animations
Modules
diff --git a/jsdoc/doc/resize-parent.js.html b/jsdoc/doc/resize-parent.js.html
index 76234a5..7b07a6d 100644
--- a/jsdoc/doc/resize-parent.js.html
+++ b/jsdoc/doc/resize-parent.js.html
@@ -155,7 +155,12 @@ Source: resize-parent.js
removeOverflowHidden(parentElement);
};
-export { initParentResize, endParentResize };
+export {
+ initParentResize,
+ endParentResize,
+ setOverflowHidden,
+ removeOverflowHidden,
+};
@@ -172,7 +177,7 @@ JS-CSS Animations
Modules