aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.accordion.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-01-11 21:24:41 -0500
committerScott González <scott.gonzalez@gmail.com>2011-01-11 21:24:41 -0500
commit368af59137f3dcfd7916a043868c0f1827f761fb (patch)
tree7ea16c9b30b3b0cb035dd6ad0c3c99f32fa69300 /ui/jquery.ui.accordion.js
parent8b23483c0b03369dbfc9720e2aff8de690a3b854 (diff)
downloadjquery-ui-368af59137f3dcfd7916a043868c0f1827f761fb.tar.gz
jquery-ui-368af59137f3dcfd7916a043868c0f1827f761fb.zip
Accordion: Handle invalid values for the active option.
Diffstat (limited to 'ui/jquery.ui.accordion.js')
-rw-r--r--ui/jquery.ui.accordion.js33
1 files changed, 22 insertions, 11 deletions
diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js
index e58c5d621..e0acd76a8 100644
--- a/ui/jquery.ui.accordion.js
+++ b/ui/jquery.ui.accordion.js
@@ -173,11 +173,14 @@ $.widget( "ui.accordion", {
},
_setOption: function( key, value ) {
- $.Widget.prototype._setOption.apply( this, arguments );
-
if ( key == "active" ) {
+ // _activate() will handle invalid values and update this.options
this._activate( value );
+ return;
}
+
+ $.Widget.prototype._setOption.apply( this, arguments );
+
if ( key == "icons" ) {
this._destroyIcons();
if ( value ) {
@@ -273,20 +276,28 @@ $.widget( "ui.accordion", {
},
_activate: function( index ) {
- // TODO: handle invalid values
- this.options.active = index;
var active = this._findActive( index )[ 0 ];
+ if ( !active ) {
+ if ( !this.options.collapsible ) {
+ return;
+ }
+ index = false;
+ }
+ this.options.active = index;
this._eventHandler( { target: active, currentTarget: active } );
},
_findActive: function( selector ) {
- return selector
- ? typeof selector === "number"
- ? this.headers.filter( ":eq(" + selector + ")" )
- : this.headers.not( this.headers.not( selector ) )
- : selector === false
- ? $( [] )
- : this.headers.filter( ":eq(0)" );
+ // handle -1 separately, we should drop support for this
+ // so that we can allow selecting via negative index, like .eq()
+ if ( selector === -1 ) {
+ selector = undefined;
+ }
+ return typeof selector === "number" ?
+ this.headers.eq( selector ) :
+ selector ?
+ this.headers.filter( selector ) :
+ $( [] );
},
_eventHandler: function( event ) {