Skip to content

Commit 0a1510c

Browse files
committed
feat(popoverWindow): support template urls (WIP)
Proof of concept
1 parent 96b980e commit 0a1510c

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

Diff for: src/popover/popover.js

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
*/
66
angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] )
77

8+
.directive( 'popoverWindowPopup', function () {
9+
return {
10+
restrict: 'EA',
11+
replace: true,
12+
templateUrl: 'template/popover/popover-window.html'
13+
};
14+
})
15+
16+
.directive( 'popoverWindow', [ '$tooltip', function ( $tooltip ) {
17+
return $tooltip( 'popoverWindow', 'popoverWindow', 'click' );
18+
}])
19+
820
.directive( 'popoverPopup', function () {
921
return {
1022
restrict: 'EA',

Diff for: src/tooltip/tooltip.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
101101

102102
return {
103103
restrict: 'EA',
104+
controller: angular.noop,
105+
controllerAs: 'tooltipCtrl',
104106
scope: {
105107
title: '@' + prefix + 'Title'
106108
},
107109
compile: function (tElem, tAttrs) {
108110
var tooltipLinker = $compile( template );
109111

110-
return function link ( scope, element, attrs ) {
112+
return function link ( scope, element, attrs, tooltipCtrl ) {
111113
var tooltip, tooltipScope;
112114
var transitionTimeout;
113115
var popupTimeout;
@@ -125,6 +127,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
125127
tooltip.css( ttPosition );
126128
};
127129

130+
// Set up the correct scope
131+
tooltipCtrl.scope = scope.$parent;
132+
128133
// By default, the tooltip is not open.
129134
// TODO add ability to start tooltip opened
130135
scope.isOpen = false;
@@ -225,7 +230,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
225230
tooltip = tooltipLinker(tooltipScope, function () {});
226231

227232
// Get contents rendered into the tooltip
228-
scope.$digest();
233+
// Apply is required in order to make it work with rendering templates
234+
scope.$apply();
229235
}
230236

231237
function removeTooltip() {
@@ -309,6 +315,32 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
309315
}];
310316
})
311317

318+
.directive( 'tooltipTemplateTransclude', [
319+
'$http', '$compile', '$templateCache',
320+
function ($http , $compile , $templateCache) {
321+
return {
322+
link: function ( scope, elem, attrs ) {
323+
if (scope.tooltipCtrl && scope.content) {
324+
// TODO: How to solve the problem of pre-loading the template?
325+
// TODO: Should this be watching for changes in scope.content?
326+
var templateUrl = scope.content,
327+
transcludeScope = scope.tooltipCtrl.scope.$new();
328+
$http.get( templateUrl, { cache: $templateCache })
329+
.then(function (response) {
330+
elem.html(response.data);
331+
$compile(elem.contents())(transcludeScope);
332+
});
333+
334+
// Manual destruction because the transclude isn't a descendent of the
335+
// current scope
336+
scope.$on('$destroy', function () {
337+
transcludeScope.$destroy();
338+
});
339+
}
340+
}
341+
};
342+
}])
343+
312344
.directive( 'tooltipPopup', function () {
313345
return {
314346
restrict: 'EA',

Diff for: template/popover/popover-window.html

+8
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" tooltip-template-transclude></div>
7+
</div>
8+
</div>

0 commit comments

Comments
 (0)