Skip to content

Commit 709d8e5

Browse files
author
Dominik Gätjens
committed
feat(popover): Adds unsafe html option for popover
This Feature enables the User to add HTML-Formatted Content to a popover See: Issue angular-ui#520
1 parent e223817 commit 709d8e5

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

src/popover/docs/demo.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ <h4>Triggers</h4>
2626
<h4>Other</h4>
2727
<button Popover-animation="true" popover="I fade in and out!" class="btn">fading</button>
2828
<button popover="I have a title!" popover-title="The title." class="btn">title</button>
29+
<button popover-html-unsafe="<b>Hello</b> Foobar" popover-title="The title." class="btn">With HTML-Body</button>
2930
</div>
3031
</div>
3132
</div>

src/popover/docs/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ will display:
1717
`tooltip` directive for supported values.
1818
- `popover-append-to-body`: Should the tooltip be appended to `$body` instead of
1919
the parent element?
20+
- `popover-html-unsafe`: To add HTML-Content to the popover body.
2021

2122
The popover directives require the `$position` service.
2223

src/popover/popover.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,17 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] )
1414
})
1515
.directive( 'popover', [ '$compile', '$timeout', '$parse', '$window', '$tooltip', function ( $compile, $timeout, $parse, $window, $tooltip ) {
1616
return $tooltip( 'popover', 'popover', 'click' );
17-
}]);
17+
}])
1818

19+
.directive( 'popoverHtmlUnsafePopup', function () {
20+
return {
21+
restrict: 'E',
22+
replace: true,
23+
scope: { content: '@', placement: '@', animation: '&', isOpen: '&' },
24+
templateUrl: 'template/popover/popover-html-unsafe-popup.html'
25+
};
26+
})
27+
28+
.directive( 'popoverHtmlUnsafe', [ '$tooltip', function ( $tooltip ) {
29+
return $tooltip( 'popoverHtmlUnsafe', 'popover', 'click' );
30+
}]);

src/popover/test/popoverSpec.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,50 @@ describe('popover', function() {
4646
}));
4747
});
4848

49-
49+
describe( 'popoverHtmlUnsafe', function() {
50+
var elm,
51+
elmBody,
52+
scope,
53+
elmScope;
54+
55+
// load the popover code
56+
beforeEach(module('ui.bootstrap.popover'));
57+
58+
// load the template
59+
beforeEach(module('template/popover/popover-html-unsafe-popup.html'));
60+
61+
beforeEach(inject(function($rootScope, $compile) {
62+
elmBody = angular.element(
63+
'<div><span popover-html-unsafe="<b> text </b>">Selector Text</span></div>'
64+
);
65+
66+
scope = $rootScope;
67+
$compile(elmBody)(scope);
68+
scope.$digest();
69+
elm = elmBody.find('span');
70+
elmScope = elm.scope();
71+
}));
72+
73+
it('should not be open initially', inject(function() {
74+
expect( elmScope.tt_isOpen ).toBe( false );
75+
76+
// We can only test *that* the popover-popup element wasn't created as the
77+
// implementation is templated and replaced.
78+
expect( elmBody.children().length ).toBe( 1 );
79+
}));
80+
81+
it('should open on click', inject(function() {
82+
elm.trigger( 'click' );
83+
expect( elmScope.tt_isOpen ).toBe( true );
84+
85+
// We can only test *that* the popover-popup element was created as the
86+
// implementation is templated and replaced.
87+
expect( elmBody.children().length ).toBe( 2 );
88+
}));
89+
90+
it('should close on second click', inject(function() {
91+
elm.trigger( 'click' );
92+
elm.trigger( 'click' );
93+
expect( elmScope.tt_isOpen ).toBe( false );
94+
}));
95+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="popover {{placement}}" ng-class="{ in: isOpen(), fade: animation() }">
2+
<div class="arrow"></div>
3+
4+
<div class="popover-inner">
5+
<h3 class="popover-title" ng-bind="title" ng-show="title"></h3>
6+
<div class="popover-content" ng-bind-html-unsafe="content"></div>
7+
</div>
8+
</div>

0 commit comments

Comments
 (0)