This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat(popover): support templates #1848
Merged
chrisirhc
merged 2 commits into
angular-ui:master
from
chrisirhc:feature/popover-template
Mar 28, 2015
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
angular.module('ui.bootstrap.demo').controller('PopoverDemoCtrl', function ($scope) { | ||
$scope.dynamicPopover = 'Hello, World!'; | ||
$scope.dynamicPopoverTitle = 'Title'; | ||
$scope.dynamicPopover = { | ||
content: 'Hello, World!', | ||
templateUrl: 'myTemplatePopover.html', | ||
title: 'Title' | ||
}; | ||
}); |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
describe('popover template', function() { | ||
var elm, | ||
elmBody, | ||
scope, | ||
elmScope, | ||
tooltipScope; | ||
|
||
// load the popover code | ||
beforeEach(module('ui.bootstrap.popover')); | ||
|
||
// load the template | ||
beforeEach(module('template/popover/popover.html')); | ||
beforeEach(module('template/popover/popover-template.html')); | ||
|
||
beforeEach(inject(function ($templateCache) { | ||
$templateCache.put('myUrl', [200, '<span>{{ myTemplateText }}</span>', {}]); | ||
})); | ||
|
||
beforeEach(inject(function($rootScope, $compile) { | ||
elmBody = angular.element( | ||
'<div><span popover-template="{{ templateUrl }}">Selector Text</span></div>' | ||
); | ||
|
||
scope = $rootScope; | ||
$compile(elmBody)(scope); | ||
scope.templateUrl = 'myUrl'; | ||
|
||
scope.$digest(); | ||
elm = elmBody.find('span'); | ||
elmScope = elm.scope(); | ||
tooltipScope = elmScope.$$childTail; | ||
})); | ||
|
||
it('should open on click', inject(function() { | ||
elm.trigger( 'click' ); | ||
expect( tooltipScope.isOpen ).toBe( true ); | ||
|
||
expect( elmBody.children().length ).toBe( 2 ); | ||
})); | ||
|
||
it('should not open on click if templateUrl is empty', inject(function() { | ||
scope.templateUrl = null; | ||
scope.$digest(); | ||
|
||
elm.trigger( 'click' ); | ||
expect( tooltipScope.isOpen ).toBe( false ); | ||
|
||
expect( elmBody.children().length ).toBe( 1 ); | ||
})); | ||
|
||
it('should show updated text', inject(function() { | ||
scope.myTemplateText = 'some text'; | ||
scope.$digest(); | ||
|
||
elm.trigger( 'click' ); | ||
expect( tooltipScope.isOpen ).toBe( true ); | ||
|
||
expect( elmBody.children().eq(1).text().trim() ).toBe( 'some text' ); | ||
|
||
scope.myTemplateText = 'new text'; | ||
scope.$digest(); | ||
|
||
expect( elmBody.children().eq(1).text().trim() ).toBe( 'new text' ); | ||
})); | ||
}); | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
describe('tooltip template', function() { | ||
var elm, | ||
elmBody, | ||
scope, | ||
elmScope, | ||
tooltipScope; | ||
|
||
// load the popover code | ||
beforeEach(module('ui.bootstrap.tooltip')); | ||
|
||
// load the template | ||
beforeEach(module('template/tooltip/tooltip-template-popup.html')); | ||
|
||
beforeEach(inject(function ($templateCache) { | ||
$templateCache.put('myUrl', [200, '<span>{{ myTemplateText }}</span>', {}]); | ||
})); | ||
|
||
beforeEach(inject(function($rootScope, $compile) { | ||
elmBody = angular.element( | ||
'<div><span tooltip-template="{{ templateUrl }}">Selector Text</span></div>' | ||
); | ||
|
||
scope = $rootScope; | ||
$compile(elmBody)(scope); | ||
scope.templateUrl = 'myUrl'; | ||
|
||
scope.$digest(); | ||
elm = elmBody.find('span'); | ||
elmScope = elm.scope(); | ||
tooltipScope = elmScope.$$childTail; | ||
})); | ||
|
||
it('should open on mouseenter', inject(function() { | ||
elm.trigger( 'mouseenter' ); | ||
expect( tooltipScope.isOpen ).toBe( true ); | ||
|
||
expect( elmBody.children().length ).toBe( 2 ); | ||
})); | ||
|
||
it('should not open on mouseenter if templateUrl is empty', inject(function() { | ||
scope.templateUrl = null; | ||
scope.$digest(); | ||
|
||
elm.trigger( 'mouseenter' ); | ||
expect( tooltipScope.isOpen ).toBe( false ); | ||
|
||
expect( elmBody.children().length ).toBe( 1 ); | ||
})); | ||
|
||
it('should show updated text', inject(function() { | ||
scope.myTemplateText = 'some text'; | ||
scope.$digest(); | ||
|
||
elm.trigger( 'mouseenter' ); | ||
expect( tooltipScope.isOpen ).toBe( true ); | ||
|
||
expect( elmBody.children().eq(1).text().trim() ).toBe( 'some text' ); | ||
|
||
scope.myTemplateText = 'new text'; | ||
scope.$digest(); | ||
|
||
expect( elmBody.children().eq(1).text().trim() ).toBe( 'new text' ); | ||
})); | ||
}); | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<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" | ||
tooltip-template-transclude="content" | ||
tooltip-template-transclude-scope="originScope()"></div> | ||
</div> | ||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be split off into its own component as a helper directive, similar to the dateParser service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little hard to generalize though, because I don't want to create another scope here (notice the directive only has a link function), and it specifically looks for
origScope
andcontent
to be present on the scope.