@@ -28,9 +28,8 @@ angular.module('angularify.semantic.accordion', [])
2828
2929 if ( isCloseAll == true ) {
3030 for ( i in $scope . accordions ) {
31- if ( i == index ) { } else {
32- $scope . accordions [ i ] . class = 'title' ;
33- $scope . accordions [ i ] . content_class = 'content' ;
31+ if ( i !== index ) {
32+ $scope . accordions [ i ] . active = false ;
3433 }
3534 }
3635
@@ -43,8 +42,9 @@ angular.module('angularify.semantic.accordion', [])
4342
4443 this . remove_accordion = function ( scope ) {
4544 var index = $scope . accordions . indexOf ( scope ) ;
46- if ( index !== - 1 )
45+ if ( index !== - 1 ) {
4746 $scope . accordions . splice ( index , 1 ) ;
47+ }
4848 }
4949
5050 this . is_close_all = function ( ) {
@@ -85,47 +85,31 @@ angular.module('angularify.semantic.accordion', [])
8585 } ,
8686 require :'^accordion' ,
8787 template : "<div class=\"ui accordion\">\
88- <div class=\"{{ class}} \" ng-click=\"click_on_accordeon_tab ()\"> \
88+ <div class=\"title\" ng- class=\"{ active: active } \" ng-click=\"click_on_accordion_tab ()\"> \
8989 <i class=\"dropdown icon\"></i> \
9090 {{ title }} \
9191 </div> \
92- <div class=\"{{content_class} }\" ng-transclude> \
92+ <div class=\"content\" ng-class=\"{ active: active }\" ng-transclude> \
9393 </div> \
9494 </div>" ,
9595
9696 link : function ( scope , element , attrs , AccordionController ) {
97- scope . isOpen = attrs . open ;
98-
99- if ( scope . isOpen == undefined )
100- scope . isOpen = false ;
10197
10298 // set up active
103- if ( attrs . open === 'true' ) {
104- scope . class = 'active title' ;
105- scope . content_class = 'active content' ;
106- }
107- else {
108- scope . class = 'title' ;
109- scope . content_class = "content" ;
110- }
99+ scope . active = attrs . open === 'true' ;
111100
101+ // Add the accordion to the controller
112102 AccordionController . add_accordion ( scope ) ;
113103
114- //
115104 // Click handler
116- //
117- scope . click_on_accordeon_tab = function ( ) {
105+ scope . click_on_accordion_tab = function ( ) {
106+
118107 // class all first of all
119- AccordionController . closeAll ( scope )
120-
121- if ( scope . content_class == 'active content' ) {
122- scope . class = 'title' ;
123- scope . content_class = 'content' ;
124- } else {
125- scope . class = 'active title' ;
126- scope . content_class = 'active content' ;
127- }
108+ AccordionController . closeAll ( scope ) ;
109+
110+ // Swap the active state
111+ scope . active = ! scope . active ;
128112 }
129113 }
130114 }
131- } ) ;
115+ } ) ;
0 commit comments