@@ -37,7 +37,12 @@ <h1 class="page-title">Source: animate.js</h1>
3737 CUSTOM_CSS_PROPERTIES,
3838} from './globals.js';
3939
40- import { initParentResize, endParentResize } from './resize-parent.js';
40+ import {
41+ initParentResize,
42+ endParentResize,
43+ setOverflowHidden,
44+ removeOverflowHidden,
45+ } from './resize-parent.js';
4146
4247import {
4348 removeInlineTransition,
@@ -60,7 +65,7 @@ <h1 class="page-title">Source: animate.js</h1>
6065 staggerDelay: undefined,
6166 start: undefined,
6267 complete: undefined,
63- keepSpace : false,
68+ maintainSpace : false,
6469 dimensionsTransition: true,
6570 widthTransition: undefined,
6671 heightTransition: undefined,
@@ -175,6 +180,12 @@ <h1 class="page-title">Source: animate.js</h1>
175180 stack: {},
176181};
177182
183+ /**
184+ * Keeps track of the EventListeners associated to a trigger selector
185+ * @type {{[x: String]: EventListener[]}}
186+ */
187+ const LISTENERS = {};
188+
178189/**
179190 * Removes the CSS properties customized by the user
180191 * @param {HTMLElement} element - The DOM element with the custom CSS properties
@@ -354,10 +365,12 @@ <h1 class="page-title">Source: animate.js</h1>
354365 * @returns True if the element has an iteration CSS property set, False otherwise
355366 */
356367const hasIterationProp = element => {
368+ const iterationProperty = element.style.getPropertyValue(
369+ PROPERTY_NAMES.iteration
370+ );
357371 return (
358- element.style
359- .getPropertyValue(PROPERTY_NAMES.iteration)
360- .match(/^(infinite|\d+)$/) !== null
372+ iterationProperty != '1' &&
373+ iterationProperty.match(/^(infinite|\d+)$/) !== null
361374 );
362375};
363376
@@ -371,17 +384,14 @@ <h1 class="page-title">Source: animate.js</h1>
371384 * element: HTMLElement,
372385 * parentMeasures: Object,
373386 * action: string,
374- * dimension: string | undefined,
375- * keepSpace: boolean
387+ * dimension: string | undefined
376388 * }} args - All the necessary arguments
377389 */
378390const handleVisibilityToggle = (element, args) => {
379391 setTimeout(() => {
380392 if (args.dimension) setParentMaxMeasures(args);
381393 if (args.action === 'show') {
382- args.keepSpace
383- ? element.classList.remove(CLASS_NAMES.hidden)
384- : element.classList.remove(CLASS_NAMES.collapsed);
394+ element.classList.remove(CLASS_NAMES.hidden, CLASS_NAMES.collapsed);
385395 }
386396 }, 0);
387397};
@@ -394,12 +404,14 @@ <h1 class="page-title">Source: animate.js</h1>
394404 */
395405const endVisibilityToggle = (element, opts) => {
396406 if (opts.action === 'hide') {
397- opts.keepSpace
407+ opts.maintainSpace
398408 ? element.classList.add(CLASS_NAMES.hidden)
399409 : element.classList.add(CLASS_NAMES.collapsed);
400410 }
401411 if (opts.heightTransition || opts.widthTransition)
402412 endParentResize(element, opts);
413+ else if (opts.overflowHidden && element.parentElement)
414+ removeOverflowHidden(element.parentElement);
403415};
404416
405417/**
@@ -442,8 +454,8 @@ <h1 class="page-title">Source: animate.js</h1>
442454 trigger,
443455 start = CONFIG.start,
444456 complete = CONFIG.complete,
445- keepSpace = CONFIG.keepSpace ,
446- dimensionsTransition = keepSpace || isMotion(animType)
457+ maintainSpace = CONFIG.maintainSpace ,
458+ dimensionsTransition = maintainSpace || isMotion(animType)
447459 ? false
448460 : CONFIG.dimensionsTransition,
449461 widthTransition = CONFIG.widthTransition ?? dimensionsTransition,
@@ -472,7 +484,8 @@ <h1 class="page-title">Source: animate.js</h1>
472484 heightTransition,
473485 overflowHidden,
474486 }));
475- }
487+ } else if (overflowHidden && element.parentElement)
488+ setOverflowHidden(element.parentElement);
476489 },
477490 motion: () => {
478491 currentTransition = getCurrentTransition(element);
@@ -487,7 +500,6 @@ <h1 class="page-title">Source: animate.js</h1>
487500 parentMeasures,
488501 action,
489502 dimension,
490- keepSpace,
491503 });
492504 },
493505 motion: () => {
@@ -501,9 +513,10 @@ <h1 class="page-title">Source: animate.js</h1>
501513 visibility: () => {
502514 endVisibilityToggle(element, {
503515 action,
504- keepSpace ,
516+ maintainSpace ,
505517 widthTransition,
506518 heightTransition,
519+ overflowHidden,
507520 });
508521 if (!hasIterationProp(element))
509522 element.classList.remove(CLASS_NAMES[action][id]);
@@ -595,7 +608,7 @@ <h1 class="page-title">Source: animate.js</h1>
595608 * @param {HTMLElement} el - The DOM element being animated
596609 * @param {number} animationId - The ID of the animation in the *_ANIMS_ID
597610 * @param {Object} opts - The options passed by the user
598- * @returns A function to be passed to the addEventListener() as a handler
611+ * @returns {EventListener} A function to be passed to the addEventListener() as a handler
599612 * @see {@link module:globals.VISIBILITY_ANIMS_ID}
600613 * @see {@link module:globals.MOTION_ANIMS_ID}
601614 */
@@ -647,24 +660,48 @@ <h1 class="page-title">Source: animate.js</h1>
647660 btn.setAttribute('target-selector', targetSelector);
648661 }
649662
663+ if (!opts.trigger) opts.trigger = trigger;
664+ LISTENERS[trigger] = [];
650665 document
651666 .querySelectorAll(getTargetSelector(btn))
652667 .forEach((el, i, queryList) => {
653- btn.addEventListener(
654- eventType,
655- // @ts-ignore
656- eventHandler(el, animationId, {
657- ...opts ,
658- totalTargets: queryList.length,
659- queryIndex: i,
660- })
661- );
668+ // @ts-ignore
669+ const listener = eventHandler(el, animationId, {
670+ ...opts,
671+ totalTargets: queryList.length,
672+ queryIndex: i ,
673+ });
674+
675+ LISTENERS[trigger].push(listener);
676+ btn.addEventListener(eventType, listener );
662677 });
663678 });
664679};
665680
681+ /**
682+ * Removes the event listener of all elements represented by the `triggerSelector`
683+ * @param {String|null} triggerSelector - A valid CSS selector for the trigger Element. If ommited, '.${CLASS_NAMES.trigger}' will be used instead.
684+ * @param {String} eventType - The event name. If ommited, 'click' is the default value.
685+ */
686+ const end = (triggerSelector = null, eventType = 'click') => {
687+ const triggerList =
688+ typeof triggerSelector === 'string'
689+ ? document.querySelectorAll(triggerSelector)
690+ : document.querySelectorAll(`.${CLASS_NAMES.trigger}`);
691+
692+ triggerList.forEach(trigger => {
693+ LISTENERS[triggerSelector ?? `.${CLASS_NAMES.trigger}`].forEach(
694+ listener => {
695+ trigger.removeEventListener(eventType, listener);
696+ }
697+ );
698+ });
699+ delete LISTENERS[triggerSelector ?? `.${CLASS_NAMES.trigger}`];
700+ };
701+
666702export {
667703 init,
704+ end,
668705 animate,
669706 preset,
670707 isEnabled,
@@ -688,7 +725,7 @@ <h2><a href="index.html">JS-CSS Animations</a></h2><h3>Modules</h3><ul><li><a hr
688725< br class ="clear ">
689726
690727< footer >
691- Documentation generated by < a href ="https://github.com/jsdoc/jsdoc "> JSDoc 4.0.0</ a > on Wed Nov 23 2022 20:32:22 GMT-0300 (Horário Padrão de Brasília)
728+ Documentation generated by < a href ="https://github.com/jsdoc/jsdoc "> JSDoc 4.0.0</ a > on Wed Dec 07 2022 15:22:18 GMT-0300 (Horário Padrão de Brasília)
692729</ footer >
693730
694731< script > prettyPrint ( ) ; </ script >
0 commit comments