@@ -37,7 +37,12 @@ <h1 class="page-title">Source: animate.js</h1>
37
37
CUSTOM_CSS_PROPERTIES,
38
38
} from './globals.js';
39
39
40
- import { initParentResize, endParentResize } from './resize-parent.js';
40
+ import {
41
+ initParentResize,
42
+ endParentResize,
43
+ setOverflowHidden,
44
+ removeOverflowHidden,
45
+ } from './resize-parent.js';
41
46
42
47
import {
43
48
removeInlineTransition,
@@ -60,7 +65,7 @@ <h1 class="page-title">Source: animate.js</h1>
60
65
staggerDelay: undefined,
61
66
start: undefined,
62
67
complete: undefined,
63
- keepSpace : false,
68
+ maintainSpace : false,
64
69
dimensionsTransition: true,
65
70
widthTransition: undefined,
66
71
heightTransition: undefined,
@@ -175,6 +180,12 @@ <h1 class="page-title">Source: animate.js</h1>
175
180
stack: {},
176
181
};
177
182
183
+ /**
184
+ * Keeps track of the EventListeners associated to a trigger selector
185
+ * @type {{[x: String]: EventListener[]}}
186
+ */
187
+ const LISTENERS = {};
188
+
178
189
/**
179
190
* Removes the CSS properties customized by the user
180
191
* @param {HTMLElement} element - The DOM element with the custom CSS properties
@@ -354,10 +365,12 @@ <h1 class="page-title">Source: animate.js</h1>
354
365
* @returns True if the element has an iteration CSS property set, False otherwise
355
366
*/
356
367
const hasIterationProp = element => {
368
+ const iterationProperty = element.style.getPropertyValue(
369
+ PROPERTY_NAMES.iteration
370
+ );
357
371
return (
358
- element.style
359
- .getPropertyValue(PROPERTY_NAMES.iteration)
360
- .match(/^(infinite|\d+)$/) !== null
372
+ iterationProperty != '1' &&
373
+ iterationProperty.match(/^(infinite|\d+)$/) !== null
361
374
);
362
375
};
363
376
@@ -371,17 +384,14 @@ <h1 class="page-title">Source: animate.js</h1>
371
384
* element: HTMLElement,
372
385
* parentMeasures: Object,
373
386
* action: string,
374
- * dimension: string | undefined,
375
- * keepSpace: boolean
387
+ * dimension: string | undefined
376
388
* }} args - All the necessary arguments
377
389
*/
378
390
const handleVisibilityToggle = (element, args) => {
379
391
setTimeout(() => {
380
392
if (args.dimension) setParentMaxMeasures(args);
381
393
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);
385
395
}
386
396
}, 0);
387
397
};
@@ -394,12 +404,14 @@ <h1 class="page-title">Source: animate.js</h1>
394
404
*/
395
405
const endVisibilityToggle = (element, opts) => {
396
406
if (opts.action === 'hide') {
397
- opts.keepSpace
407
+ opts.maintainSpace
398
408
? element.classList.add(CLASS_NAMES.hidden)
399
409
: element.classList.add(CLASS_NAMES.collapsed);
400
410
}
401
411
if (opts.heightTransition || opts.widthTransition)
402
412
endParentResize(element, opts);
413
+ else if (opts.overflowHidden && element.parentElement)
414
+ removeOverflowHidden(element.parentElement);
403
415
};
404
416
405
417
/**
@@ -442,8 +454,8 @@ <h1 class="page-title">Source: animate.js</h1>
442
454
trigger,
443
455
start = CONFIG.start,
444
456
complete = CONFIG.complete,
445
- keepSpace = CONFIG.keepSpace ,
446
- dimensionsTransition = keepSpace || isMotion(animType)
457
+ maintainSpace = CONFIG.maintainSpace ,
458
+ dimensionsTransition = maintainSpace || isMotion(animType)
447
459
? false
448
460
: CONFIG.dimensionsTransition,
449
461
widthTransition = CONFIG.widthTransition ?? dimensionsTransition,
@@ -472,7 +484,8 @@ <h1 class="page-title">Source: animate.js</h1>
472
484
heightTransition,
473
485
overflowHidden,
474
486
}));
475
- }
487
+ } else if (overflowHidden && element.parentElement)
488
+ setOverflowHidden(element.parentElement);
476
489
},
477
490
motion: () => {
478
491
currentTransition = getCurrentTransition(element);
@@ -487,7 +500,6 @@ <h1 class="page-title">Source: animate.js</h1>
487
500
parentMeasures,
488
501
action,
489
502
dimension,
490
- keepSpace,
491
503
});
492
504
},
493
505
motion: () => {
@@ -501,9 +513,10 @@ <h1 class="page-title">Source: animate.js</h1>
501
513
visibility: () => {
502
514
endVisibilityToggle(element, {
503
515
action,
504
- keepSpace ,
516
+ maintainSpace ,
505
517
widthTransition,
506
518
heightTransition,
519
+ overflowHidden,
507
520
});
508
521
if (!hasIterationProp(element))
509
522
element.classList.remove(CLASS_NAMES[action][id]);
@@ -595,7 +608,7 @@ <h1 class="page-title">Source: animate.js</h1>
595
608
* @param {HTMLElement} el - The DOM element being animated
596
609
* @param {number} animationId - The ID of the animation in the *_ANIMS_ID
597
610
* @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
599
612
* @see {@link module:globals.VISIBILITY_ANIMS_ID}
600
613
* @see {@link module:globals.MOTION_ANIMS_ID}
601
614
*/
@@ -647,24 +660,48 @@ <h1 class="page-title">Source: animate.js</h1>
647
660
btn.setAttribute('target-selector', targetSelector);
648
661
}
649
662
663
+ if (!opts.trigger) opts.trigger = trigger;
664
+ LISTENERS[trigger] = [];
650
665
document
651
666
.querySelectorAll(getTargetSelector(btn))
652
667
.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 );
662
677
});
663
678
});
664
679
};
665
680
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
+
666
702
export {
667
703
init,
704
+ end,
668
705
animate,
669
706
preset,
670
707
isEnabled,
@@ -688,7 +725,7 @@ <h2><a href="index.html">JS-CSS Animations</a></h2><h3>Modules</h3><ul><li><a hr
688
725
< br class ="clear ">
689
726
690
727
< 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)
692
729
</ footer >
693
730
694
731
< script > prettyPrint ( ) ; </ script >
0 commit comments