Skip to content

Commit

Permalink
Merge PR from jbruni/popover-template in relation with angular-ui#1391
Browse files Browse the repository at this point in the history
  • Loading branch information
wedgybo committed Dec 16, 2013
2 parents 41bea46 + 205480b commit 7ce51e2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/popover/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}]);

16 changes: 13 additions & 3 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"'+

This comment has been minimized.

Copy link
@zhech2

zhech2 Dec 20, 2013

Looks like a space is needed after tt_isOpen" (Updated line: 'is-open="tt_isOpen" ' +). If not the attributes will be right next to each other: animation="" is-open=""compile-scope="".

'compile-scope="$parent"'+
'>'+
'</div>';

Expand Down Expand Up @@ -223,7 +224,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;

Expand All @@ -235,10 +236,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 ); } );
}
}

Expand Down Expand Up @@ -312,7 +322,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
$timeout.cancel( transitionTimeout );
$timeout.cancel( popupTimeout );
unregisterTriggers();
tooltip.remove();
remove( true );
tooltip.unbind();
tooltip = null;
});
Expand Down
8 changes: 8 additions & 0 deletions template/popover/popover-template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<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>

0 comments on commit 7ce51e2

Please sign in to comment.