From 2ca25a0965c5aa851a9d668a52a3007b7b25c9ac Mon Sep 17 00:00:00 2001 From: Chris Chua Date: Sat, 18 Apr 2015 23:40:55 -0700 Subject: [PATCH 1/3] feat(tooltip): use expression to fix usage with $sce Allows for trusted resource URLs through Strict Contextual Escaping ($sce). If the an interpolated expression is used instead, then the benefits of SCE is lost. Fixes #3558 --- src/tooltip/docs/demo.html | 2 +- src/tooltip/test/tooltip-template.spec.js | 16 +++++++- src/tooltip/tooltip.js | 42 +++++++++++++------- template/tooltip/tooltip-template-popup.html | 2 +- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/tooltip/docs/demo.html b/src/tooltip/docs/demo.html index 3072ec345c..4bb7f0adf9 100644 --- a/src/tooltip/docs/demo.html +++ b/src/tooltip/docs/demo.html @@ -20,7 +20,7 @@ fading at elementum eu, facilisis sed odio morbi quis commodo odio. In cursus delayed turpis massa tincidunt dui ut. - Custom template + Custom template nunc sed velit dignissim sodales ut eu sem integer vitae. Turpis egestas

diff --git a/src/tooltip/test/tooltip-template.spec.js b/src/tooltip/test/tooltip-template.spec.js index dab8d34863..190be308c7 100644 --- a/src/tooltip/test/tooltip-template.spec.js +++ b/src/tooltip/test/tooltip-template.spec.js @@ -17,7 +17,7 @@ describe('tooltip template', function() { beforeEach(inject(function($rootScope, $compile) { elmBody = angular.element( - '
Selector Text
' + '
Selector Text
' ); scope = $rootScope; @@ -61,5 +61,19 @@ describe('tooltip template', function() { expect( elmBody.children().eq(1).text().trim() ).toBe( 'new text' ); })); + + it('should hide tooltip when template becomes empty', inject(function ($timeout) { + elm.trigger( 'mouseenter' ); + expect( tooltipScope.isOpen ).toBe( true ); + + scope.templateUrl = ''; + scope.$digest(); + + expect( tooltipScope.isOpen ).toBe( false ); + + $timeout.flush(); + expect( elmBody.children().length ).toBe( 1 ); + })); + }); diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 9189c70f4e..924c91c35d 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -14,7 +14,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap var defaultOptions = { placement: 'top', animation: true, - popupDelay: 0 + popupDelay: 0, + useContentExp: false }; // Default hide triggers for each show trigger @@ -65,8 +66,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap * TODO support multiple triggers */ this.$get = [ '$window', '$compile', '$timeout', '$document', '$position', '$interpolate', function ( $window, $compile, $timeout, $document, $position, $interpolate ) { - return function $tooltip ( type, prefix, defaultTriggerShow ) { - var options = angular.extend( {}, defaultOptions, globalOptions ); + return function $tooltip ( type, prefix, defaultTriggerShow, options ) { + options = angular.extend( {}, defaultOptions, globalOptions, options ); /** * Returns an object of show and hide triggers. @@ -98,8 +99,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap var template = '
From 8c37865a46df302a364062e0bedc4c3eb8175f8d Mon Sep 17 00:00:00 2001 From: Chris Chua Date: Sat, 18 Apr 2015 23:43:42 -0700 Subject: [PATCH 2/3] feat(popover): use expression to fix usage with $sce Allows for trusted resource URLs through Strict Contextual Escaping ($sce). If the an interpolated expression is used instead, then the benefits of SCE is lost. Fixes #3558 --- src/popover/docs/demo.html | 2 +- src/popover/popover.js | 6 ++++-- src/popover/test/popover-template.spec.js | 16 +++++++++++++++- template/popover/popover-template.html | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/popover/docs/demo.html b/src/popover/docs/demo.html index b0dd4243e6..b4fcc087f0 100644 --- a/src/popover/docs/demo.html +++ b/src/popover/docs/demo.html @@ -14,7 +14,7 @@

Dynamic

- +