Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Added support for popover-html directive for binding html #1660

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/popover/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] )
};
})

.directive( 'popoverHtmlPopup', function () {
return {
restrict: 'EA',
replace: true,
scope: { title: '@', content: '=', placement: '@', animation: '&', isOpen: '&' },
templateUrl: 'template/popover/popover-html.html'
};
})

.directive( 'popover', [ '$tooltip', function ( $tooltip ) {
return $tooltip( 'popover', 'popover', 'click' );
}])

.directive( 'popoverHtml', [ '$tooltip', function ( $tooltip ) {
return $tooltip( 'popoverHtml', 'popoverHtml', 'click', true );
}]);
33 changes: 33 additions & 0 deletions src/popover/test/popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,37 @@ describe('popover', function() {
}));
});

describe('popoverHtml', function() {
var elm,
elmBody,
scope,
elmScope;

// load the popover code
beforeEach(module('ui.bootstrap.popover'));

// load the template
beforeEach(module('template/popover/popover-html.html'));

beforeEach(inject(function($rootScope, $compile) {
elmBody = angular.element(
'<div><span popover-html="html">Selector Text</span></div>'
);

scope = $rootScope;
scope.html = '<div>foo</div>';
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
}));

it('should render properly', inject(function() {
// We can only test *that* the popover-html-popup element was created as the
// implementation is templated and replaced.
expect( elmBody.children().length ).toBe( 1 );
}));
});



12 changes: 10 additions & 2 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
* TODO support multiple triggers
*/
this.$get = [ '$window', '$compile', '$timeout', '$parse', '$document', '$position', '$interpolate', function ( $window, $compile, $timeout, $parse, $document, $position, $interpolate ) {
return function $tooltip ( type, prefix, defaultTriggerShow ) {
return function $tooltip ( type, prefix, defaultTriggerShow, bindHtml ) {
var options = angular.extend( {}, defaultOptions, globalOptions );

/**
Expand Down Expand Up @@ -95,7 +95,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap

var startSym = $interpolate.startSymbol();
var endSym = $interpolate.endSymbol();
var template =
var template = bindHtml ?
'<div '+ directiveName +'-popup '+
'title="'+startSym+'tt_title'+endSym+'" '+
'content="tt_content" '+
'placement="'+startSym+'tt_placement'+endSym+'" '+
'animation="tt_animation" '+
'is-open="tt_isOpen"'+
'>'+
'</div>' :
'<div '+ directiveName +'-popup '+
'title="'+startSym+'tt_title'+endSym+'" '+
'content="'+startSym+'tt_content'+endSym+'" '+
Expand Down
8 changes: 8 additions & 0 deletions template/popover/popover-html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="popover {{placement}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="arrow"></div>

<div class="popover-inner">
<h3 class="popover-title" ng-bind="title" ng-show="title"></h3>
<div class="popover-content" bind-html-unsafe="content"></div>
</div>
</div>