From 205480bc953400993863189294f05a8b2437815a Mon Sep 17 00:00:00 2001 From: "J. Bruni" Date: Wed, 11 Dec 2013 11:26:09 -0200 Subject: [PATCH] popover-template directive - addresses issue #220 --- src/popover/popover.js | 22 ++++++++++++++++++++++ src/tooltip/tooltip.js | 16 +++++++++++++--- template/popover/popover-template.html | 8 ++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 template/popover/popover-template.html diff --git a/src/popover/popover.js b/src/popover/popover.js index c38ff9461e..d13db875b9 100644 --- a/src/popover/popover.js +++ b/src/popover/popover.js @@ -14,5 +14,27 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] ) }) .directive( 'popover', [ '$compile', '$timeout', '$parse', '$window', '$tooltip', function ( $compile, $timeout, $parse, $window, $tooltip ) { return $tooltip( 'popover', 'popover', 'click' ); +}]) +.directive( 'popoverTemplatePopup', [ '$http', '$templateCache', '$compile', function ( $http, $templateCache, $compile ) { + return { + restrict: 'EA', + replace: true, + scope: { title: '@', content: '@', placement: '@', animation: '&', isOpen: '&', compileScope: '&' }, + templateUrl: 'template/popover/popover-template.html', + link: function( scope, iElement ) { + scope.$watch( 'content', function( templateUrl ) { + if ( !templateUrl ) { return; } + $http.get( templateUrl, { cache: $templateCache } ) + .then( function( response ) { + var contentEl = angular.element( iElement[0].querySelector( '.popover-content' ) ); + contentEl.children().remove(); + contentEl.append( $compile( response.data.trim() )( scope.compileScope() ) ); + }); + }); + } + }; +}]) +.directive( 'popoverTemplate', [ '$tooltip', function ( $tooltip ) { + return $tooltip( 'popoverTemplate', 'popover', 'click' ); }]); diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index a72d5295af..774f3e0bf1 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -102,6 +102,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap 'placement="'+startSym+'tt_placement'+endSym+'" '+ 'animation="tt_animation" '+ 'is-open="tt_isOpen"'+ + 'compile-scope="$parent"'+ '>'+ ''; @@ -224,7 +225,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap } // Hide the tooltip popup element. - function hide() { + function hide( destroy ) { // First things first: we don't show it anymore. scope.tt_isOpen = false; @@ -236,10 +237,19 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap // FIXME: this is a placeholder for a port of the transitions library. if ( scope.tt_animation ) { transitionTimeout = $timeout(function () { - tooltip.remove(); + remove( destroy ); }, 500); } else { + remove( destroy ); + } + } + + function remove( destroy ) { + if ( destroy ) { tooltip.remove(); + } else { + // corresponds to jQuery's "detach" (should be included in jqLite?) + angular.forEach( tooltip, function( e ) { e.parentNode.removeChild( e ); } ); } } @@ -308,7 +318,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap // Make sure tooltip is destroyed and removed. scope.$on('$destroy', function onDestroyTooltip() { $timeout.cancel( popupTimeout ); - tooltip.remove(); + remove( true ); tooltip.unbind(); tooltip = null; $body = null; diff --git a/template/popover/popover-template.html b/template/popover/popover-template.html new file mode 100644 index 0000000000..6f13d8b96f --- /dev/null +++ b/template/popover/popover-template.html @@ -0,0 +1,8 @@ +
+
+ +
+

+
+
+