Skip to content

Instantly share code, notes, and snippets.

@tb
Forked from jbruni/example-template.html
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tb/8d4c9693e57a10df5765 to your computer and use it in GitHub Desktop.
Save tb/8d4c9693e57a10df5765 to your computer and use it in GitHub Desktop.
<p>Here comes the <b>bindable HTML</b> popover contents!!!</p>
<p>Number: {{number}}</p>
<div ng-init="number = 108">
<button popover-template="example-template.html" class="btn">Example</button>
</div>
<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"></div>
</div>
</div>
angular.module( 'ui.bootstrap.popover' )
.directive( 'popoverTemplatePopup', [ '$templateCache', '$compile', function ( $templateCache, $compile ) {
return {
restrict: 'EA',
replace: true,
scope: { title: '@', content: '@', placement: '@', animation: '&', isOpen: '&' },
templateUrl: 'template/popover/popover-template.html',
link: function( scope, iElement ) {
var content = angular.fromJson( scope.content ),
template = $templateCache.get( content.templateUrl ),
templateScope = scope,
scopeElements = document.getElementsByClassName( 'ng-scope' );
angular.forEach( scopeElements, function( element ) {
var aScope = angular.element( element ).scope();
if ( aScope.$id == content.scopeId ) {
templateScope = aScope;
}
});
iElement.find('div.popover-content').html( $compile( template )( templateScope ) );
}
};
}])
.directive( 'popoverTemplate', [ '$tooltip', function ( $tooltip ) {
var tooltip = $tooltip( 'popoverTemplate', 'popover', 'click' );
tooltip.compile = function() {
return {
'pre': function( scope, iElement, iAttrs ) {
iAttrs.$set( 'popoverTemplate', { templateUrl: iAttrs.popoverTemplate, scopeId: scope.$id } );
},
'post': tooltip.link
};
};
return tooltip;
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment