File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,20 @@ test("{ active: false }", function() {
3838} ) ;
3939
4040test ( "{ active: Number }" , function ( ) {
41- ok ( false , 'missing test - untested code is broken code' ) ;
41+ expect ( 4 ) ;
42+ $ ( "#list1" ) . accordion ( {
43+ active : 0
44+ } ) ;
45+ equals ( $ ( "#list1" ) . accordion ( 'option' , 'active' ) , 0 ) ;
46+
47+ $ ( "#list1" ) . accordion ( 'option' , 'active' , 1 ) ;
48+ equals ( $ ( "#list1" ) . accordion ( 'option' , 'active' ) , 1 ) ;
49+
50+ $ ( '.ui-accordion-header:eq(2)' , '#list1' ) . click ( ) ;
51+ equals ( $ ( "#list1" ) . accordion ( 'option' , 'active' ) , 2 ) ;
52+
53+ $ ( "#list1" ) . accordion ( 'activate' , 0 ) ;
54+ equals ( $ ( "#list1" ) . accordion ( 'option' , 'active' ) , 0 ) ;
4255} ) ;
4356
4457test ( "{ animated: false }, default" , function ( ) {
Original file line number Diff line number Diff line change @@ -153,6 +153,9 @@ $.widget("ui.accordion", {
153153
154154 $ . widget . prototype . _setData . apply ( this , arguments ) ;
155155
156+ if ( key == "active" ) {
157+ this . activate ( value ) ;
158+ }
156159 if ( key == "icons" ) {
157160 this . _destroyIcons ( ) ;
158161 if ( value ) {
@@ -230,6 +233,7 @@ $.widget("ui.accordion", {
230233 } ,
231234
232235 activate : function ( index ) {
236+ this . options . active = index ;
233237 // call clickHandler with custom event
234238 var active = this . _findActive ( index ) [ 0 ] ;
235239 this . _clickHandler ( { target : active } , active ) ;
@@ -273,6 +277,8 @@ $.widget("ui.accordion", {
273277 // get the click target
274278 var clicked = $ ( event . currentTarget || target ) ;
275279 var clickedIsActive = clicked [ 0 ] == this . active [ 0 ] ;
280+
281+ o . active = $ ( '.ui-accordion-header' , this . element ) . index ( clicked ) ;
276282
277283 // if animations are still active, or the active header is the target, ignore click
278284 if ( this . running || ( ! o . collapsible && clickedIsActive ) ) {
You can’t perform that action at this time.
0 commit comments