Last active
December 23, 2015 11:39
-
-
Save jbruni/6629714 to your computer and use it in GitHub Desktop.
AngularJS UI Bootstrap "extension" - Popover with bindable HTML template!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Here comes the <b>bindable HTML</b> popover contents!!!</p> | |
<p>Number: {{number}}</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-init="number = 108"> | |
<button popover-template="example-template.html" class="btn">Example</button> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
The same here Rawry... Any chance of reproduce it on JSFIDDLE?