@@ -3,18 +3,8 @@ import { DOMObserver } from '@untemps/dom-observer'
33class Tooltip {
44 static #instances = [ ]
55
6- #observer = null
7- #events = [ ]
8- #enterDelay = 0
9- #leaveDelay = 0
10- #delay = null
11-
126 #tooltip = null
137
14- #boundEnterHandler = null
15- #boundLeaveHandler = null
16- #boundWindowChangeHandler = null
17-
188 #target = null
199 #content = null
2010 #contentSelector = null
@@ -24,8 +14,19 @@ class Tooltip {
2414 #animated = false
2515 #animationEnterClassName = null
2616 #animationLeaveClassName = null
17+ #enterDelay = 0
18+ #leaveDelay = 0
2719 #offset = 10
2820
21+ #observer = null
22+ #events = [ ]
23+ #delay = null
24+ #transitioning = false
25+
26+ #boundEnterHandler = null
27+ #boundLeaveHandler = null
28+ #boundWindowChangeHandler = null
29+
2930 static destroy ( ) {
3031 Tooltip . #instances. forEach ( ( instance ) => {
3132 instance . destroy ( )
@@ -88,10 +89,13 @@ class Tooltip {
8889 offset ,
8990 disabled
9091 ) {
91- const hasContentChanged = contentSelector !== this . #contentSelector || content !== this . #content
92- const hasContainerClassNameChanged = containerClassName !== this . #containerClassName
93- const hasPositionChanged = position !== this . #position
94- const hasOffsetChanged = position !== this . #offset
92+ const hasContentChanged =
93+ ( contentSelector !== undefined && contentSelector !== this . #contentSelector) ||
94+ ( content !== undefined && content !== this . #content)
95+ const hasContainerClassNameChanged =
96+ containerClassName !== undefined && containerClassName !== this . #containerClassName
97+ const hasPositionChanged = position !== undefined && position !== this . #position
98+ const hasOffsetChanged = offset !== undefined && offset !== this . #offset
9599 const hasToDisableTarget = disabled && this . #boundEnterHandler
96100 const hasToEnableTarget = ! disabled && ! this . #boundEnterHandler
97101
@@ -326,31 +330,32 @@ class Tooltip {
326330
327331 #transitionTooltip( direction ) {
328332 return new Promise ( ( resolve ) => {
329- let classToAdd , classToRemove
330333 switch ( direction ) {
331334 case 1 : {
332- classToAdd = this . #animationEnterClassName
333- classToRemove = this . #animationLeaveClassName
335+ this . #tooltip. classList . add ( this . #animationEnterClassName)
336+ this . #tooltip. classList . remove ( this . #animationLeaveClassName)
337+ this . #transitioning = false
338+ resolve ( )
334339 break
335340 }
336341 default : {
337- classToAdd = this . #animationLeaveClassName
338- classToRemove = this . #animationEnterClassName
339- }
340- }
341- this . #tooltip. classList . add ( classToAdd )
342- this . #tooltip. classList . remove ( classToRemove )
343-
344- if ( direction === 1 ) {
345- resolve ( )
346- }
342+ const onTransitionEnd = ( ) => {
343+ this . #tooltip. removeEventListener ( 'animationend' , onTransitionEnd )
344+ this . #tooltip. classList . remove ( this . #animationLeaveClassName)
345+ if ( this . #transitioning) {
346+ this . #transitioning = false
347+ resolve ( )
348+ }
349+ }
347350
348- const onTransitionEnd = ( ) => {
349- this . #tooltip. removeEventListener ( 'animationend' , onTransitionEnd )
350- this . #tooltip. classList . remove ( classToAdd )
351- resolve ( )
351+ if ( ! this . #transitioning) {
352+ this . #tooltip. addEventListener ( 'animationend' , onTransitionEnd )
353+ this . #tooltip. classList . add ( this . #animationLeaveClassName)
354+ this . #tooltip. classList . remove ( this . #animationEnterClassName)
355+ this . #transitioning = true
356+ }
357+ }
352358 }
353- this . #tooltip. addEventListener ( 'animationend' , onTransitionEnd )
354359 } )
355360 }
356361
0 commit comments