@@ -16,6 +16,8 @@ const DEFAULT_OPTIONS = {
1616 offset : 0 ,
1717}
1818
19+ const openTooltips = [ ]
20+
1921export default class Tooltip {
2022 /**
2123 * Create a new Tooltip.js instance
@@ -203,6 +205,7 @@ export default class Tooltip {
203205 )
204206 : [ ]
205207 this . _isDisposed = false
208+ this . _enableDocumentTouch = events . indexOf ( 'manual' ) === - 1
206209
207210 // set event listeners
208211 this . _setEventListeners ( this . reference , events , this . options )
@@ -290,6 +293,8 @@ export default class Tooltip {
290293 }
291294 this . _isOpen = true
292295
296+ openTooltips . push ( this )
297+
293298 // if the tooltipNode already exists, just show it
294299 if ( this . _tooltipNode ) {
295300 this . _tooltipNode . style . display = ''
@@ -366,13 +371,21 @@ export default class Tooltip {
366371 return this
367372 }
368373
374+ _noLongerOpen ( ) {
375+ const index = openTooltips . indexOf ( this )
376+ if ( index !== - 1 ) {
377+ openTooltips . splice ( index , 1 )
378+ }
379+ }
380+
369381 _hide ( /* reference, options */ ) {
370382 // don't hide if it's already hidden
371383 if ( ! this . _isOpen ) {
372384 return this
373385 }
374386
375387 this . _isOpen = false
388+ this . _noLongerOpen ( )
376389
377390 // hide tooltipNode
378391 this . _tooltipNode . style . display = 'none'
@@ -420,6 +433,8 @@ export default class Tooltip {
420433 this . _tooltipNode . parentNode . removeChild ( this . _tooltipNode )
421434 this . _tooltipNode = null
422435 }
436+ } else {
437+ this . _noLongerOpen ( )
423438 }
424439 return this
425440 }
@@ -493,6 +508,12 @@ export default class Tooltip {
493508 } )
494509 }
495510
511+ _onDocumentTouch ( event ) {
512+ if ( this . _enableDocumentTouch ) {
513+ this . _scheduleHide ( this . reference , this . options . delay , this . options , event )
514+ }
515+ }
516+
496517 _scheduleShow ( reference , delay , options /*, evt */ ) {
497518 // defaults to 0
498519 const computedDelay = ( delay && delay . show ) || delay || 0
@@ -554,6 +575,15 @@ export default class Tooltip {
554575 } ;
555576}
556577
578+ // Hide tooltips on touch devices
579+ if ( typeof document !== 'undefined' ) {
580+ document . addEventListener ( 'touchstart' , event => {
581+ for ( let i = 0 ; i < openTooltips . length ; i ++ ) {
582+ openTooltips [ i ] . _onDocumentTouch ( event )
583+ }
584+ } )
585+ }
586+
557587/**
558588 * Placement function, its context is the Tooltip instance.
559589 * @memberof Tooltip
0 commit comments