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

Commit

Permalink
bug fix - not allowing user to toggle each accordion group.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzou committed Nov 13, 2012
1 parent cdcef31 commit b8d67a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@ angular.module('ui.bootstrap.accordion').controller('AccordionController', ['$sc

var groups = $scope.groups = [];

this.select = function (group) {
this.select = function(group) {
angular.forEach(groups, function (group) {
group.selected = false;
});
group.selected = true;
};

this.addGroup = function (group) {
this.toggle = function(group) {
if (group.selected) {
group.selected = false;
} else {
this.select(group);
}
};

this.addGroup = function(group) {
groups.push(group);
if(group.selected) {
this.select(group);
}
};

this.removeGroup = function (group) {
this.removeGroup = function(group) {
groups.splice(groups.indexOf(group), 1);
};

}]);

/* accordion: Bootstrap accordion implementation
Expand Down Expand Up @@ -48,14 +57,18 @@ angular.module('ui.bootstrap.accordion').directive('accordionGroup', function ()
scope:{
title:'='
},
link:function (scope, element, attrs, accordionCtrl) {
link: function(scope, element, attrs, accordionCtrl) {

accordionCtrl.addGroup(scope);

scope.select = function () {
scope.select = function() {
accordionCtrl.select(scope);
};

scope.toggle = function() {
accordionCtrl.toggle(scope);
};

scope.$on('$destroy', function (event) {
accordionCtrl.removeGroup(scope);
});
Expand Down
7 changes: 7 additions & 0 deletions src/accordion/test/accordionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ describe('accordion', function () {
expect(findGroupBody(0)).not.toHaveClass('in');
expect(findGroupBody(1)).toHaveClass('in');
});

it('should toggle element on click', function() {
findGroupLink(0).click();
expect(findGroupBody(0)).toHaveClass('in');
findGroupLink(0).click();
expect(findGroupBody(0)).not.toHaveClass('in');
});
});

describe('dynamic accordion', function () {
Expand Down
2 changes: 1 addition & 1 deletion template/accordion/accordion-group.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" ng-click="select()">{{title}}</a>
<a class="accordion-toggle" ng-click="toggle()">{{title}}</a>
</div>
<div class="accordion-body collapse" ng-class="{in : selected}">
<div class="accordion-inner" ng-transclude></div>
Expand Down

0 comments on commit b8d67a6

Please sign in to comment.