@@ -173,11 +173,14 @@ $.widget( "ui.accordion", {
173
173
} ,
174
174
175
175
_setOption : function ( key , value ) {
176
- $ . Widget . prototype . _setOption . apply ( this , arguments ) ;
177
-
178
176
if ( key == "active" ) {
177
+ // _activate() will handle invalid values and update this.options
179
178
this . _activate ( value ) ;
179
+ return ;
180
180
}
181
+
182
+ $ . Widget . prototype . _setOption . apply ( this , arguments ) ;
183
+
181
184
if ( key == "icons" ) {
182
185
this . _destroyIcons ( ) ;
183
186
if ( value ) {
@@ -273,20 +276,28 @@ $.widget( "ui.accordion", {
273
276
} ,
274
277
275
278
_activate : function ( index ) {
276
- // TODO: handle invalid values
277
- this . options . active = index ;
278
279
var active = this . _findActive ( index ) [ 0 ] ;
280
+ if ( ! active ) {
281
+ if ( ! this . options . collapsible ) {
282
+ return ;
283
+ }
284
+ index = false ;
285
+ }
286
+ this . options . active = index ;
279
287
this . _eventHandler ( { target : active , currentTarget : active } ) ;
280
288
} ,
281
289
282
290
_findActive : function ( selector ) {
283
- return selector
284
- ? typeof selector === "number"
285
- ? this . headers . filter ( ":eq(" + selector + ")" )
286
- : this . headers . not ( this . headers . not ( selector ) )
287
- : selector === false
288
- ? $ ( [ ] )
289
- : this . headers . filter ( ":eq(0)" ) ;
291
+ // handle -1 separately, we should drop support for this
292
+ // so that we can allow selecting via negative index, like .eq()
293
+ if ( selector === - 1 ) {
294
+ selector = undefined ;
295
+ }
296
+ return typeof selector === "number" ?
297
+ this . headers . eq ( selector ) :
298
+ selector ?
299
+ this . headers . filter ( selector ) :
300
+ $ ( [ ] ) ;
290
301
} ,
291
302
292
303
_eventHandler : function ( event ) {
0 commit comments