From 44f19b963114699081212094660309bf5d60eb05 Mon Sep 17 00:00:00 2001 From: "J. Bruni" Date: Thu, 19 Sep 2013 22:54:02 -0300 Subject: [PATCH 1/6] "popoverTemplate" and "popoverTemplatePopup" directives --- src/popover/popover.js | 16 +++++++++++++++- src/tooltip/tooltip.js | 5 +++-- template/popover/popover-template.html | 8 ++++++++ 3 files changed, 26 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..55a2473ad4 100644 --- a/src/popover/popover.js +++ b/src/popover/popover.js @@ -14,5 +14,19 @@ 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', [ '$templateCache', '$compile', function ( $templateCache, $compile ) { + return { + restrict: 'EA', + replace: true, + scope: { title: '@', content: '@', placement: '@', animation: '&', isOpen: '&', compileScope: '&' }, + templateUrl: 'template/popover/popover-template.html', + link: function( scope, iElement ) { + iElement.find( 'div.popover-content' ) + .html( $compile( $templateCache.get( scope.content ) )( 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 b75124eb17..c87201e892 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"'+ '>'+ ''; @@ -232,9 +233,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap // need to wait for it to expire beforehand. // FIXME: this is a placeholder for a port of the transitions library. if ( angular.isDefined( scope.tt_animation ) && scope.tt_animation() ) { - transitionTimeout = $timeout( function () { tooltip.remove(); }, 500 ); + transitionTimeout = $timeout( function () { tooltip.remove(undefined, true); }, 500 ); } else { - tooltip.remove(); + tooltip.remove(undefined, true); } } 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 @@ +
+
+ +
+

+
+
+
From 0f5ed4ff440f94b5d067a0a8c2264f9f1b61df73 Mon Sep 17 00:00:00 2001 From: "J. Bruni" Date: Thu, 19 Sep 2013 23:45:39 -0300 Subject: [PATCH 2/6] Making it work with jqLite --- src/tooltip/tooltip.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index c87201e892..08bb48af88 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -233,9 +233,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap // need to wait for it to expire beforehand. // FIXME: this is a placeholder for a port of the transitions library. if ( angular.isDefined( scope.tt_animation ) && scope.tt_animation() ) { - transitionTimeout = $timeout( function () { tooltip.remove(undefined, true); }, 500 ); + transitionTimeout = $timeout( function () { + angular.forEach( tooltip, function( e ) { e.parentNode.removeChild( e ) } ); + }, 500 ); } else { - tooltip.remove(undefined, true); + angular.forEach( tooltip, function( e ) { e.parentNode.removeChild( e ) } ); } } From 1f29094e33226e608dc56a754b617ed6bdcae467 Mon Sep 17 00:00:00 2001 From: "J. Bruni" Date: Thu, 19 Sep 2013 23:54:01 -0300 Subject: [PATCH 3/6] Added missing semicolons to make jshint happy --- src/tooltip/tooltip.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 08bb48af88..ea56dd6dc3 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -234,10 +234,10 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap // FIXME: this is a placeholder for a port of the transitions library. if ( angular.isDefined( scope.tt_animation ) && scope.tt_animation() ) { transitionTimeout = $timeout( function () { - angular.forEach( tooltip, function( e ) { e.parentNode.removeChild( e ) } ); + angular.forEach( tooltip, function( e ) { e.parentNode.removeChild( e ); } ); }, 500 ); } else { - angular.forEach( tooltip, function( e ) { e.parentNode.removeChild( e ) } ); + angular.forEach( tooltip, function( e ) { e.parentNode.removeChild( e ); } ); } } From 3e409272466efa0764a3c50a5b8fa915f8c94693 Mon Sep 17 00:00:00 2001 From: "J. Bruni" Date: Fri, 20 Sep 2013 00:21:06 -0300 Subject: [PATCH 4/6] Detaching when only hiding; removing when scope is destroyed --- src/tooltip/tooltip.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index ea56dd6dc3..3ee2dcfd0b 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -222,7 +222,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; @@ -233,9 +233,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap // need to wait for it to expire beforehand. // FIXME: this is a placeholder for a port of the transitions library. if ( angular.isDefined( scope.tt_animation ) && scope.tt_animation() ) { - transitionTimeout = $timeout( function () { - angular.forEach( tooltip, function( e ) { e.parentNode.removeChild( e ); } ); - }, 500 ); + transitionTimeout = $timeout( function () { remove( destroy ); }, 500 ); + } else { + remove( destroy ); + } + } + + function remove( destroy ) { + if ( destroy ) { + tooltip.remove(); } else { angular.forEach( tooltip, function( e ) { e.parentNode.removeChild( e ); } ); } @@ -302,9 +308,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap // Make sure tooltip is destroyed and removed. scope.$on('$destroy', function onDestroyTooltip() { if ( scope.tt_isOpen ) { - hide(); + hide( true ); } else { - tooltip.remove(); + remove( true ); } }); } From d3f61c0483361e6f6a667ab56fabfe37d0e82fec Mon Sep 17 00:00:00 2001 From: "J. Bruni" Date: Sun, 6 Oct 2013 21:47:28 -0300 Subject: [PATCH 5/6] Made popover-template directive compatible with AngularJS 1.0.8 Removed jQuery dependency Accepts external file templates --- src/popover/popover.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/popover/popover.js b/src/popover/popover.js index 55a2473ad4..d1620491d6 100644 --- a/src/popover/popover.js +++ b/src/popover/popover.js @@ -15,15 +15,22 @@ 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', [ '$templateCache', '$compile', function ( $templateCache, $compile ) { +.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 ) { - iElement.find( 'div.popover-content' ) - .html( $compile( $templateCache.get( scope.content ) )( scope.compileScope() ) ); + 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() ) ); + }); + }); } }; }]) From d1127b8d8e4dc9e715b7a37003b972977e126313 Mon Sep 17 00:00:00 2001 From: J Bruni Date: Sun, 6 Oct 2013 22:15:53 -0300 Subject: [PATCH 6/6] Made popover-template directive compatible with AngularJS 1.0.8 Removed jQuery dependency Accepts external file template --- src/popover/popover.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popover/popover.js b/src/popover/popover.js index d1620491d6..f8c151d450 100644 --- a/src/popover/popover.js +++ b/src/popover/popover.js @@ -23,7 +23,7 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] ) templateUrl: 'template/popover/popover-template.html', link: function( scope, iElement ) { scope.$watch( 'content', function( templateUrl ) { - if ( !templateUrl ) return; + if ( !templateUrl ) { return; } $http.get( templateUrl, { cache: $templateCache } ) .then( function( response ) { var contentEl = angular.element( iElement[0].querySelector( '.popover-content' ) );