From dfa53155bf59c25b3c7fe6779f1698c2ef7dddd9 Mon Sep 17 00:00:00 2001 From: Josh David Miller Date: Sun, 23 Jun 2013 12:26:19 -0700 Subject: [PATCH] feat(tooltip): add custom trigger support The $tooltipProvider now allows extending the default set of open and close trigger mappings. Closes #382. --- src/tooltip/test/tooltip.spec.js | 28 ++++++++++++++++++++++++++++ src/tooltip/tooltip.js | 9 +++++++++ 2 files changed, 37 insertions(+) diff --git a/src/tooltip/test/tooltip.spec.js b/src/tooltip/test/tooltip.spec.js index b62f93fe02..75b0df2c86 100644 --- a/src/tooltip/test/tooltip.spec.js +++ b/src/tooltip/test/tooltip.spec.js @@ -429,6 +429,34 @@ describe( '$tooltipProvider', function() { })); }); + describe( 'triggers with a custom mapped value', function() { + beforeEach(module('ui.bootstrap.tooltip', function($tooltipProvider){ + $tooltipProvider.setTriggers({ 'customOpenTrigger': 'customCloseTrigger' }); + $tooltipProvider.options({trigger: 'customOpenTrigger'}); + })); + + // load the template + beforeEach(module('template/tooltip/tooltip-popup.html')); + + it( 'should use the show trigger and the mapped value for the hide trigger', inject( function ( $rootScope, $compile ) { + elmBody = angular.element( + '
' + ); + + scope = $rootScope; + $compile(elmBody)(scope); + scope.$digest(); + elm = elmBody.find('input'); + elmScope = elm.scope(); + + expect( elmScope.tt_isOpen ).toBeFalsy(); + elm.trigger('customOpenTrigger'); + expect( elmScope.tt_isOpen ).toBeTruthy(); + elm.trigger('customCloseTrigger'); + expect( elmScope.tt_isOpen ).toBeFalsy(); + })); + }); + describe( 'triggers without a mapped value', function() { beforeEach(module('ui.bootstrap.tooltip', function($tooltipProvider){ $tooltipProvider.options({trigger: 'fakeTrigger'}); diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 9b9e42cd1a..3803820226 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -40,6 +40,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] ) angular.extend( globalOptions, value ); }; + /** + * This allows you to extend the set of trigger mappings available. E.g.: + * + * $tooltipProvider.setTriggers( 'openTrigger': 'closeTrigger' ); + */ + this.setTriggers = function setTriggers ( triggers ) { + angular.extend( triggerMap, triggers ); + }; + /** * This is a helper function for translating camel-case to snake-case. */