diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 1db5654fb7..8938710210 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -63,6 +63,14 @@ angular.module( 'ui.bootstrap.tooltip', [] ) '>'+ ''; + var hideTriggerDefaults = { + 'click': 'click', + 'hover': 'hover', + 'focus': 'focus', + 'focusin': 'focusout', + 'mouseenter': 'mouseleave' + }; + // Calculate the current position and size of the directive element. function getPosition( element ) { var boundingClientRect = element[0].getBoundingClientRect(); @@ -211,23 +219,45 @@ angular.module( 'ui.bootstrap.tooltip', [] ) // Register the event listeners. If only one event listener was // supplied, we use the same event listener for showing and hiding. - // TODO add ability to customize event triggers - if ( ! angular.isDefined( defaultTriggerHide ) ) { - element.bind( defaultTriggerShow, function toggleTooltipBind () { - if ( ! scope.tt_isOpen ) { - showWithDelay(); + var tt_triggerShow, tt_triggerHide; + + attrs.$observe( type+'TriggerShow', function ( val ) { + if ( angular.isDefined( val ) ) { + tt_triggerShow = val; + } else if ( angular.isDefined( options.triggerShow ) ) { + tt_triggerShow = options.triggerShow; + } else { + tt_triggerShow = defaultTriggerShow; + } + + attrs.$observe( type+'TriggerHide', function ( val ) { + if ( angular.isDefined( val ) ) { + tt_triggerHide = val; + } else if ( angular.isDefined( options.triggerHide ) ) { + tt_triggerHide = options.triggerHide; } else { - scope.$apply( hide ); + tt_triggerHide = hideTriggerDefaults[tt_triggerShow] || defaultTriggerHide; + } + + if ( tt_triggerShow === tt_triggerHide ) { + element.bind( tt_triggerShow, function toggleTooltipBind () { + if ( ! scope.tt_isOpen ) { + showWithDelay(); + } else { + scope.$apply( hide ); + } + }); + } else { + element.bind( tt_triggerShow, function showTooltipBind () { + showWithDelay(); + }); + + element.bind( tt_triggerHide, function hideTooltipBind () { + scope.$apply( hide ); + }); } }); - } else { - element.bind( defaultTriggerShow, function showTooltipBind() { - showWithDelay(); - }); - element.bind( defaultTriggerHide, function hideTooltipBind() { - scope.$apply( hide ); - }); - } + }); } }; };