Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
feat(accordion): add templateUrl support
Browse files Browse the repository at this point in the history
- Add ability to override the template of the `accordion` and `accordion-group` directives on an instance by instance basis

Closes #4084
  • Loading branch information
wesleycho committed Aug 4, 2015
1 parent b18dc8f commit f777c32
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
controller:'AccordionController',
transclude: true,
replace: false,
templateUrl: 'template/accordion/accordion.html'
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/accordion/accordion.html';
}
};
})

Expand All @@ -60,7 +62,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
restrict:'EA',
transclude:true, // It transcludes the contents of the directive into the template
replace: true, // The element containing the directive will be replaced with the template
templateUrl:'template/accordion/accordion-group.html',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/accordion/accordion-group.html';
},
scope: {
heading: '@', // Interpolate the heading attribute onto this scope
isOpen: '=?',
Expand Down
7 changes: 7 additions & 0 deletions src/accordion/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ The body of each accordion group is transcluded in to the body of the collapsibl

* `is-open` <i class="glyphicon glyphicon-eye-open"></i> (Defaults: false) :
Whether accordion group is open or closed.
* `template-url` (Defaults: `template/accordion/accordion.html`) :
Add ability to override the template url used

### Accordion Group Settings ###

* `template-url` (Defaults: `template/accordion/accordion-group.html`) :
Add ability to override the template url used
31 changes: 30 additions & 1 deletion src/accordion/test/accordion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ describe('accordion', function () {
});
});

describe('accordion', function () {
var scope, $compile, element;

beforeEach(inject(function($rootScope, _$compile_) {
scope = $rootScope;
$compile = _$compile_;
}));

it('should allow custom templates', inject(function ($templateCache) {
$templateCache.put('foo/bar.html', '<div>baz</div>');

element = $compile('<accordion template-url="foo/bar.html"></accordion>')(scope);
scope.$digest();
expect(element.html()).toBe('<div>baz</div>');
}));
});

describe('accordion-group', function () {

var scope, $compile;
Expand All @@ -113,7 +130,6 @@ describe('accordion', function () {
return groups.eq(index).find('.panel-collapse').eq(0);
};


beforeEach(inject(function(_$rootScope_, _$compile_) {
scope = _$rootScope_;
$compile = _$compile_;
Expand All @@ -123,6 +139,19 @@ describe('accordion', function () {
element = groups = scope = $compile = undefined;
});

it('should allow custom templates', inject(function ($templateCache) {
$templateCache.put('foo/bar.html', '<div>baz</div>');

var tpl =
'<accordion>' +
'<accordion-group heading="title 1" template-url="foo/bar.html"></accordion-group>' +
'</accordion>';

element = $compile(tpl)(scope);
scope.$digest();
expect(element.find('[template-url]').html()).toBe('baz');
}));

describe('with static panels', function () {
beforeEach(function () {
var tpl =
Expand Down

0 comments on commit f777c32

Please sign in to comment.