Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
feat(tooltip): add support for comma-separated delay values (fixes #791
Browse files Browse the repository at this point in the history
…, fixes #1009)
  • Loading branch information
mgcrea committed Sep 14, 2014
1 parent 987a8fb commit 1568231
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/tooltip/test/tooltip.spec.js
Expand Up @@ -49,6 +49,9 @@ describe('tooltip', function() {
'options-delay': {
element: '<a data-delay="15" bs-tooltip="tooltip">hover me</a>'
},
'options-delay-multiple': {
element: '<a data-delay="15,30" bs-tooltip="tooltip">hover me</a>'
},
'options-keyboard': {
scope: {tooltip: {title: 'Hello Tooltip!', keyboard: true}},
element: '<a data-keyboard="true" bs-tooltip="tooltip">hover me</a>'
Expand Down Expand Up @@ -287,6 +290,18 @@ describe('tooltip', function() {
}, 20);
});

it('should support multiple delay', function(done) {
var elm = compileDirective('options-delay-multiple');
angular.element(elm[0]).triggerHandler('mouseenter');
$animate.triggerCallbacks();

expect(sandboxEl.children('.tooltip').length).toBe(0);
setTimeout(function() {
expect(sandboxEl.children('.tooltip').length).toBe(1);
done();
}, 20);
});

});

describe('keyboard', function() {
Expand Down
13 changes: 6 additions & 7 deletions src/tooltip/tooltip.js
Expand Up @@ -39,7 +39,8 @@ angular.module('mgcrea.ngStrap.tooltip', ['mgcrea.ngStrap.helpers.dimensions'])
$tooltip.$promise = fetchTemplate(options.template);
var scope = $tooltip.$scope = options.scope && options.scope.$new() || $rootScope.$new();
if(options.delay && angular.isString(options.delay)) {
options.delay = parseFloat(options.delay);
var split = options.delay.split(',').map(parseFloat);
options.delay = split.length > 1 ? {show: split[0], hide: split[1]} : split[0];
}

// Support scope as string options
Expand Down Expand Up @@ -440,12 +441,10 @@ angular.module('mgcrea.ngStrap.tooltip', ['mgcrea.ngStrap.helpers.dimensions'])
});

// Observe scope attributes for change
angular.forEach(['title'], function(key) {
attr.$observe(key, function(newValue, oldValue) {
scope[key] = $sce.trustAsHtml(newValue);
angular.isDefined(oldValue) && $$rAF(function() {
tooltip && tooltip.$applyPlacement();
});
attr.$observe('title', function(newValue, oldValue) {
scope.title = $sce.trustAsHtml(newValue);
angular.isDefined(oldValue) && $$rAF(function() {
tooltip && tooltip.$applyPlacement();
});
});

Expand Down

0 comments on commit 1568231

Please sign in to comment.