@@ -178,21 +178,26 @@ class ToolTip {
178
178
179
179
// Destroy this instance
180
180
destroy ( ) {
181
- this . visibleCheck ( false ) ;
181
+ // Stop listening to trigger events
182
+ this . unListen ( ) ;
183
+ // Disable while open listeners/watchers
184
+ this . setWhileOpenListeners ( false ) ;
185
+ // Clear any timouts
182
186
clearTimeout ( this . $hoverTimeout ) ;
183
187
this . $hoverTimeout = null ;
184
188
clearTimeout ( this . $fadeTimeout ) ;
185
189
this . $fadeTimeout = null ;
186
- this . unListen ( ) ;
187
- this . setOnTouchStartListener ( false ) ;
190
+ // Remove popper
188
191
if ( this . $popper ) {
189
192
this . $popper . destroy ( ) ;
190
193
}
191
194
this . $popper = null ;
195
+ // Remove tip from document
192
196
if ( this . $tip && this . $tip . parentElement ) {
193
197
this . $tip . parentElement . removeChild ( this . $tip ) ;
194
198
}
195
199
this . $tip = null ;
200
+ // Null out other properties
196
201
this . $id = null
197
202
this . $root = null ;
198
203
this . $element = null ;
@@ -289,13 +294,11 @@ class ToolTip {
289
294
this . emitEvent ( shownEvt ) ;
290
295
} ;
291
296
297
+ // Enable while open listeners/watchers
298
+ this . setWhileOpenListeners ( true ) ;
299
+
292
300
// Show tip
293
301
tip . classList . add ( ClassName . SHOW ) ;
294
- this . setOnTouchStartListener ( true ) ;
295
-
296
- // Periodically check to make sure $element is visible
297
- // For handling when tip is in <keepalive>, tabs, carousel, etc
298
- this . visibleCheck ( true ) ;
299
302
300
303
// Start the transition/animation
301
304
this . transitionOnce ( tip , complete ) ;
@@ -316,6 +319,20 @@ class ToolTip {
316
319
}
317
320
}
318
321
322
+ setWhileOpenListeners ( on ) {
323
+ // Ontouch start listeners
324
+ this . setOnTouchStartListener ( on ) ;
325
+ // Global hide events
326
+ this . setRootListener ( on ) ;
327
+ // Modal close events
328
+ this . setModalListener ( on ) ;
329
+ // Route change events
330
+ this . setRouteWatcher ( on ) ;
331
+ // Periodic $element visibility check
332
+ // For handling when tip is in <keepalive>, tabs, carousel, etc
333
+ this . visibleCheck ( on ) ;
334
+ }
335
+
319
336
// force hide of tip (internal method)
320
337
forceHide ( ) {
321
338
const tip = this . getTipElement ( ) ;
@@ -349,9 +366,6 @@ class ToolTip {
349
366
return ;
350
367
}
351
368
352
- // Stop checking for visibility of element.
353
- this . visibleCheck ( false ) ;
354
-
355
369
// Transitionend Callback
356
370
const complete = ( ) => {
357
371
if ( this . $hoverState !== HoverState . SHOW && tip . parentNode ) {
@@ -374,8 +388,10 @@ class ToolTip {
374
388
this . emitEvent ( hiddenEvt ) ;
375
389
} ;
376
390
391
+ // Disable while open listeners/watchers
392
+ this . setWhileOpenListeners ( false ) ;
393
+
377
394
// Hide tip
378
- this . setOnTouchStartListener ( false ) ;
379
395
tip . classList . remove ( ClassName . SHOW ) ;
380
396
381
397
this . $activeTrigger . click = false ;
@@ -582,10 +598,6 @@ class ToolTip {
582
598
this . $element . addEventListener ( 'mouseleave' , this ) ;
583
599
}
584
600
} , this ) ;
585
- // If we are in a modal, we need to hide when it closes
586
- this . setModalListener ( true ) ;
587
- // Watch for route changes
588
- this . setRouteWatcher ( true ) ;
589
601
}
590
602
591
603
unListen ( ) {
@@ -594,9 +606,6 @@ class ToolTip {
594
606
events . forEach ( evt => {
595
607
this . $element . removeEventListener ( evt , this ) ;
596
608
} , this ) ;
597
- this . setModalListener ( false ) ;
598
- // stop watching for route changes
599
- this . setRouteWatcher ( false ) ;
600
609
}
601
610
602
611
handleEvent ( e ) {
@@ -648,15 +657,16 @@ class ToolTip {
648
657
}
649
658
// We can listen for modal hidden events on $root
650
659
if ( this . $root ) {
651
- if ( on ) {
652
- MODAL_CLOSE_EVENT . forEach ( evtName => {
653
- this . $root . $on ( evtName , this . forceHide . bind ( this ) ) ;
654
- } ) ;
655
- } else {
656
- MODAL_CLOSE_EVENT . forEach ( evtName => {
657
- this . $root . $off ( evtName , this . forceHide . bind ( this ) ) ;
658
- } ) ;
659
- }
660
+ MODAL_CLOSE_EVENT . forEach ( evtName => {
661
+ this . $root [ on ? '$on' : '$off' ] ( evtName , this . forceHide . bind ( this ) ) ;
662
+ } ) ;
663
+ }
664
+ }
665
+
666
+ setRootListener ( on ) {
667
+ // We can listen for global 'bv::hide::popover/tooltip' hide request event
668
+ if ( this . $root ) {
669
+ this . $root [ on ? '$on' : '$off' ] ( `bv::hide::${ this . constructor . NAME } ` , this . forceHide . bind ( this ) ) ;
660
670
}
661
671
}
662
672
@@ -667,11 +677,7 @@ class ToolTip {
667
677
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
668
678
if ( 'ontouchstart' in document . documentElement ) {
669
679
arrayFrom ( document . body . children ) . forEach ( el => {
670
- if ( on ) {
671
- el . addEventListener ( 'mouseover' , this . noop ) ;
672
- } else {
673
- el . removeEventListener ( 'mouseover' , this . noop ) ;
674
- }
680
+ el [ on ? 'addEventListener' : 'removeEventListener' ] ( 'mouseover' , this . noop ) ;
675
681
} ) ;
676
682
}
677
683
}
0 commit comments