From 3e0736674a21e59a9a7d2f87fdc109df467b257a Mon Sep 17 00:00:00 2001
From: Chris Chua
Date: Sun, 5 Apr 2015 21:04:57 -0700
Subject: [PATCH 1/2] feat(tooltip): add tooltip-html directive
This directive replaces tooltip-html-unsafe use cases. It requires
safe HTML content from $sce.
---
src/tooltip/docs/demo.html | 2 +-
src/tooltip/docs/demo.js | 4 +-
src/tooltip/test/tooltip.spec.js | 54 +++++++++++++++++++++++-
src/tooltip/tooltip.js | 18 ++++++++
template/tooltip/tooltip-html-popup.html | 4 ++
5 files changed, 78 insertions(+), 4 deletions(-)
create mode 100644 template/tooltip/tooltip-html-popup.html
diff --git a/src/tooltip/docs/demo.html b/src/tooltip/docs/demo.html
index 914dc91ccd..3072ec345c 100644
--- a/src/tooltip/docs/demo.html
+++ b/src/tooltip/docs/demo.html
@@ -25,7 +25,7 @@
- I can even contain HTML. Check me out!
+ I can even contain HTML. Check me out!
diff --git a/src/tooltip/docs/demo.js b/src/tooltip/docs/demo.js
index bc7fd24b82..18c2794b3e 100644
--- a/src/tooltip/docs/demo.js
+++ b/src/tooltip/docs/demo.js
@@ -1,5 +1,5 @@
-angular.module('ui.bootstrap.demo').controller('TooltipDemoCtrl', function ($scope) {
+angular.module('ui.bootstrap.demo').controller('TooltipDemoCtrl', function ($scope, $sce) {
$scope.dynamicTooltip = 'Hello, World!';
$scope.dynamicTooltipText = 'dynamic';
- $scope.htmlTooltip = 'I\'ve been made bold!';
+ $scope.htmlTooltip = $sce.trustAsHtml('I\'ve been made bold!');
});
diff --git a/src/tooltip/test/tooltip.spec.js b/src/tooltip/test/tooltip.spec.js
index ec1a576f2d..23abe5d6ba 100644
--- a/src/tooltip/test/tooltip.spec.js
+++ b/src/tooltip/test/tooltip.spec.js
@@ -498,8 +498,54 @@ describe( 'tooltip positioning', function() {
});
+describe( 'tooltipHtml', function() {
+ var elm, elmBody, elmScope, tooltipScope, scope;
+
+ // load the tooltip code
+ beforeEach(module('ui.bootstrap.tooltip', function ( $tooltipProvider ) {
+ $tooltipProvider.options({ animation: false });
+ }));
+
+ // load the template
+ beforeEach(module('template/tooltip/tooltip-html-popup.html'));
+
+ beforeEach(inject(function($rootScope, $compile, $sce) {
+ scope = $rootScope;
+ scope.html = 'I say: Hello!';
+ scope.safeHtml = $sce.trustAsHtml(scope.html);
+
+ elmBody = $compile( angular.element(
+ '
Selector Text
'
+ ))( scope );
+ scope.$digest();
+ elm = elmBody.find('span');
+ elmScope = elm.scope();
+ tooltipScope = elmScope.$$childTail;
+ }));
+
+ it( 'should render html properly', inject( function () {
+ elm.trigger( 'mouseenter' );
+ expect( elmBody.find('.tooltip-inner').html() ).toBe( scope.html );
+ }));
+
+ it( 'should show on mouseenter and hide on mouseleave', inject( function ($sce) {
+ expect( tooltipScope.isOpen ).toBe( false );
+
+ elm.trigger( 'mouseenter' );
+ expect( tooltipScope.isOpen ).toBe( true );
+ expect( elmBody.children().length ).toBe( 2 );
+
+ expect( $sce.getTrustedHtml(tooltipScope.contentExp()) ).toEqual( scope.html );
+
+ elm.trigger( 'mouseleave' );
+ expect( tooltipScope.isOpen ).toBe( false );
+ expect( elmBody.children().length ).toBe( 1 );
+ }));
+});
+
describe( 'tooltipHtmlUnsafe', function() {
var elm, elmBody, elmScope, tooltipScope, scope;
+ var logWarnSpy;
// load the tooltip code
beforeEach(module('ui.bootstrap.tooltip', function ( $tooltipProvider ) {
@@ -509,10 +555,12 @@ describe( 'tooltipHtmlUnsafe', function() {
// load the template
beforeEach(module('template/tooltip/tooltip-html-unsafe-popup.html'));
- beforeEach(inject(function($rootScope, $compile) {
+ beforeEach(inject(function($rootScope, $compile, $log) {
scope = $rootScope;
scope.html = 'I say: Hello!';
+ logWarnSpy = spyOn($log, 'warn');
+
elmBody = $compile( angular.element(
'Selector Text
'
))( scope );
@@ -522,6 +570,10 @@ describe( 'tooltipHtmlUnsafe', function() {
tooltipScope = elmScope.$$childTail;
}));
+ it( 'should warn that this is deprecated', function () {
+ expect(logWarnSpy).toHaveBeenCalledWith(jasmine.stringMatching('deprecated'));
+ });
+
it( 'should render html properly', inject( function () {
elm.trigger( 'mouseenter' );
expect( elmBody.find('.tooltip-inner').html() ).toBe( scope.html );
diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js
index d7afc7d1fd..2b05c1a1be 100644
--- a/src/tooltip/tooltip.js
+++ b/src/tooltip/tooltip.js
@@ -99,6 +99,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
'
From 7a2bec27f7964a795cc4bba92eb814ebca367967 Mon Sep 17 00:00:00 2001
From: Chris Chua
Date: Sun, 5 Apr 2015 18:45:21 -0700
Subject: [PATCH 2/2] feat(tooltip): add deprecate warning for -html-unsafe
---
src/tooltip/tooltip.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js
index 2b05c1a1be..ba7416dc69 100644
--- a/src/tooltip/tooltip.js
+++ b/src/tooltip/tooltip.js
@@ -478,6 +478,12 @@ Deprecated
};
})
-.directive( 'tooltipHtmlUnsafe', [ '$tooltip', function ( $tooltip ) {
+.value('tooltipHtmlUnsafeSuppressDeprecated', false)
+.directive( 'tooltipHtmlUnsafe', [
+ '$tooltip', 'tooltipHtmlUnsafeSuppressDeprecated', '$log',
+function ( $tooltip , tooltipHtmlUnsafeSuppressDeprecated , $log) {
+ if (!tooltipHtmlUnsafeSuppressDeprecated) {
+ $log.warn('tooltip-html-unsafe is now deprecated. Use tooltip-html or tooltip-template instead.');
+ }
return $tooltip( 'tooltipHtmlUnsafe', 'tooltip', 'mouseenter' );
}]);