1
1
angular . module ( 'ui.bootstrap.accordion' , [ 'ui.bootstrap.collapse' ] )
2
2
3
- . constant ( 'accordionConfig ' , {
3
+ . constant ( 'uibAccordionConfig ' , {
4
4
closeOthers : true
5
5
} )
6
6
7
- . controller ( 'AccordionController ' , [ '$scope' , '$attrs' , 'accordionConfig ' , function ( $scope , $attrs , accordionConfig ) {
7
+ . controller ( 'UibAccordionController ' , [ '$scope' , '$attrs' , 'uibAccordionConfig ' , function ( $scope , $attrs , accordionConfig ) {
8
8
// This array keeps track of the accordion groups
9
9
this . groups = [ ] ;
10
10
@@ -43,10 +43,10 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
43
43
44
44
// The accordion directive simply sets up the directive controller
45
45
// and adds an accordion CSS class to itself element.
46
- . directive ( 'accordion ' , function ( ) {
46
+ . directive ( 'uibAccordion ' , function ( ) {
47
47
return {
48
48
restrict : 'EA' ,
49
- controller : 'AccordionController ' ,
49
+ controller : 'UibAccordionController ' ,
50
50
controllerAs : 'accordion' ,
51
51
transclude : true ,
52
52
replace : false ,
@@ -57,9 +57,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
57
57
} )
58
58
59
59
// The accordion-group directive indicates a block of html that will expand and collapse in an accordion
60
- . directive ( 'accordionGroup ' , function ( ) {
60
+ . directive ( 'uibAccordionGroup ' , function ( ) {
61
61
return {
62
- require : '^accordion ' , // We need this directive to be inside an accordion
62
+ require : '^uibAccordion ' , // We need this directive to be inside an accordion
63
63
restrict : 'EA' ,
64
64
transclude : true , // It transcludes the contents of the directive into the template
65
65
replace : true , // The element containing the directive will be replaced with the template
@@ -103,13 +103,13 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
103
103
// <accordion-group>
104
104
// <accordion-heading>Heading containing HTML - <img src="..."></accordion-heading>
105
105
// </accordion-group>
106
- . directive ( 'accordionHeading ' , function ( ) {
106
+ . directive ( 'uibAccordionHeading ' , function ( ) {
107
107
return {
108
108
restrict : 'EA' ,
109
109
transclude : true , // Grab the contents to be used as the heading
110
110
template : '' , // In effect remove this element!
111
111
replace : true ,
112
- require : '^accordionGroup ' ,
112
+ require : '^uibAccordionGroup ' ,
113
113
link : function ( scope , element , attr , accordionGroupCtrl , transclude ) {
114
114
// Pass the heading to the accordion-group controller
115
115
// so that it can be transcluded into the right place in the template
@@ -125,18 +125,125 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
125
125
// <div class="accordion-heading" ><a ... accordion-transclude="heading">...</a></div>
126
126
// ...
127
127
// </div>
128
- . directive ( 'accordionTransclude ' , function ( ) {
128
+ . directive ( 'uibAccordionTransclude ' , function ( ) {
129
129
return {
130
- require : '^ accordionGroup',
130
+ require : [ '?^uibAccordionGroup' , '?^ accordionGroup'] ,
131
131
link : function ( scope , element , attr , controller ) {
132
- scope . $watch ( function ( ) { return controller [ attr . accordionTransclude ] ; } , function ( heading ) {
132
+ controller = controller [ 0 ] ? controller [ 0 ] : controller [ 1 ] ; // Delete after we remove deprecation
133
+ scope . $watch ( function ( ) { return controller [ attr . uibAccordionTransclude ] ; } , function ( heading ) {
133
134
if ( heading ) {
134
135
element . find ( 'span' ) . html ( '' ) ;
135
136
element . find ( 'span' ) . append ( heading ) ;
136
137
}
137
138
} ) ;
138
139
}
139
140
} ;
140
- } )
141
+ } ) ;
142
+
143
+ /* Deprecated accordion below */
144
+
145
+ angular . module ( 'ui.bootstrap.accordion' )
146
+
147
+ . value ( '$accordionSuppressWarning' , false )
148
+
149
+ . directive ( 'accordion' , [ '$log' , '$accordionSuppressWarning' , function ( $log , $accordionSuppressWarning ) {
150
+ return {
151
+ restrict : 'EA' ,
152
+ controller : 'UibAccordionController' ,
153
+ controllerAs : 'accordion' ,
154
+ transclude : true ,
155
+ replace : false ,
156
+ templateUrl : function ( element , attrs ) {
157
+ return attrs . templateUrl || 'template/accordion/accordion.html' ;
158
+ } ,
159
+ link : function ( ) {
160
+ if ( ! $accordionSuppressWarning ) {
161
+ $log . warn ( 'accordion is now deprecated. Use uib-accordion instead.' ) ;
162
+ }
163
+ }
164
+ } ;
165
+ } ] )
166
+
167
+ . directive ( 'accordionGroup' , [ '$log' , '$accordionSuppressWarning' , function ( $log , $accordionSuppressWarning ) {
168
+ return {
169
+ require : '^accordion' , // We need this directive to be inside an accordion
170
+ restrict : 'EA' ,
171
+ transclude : true , // It transcludes the contents of the directive into the template
172
+ replace : true , // The element containing the directive will be replaced with the template
173
+ templateUrl : function ( element , attrs ) {
174
+ return attrs . templateUrl || 'template/accordion/accordion-group.html' ;
175
+ } ,
176
+ scope : {
177
+ heading : '@' , // Interpolate the heading attribute onto this scope
178
+ isOpen : '=?' ,
179
+ isDisabled : '=?'
180
+ } ,
181
+ controller : function ( ) {
182
+ this . setHeading = function ( element ) {
183
+ this . heading = element ;
184
+ } ;
185
+ } ,
186
+ link : function ( scope , element , attrs , accordionCtrl ) {
187
+ if ( ! $accordionSuppressWarning ) {
188
+ $log . warn ( 'accordion-group is now deprecated. Use uib-accordion-group instead.' ) ;
189
+ }
190
+
191
+ accordionCtrl . addGroup ( scope ) ;
192
+
193
+ scope . openClass = attrs . openClass || 'panel-open' ;
194
+ scope . panelClass = attrs . panelClass ;
195
+ scope . $watch ( 'isOpen' , function ( value ) {
196
+ element . toggleClass ( scope . openClass , ! ! value ) ;
197
+ if ( value ) {
198
+ accordionCtrl . closeOthers ( scope ) ;
199
+ }
200
+ } ) ;
201
+
202
+ scope . toggleOpen = function ( $event ) {
203
+ if ( ! scope . isDisabled ) {
204
+ if ( ! $event || $event . which === 32 ) {
205
+ scope . isOpen = ! scope . isOpen ;
206
+ }
207
+ }
208
+ } ;
209
+ }
210
+ } ;
211
+ } ] )
212
+
213
+ . directive ( 'accordionHeading' , [ '$log' , '$accordionSuppressWarning' , function ( $log , $accordionSuppressWarning ) {
214
+ return {
215
+ restrict : 'EA' ,
216
+ transclude : true , // Grab the contents to be used as the heading
217
+ template : '' , // In effect remove this element!
218
+ replace : true ,
219
+ require : '^accordionGroup' ,
220
+ link : function ( scope , element , attr , accordionGroupCtrl , transclude ) {
221
+ if ( ! $accordionSuppressWarning ) {
222
+ $log . warn ( 'accordion-heading is now deprecated. Use uib-accordion-heading instead.' ) ;
223
+ }
224
+ // Pass the heading to the accordion-group controller
225
+ // so that it can be transcluded into the right place in the template
226
+ // [The second parameter to transclude causes the elements to be cloned so that they work in ng-repeat]
227
+ accordionGroupCtrl . setHeading ( transclude ( scope , angular . noop ) ) ;
228
+ }
229
+ } ;
230
+ } ] )
231
+
232
+ . directive ( 'accordionTransclude' , [ '$log' , '$accordionSuppressWarning' , function ( $log , $accordionSuppressWarning ) {
233
+ return {
234
+ require : '^accordionGroup' ,
235
+ link : function ( scope , element , attr , controller ) {
236
+ if ( ! $accordionSuppressWarning ) {
237
+ $log . warn ( 'accordion-transclude is now deprecated. Use uib-accordion-transclude instead.' ) ;
238
+ }
239
+
240
+ scope . $watch ( function ( ) { return controller [ attr . accordionTransclude ] ; } , function ( heading ) {
241
+ if ( heading ) {
242
+ element . find ( 'span' ) . html ( '' ) ;
243
+ element . find ( 'span' ) . append ( heading ) ;
244
+ }
245
+ } ) ;
246
+ }
247
+ } ;
248
+ } ] ) ;
141
249
142
- ;
0 commit comments