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

feat(popover): created popover-template directive #369

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
9 changes: 9 additions & 0 deletions src/popover/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ <h4>Triggers</h4>
popover="I appeared on focus! Click away and I'll vanish..."
popover-trigger="focus" />
</div>
<script type="text/ng-template" id="mypopover.tpl.html">
<div class="popover-content">
<h3>Hello!</h3>
</div>
</script>
<div>
<h4>Custom Templates</h4>
<button popover-template="mypopover.tpl.html" class="btn">Open!</button>
</div>
<div>
<h4>Other</h4>
<button Popover-animation="true" popover="I fade in and out!" class="btn">fading</button>
Expand Down
25 changes: 18 additions & 7 deletions src/popover/popover.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* The following features are still outstanding: popup delay, animation as a
* function, placement as a function, inside, support for more triggers than
* just mouse enter/leave, html popovers, and selector delegatation.
*/
angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] )
.directive( 'popoverPopup', function () {
return {
Expand All @@ -12,7 +7,23 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] )
templateUrl: 'template/popover/popover.html'
};
})
.directive( 'popover', [ '$compile', '$timeout', '$parse', '$window', '$tooltip', function ( $compile, $timeout, $parse, $window, $tooltip ) {

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

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

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

;

29 changes: 28 additions & 1 deletion src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
'content="{{tt_content}}" '+
'placement="{{tt_placement}}" '+
'animation="tt_animation()" '+
'is-open="tt_isOpen"'+
'is-open="tt_isOpen" '+
'template="{{tt_template}}"'+
'>'+
'</'+ directiveName +'-popup>';

Expand Down Expand Up @@ -266,6 +267,10 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
element.bind( triggers.hide, hideTooltipBind );
}
});

attrs.$observe( prefix+'Template', function ( val ) {
scope.tt_template = val;
});
}
};
};
Expand Down Expand Up @@ -298,5 +303,27 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
return $tooltip( 'tooltipHtmlUnsafe', 'tooltip', 'mouseenter' );
}])

/**
* Loads the provided template via $http, attaches it to the current element,
* and compiles it relative to a new sibling scope.
*
* For internal use only!
*/
.directive( 'ttLoadTemplateInSibling', [ '$http', '$templateCache', '$compile', function ( $http, $templateCache, $compile ) {
return {
link: function ( scope, element, attrs ) {
var templateScope = scope.$parent.$new();

attrs.$observe( 'ttLoadTemplateInSibling', function ( val ) {
$http.get( val, { cache: $templateCache } )
.then( function( response ) {
element.html( response.data );
$compile( element.contents() )( templateScope );
});
});
}
};
}])

;

6 changes: 6 additions & 0 deletions template/popover/popover-template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="popover {{placement}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="arrow"></div>

<div class="popover-inner" tt-load-template-in-sibling="{{template}}"></div>
</div>