diff options
-rw-r--r-- | tests/unit/accordion/accordion_options.js | 7 | ||||
-rw-r--r-- | ui/jquery.ui.accordion.js | 4 |
2 files changed, 7 insertions, 4 deletions
diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index 71154d57a..9aa7e6e76 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -51,12 +51,11 @@ test( "{ active: Number }", function() { if ( $.uiBackCompat === false ) { test( "{ active: -Number }", function() { - // TODO: fix initializing with negative value var ac = $( "#list1" ).accordion({ -// active: -1 + active: -1 }); -// equals( ac.accordion( "option", "active" ), 2 ); -// state( ac, 0, 0, 1 ); + equals( ac.accordion( "option", "active" ), 2 ); + state( ac, 0, 0, 1 ); ac.accordion( "option", "active", -2 ); equals( ac.accordion( "option", "active" ), 1 ); diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index 33c3a8505..71e3b44b4 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -48,6 +48,10 @@ $.widget( "ui.accordion", { if ( !options.collapsible && options.active === false ) { options.active = 0; } + // handle negative values + if ( options.active < 0 ) { + options.active += this.headers.length; + } self.active = self._findActive( options.active ) .addClass( "ui-state-default ui-state-active" ) .toggleClass( "ui-corner-all" ) |