Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Add custom trigger property for $tooltip provider #289

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 additions & 14 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ angular.module( 'ui.bootstrap.tooltip', [] )
'>'+
'</'+ directiveName +'-popup>';

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();
Expand Down Expand Up @@ -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 );
});
}
});
}
};
};
Expand Down