]> source.dussan.org Git - jquery-ui.git/commitdiff
Accordion: Handle changing the event option. Fixes #6740 - Dynamically changing accor...
authorScott González <scott.gonzalez@gmail.com>
Mon, 21 Feb 2011 15:07:42 +0000 (16:07 +0100)
committerScott González <scott.gonzalez@gmail.com>
Mon, 21 Feb 2011 15:07:59 +0000 (16:07 +0100)
tests/unit/accordion/accordion_options.js
ui/jquery.ui.accordion.js

index f27431a500c3978409dda9ff80e4f5c25864be83..42cbb495c711374bc54984960b31323221c08073 100644 (file)
@@ -105,7 +105,52 @@ test( "{ collapsible: true }", function() {
        state( ac, 0, 0, 0 );
 });
 
-// TODO: add event tests
+test( "{ event: null }", function() {
+       var ac = $( "#list1" ).accordion({
+               event: null
+       });
+       state( ac, 1, 0, 0 );
+
+       ac.accordion( "option", "active", 1 );
+       equal( ac.accordion( "option", "active" ), 1 );
+       state( ac, 0, 1, 0 );
+
+       // ensure default click handler isn't bound
+       ac.find( ".ui-accordion-header" ).eq( 2 ).click();
+       equal( ac.accordion( "option", "active" ), 1 );
+       state( ac, 0, 1, 0 );
+});
+
+test( "{ event: custom }", function() {
+       var ac = $( "#list1" ).accordion({
+               event: "custom1 custom2"
+       });
+       state( ac, 1, 0, 0 );
+
+       ac.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" );
+       equal( ac.accordion( "option", "active" ), 1 );
+       state( ac, 0, 1, 0 );
+
+       // ensure default click handler isn't bound
+       ac.find( ".ui-accordion-header" ).eq( 2 ).trigger( "click" );
+       equal( ac.accordion( "option", "active" ), 1 );
+       state( ac, 0, 1, 0 );
+
+       ac.find( ".ui-accordion-header" ).eq( 2 ).trigger( "custom2" );
+       equal( ac.accordion( "option", "active" ), 2 );
+       state( ac, 0, 0, 1 );
+
+       ac.accordion( "option", "event", "custom3" );
+
+       // ensure old event handlers are unbound
+       ac.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" );
+       equal( ac.accordion( "option", "active" ), 2 );
+       state( ac, 0, 0, 1 );
+
+       ac.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom3" );
+       equal( ac.accordion( "option", "active" ), 1 );
+       state( ac, 0, 1, 0 );
+});
 
 test( "{ header: default }", function() {
        // default: > li > :first-child,> :not(li):even
index 1c30ba89b3a19fe7e763fba57ea00a6c25e8ad85..8049868e876f2bc5b73152e8b789757bc9c998f8 100644 (file)
@@ -96,10 +96,7 @@ $.widget( "ui.accordion", {
                        self.headers.find( "a" ).attr( "tabIndex", -1 );
                }
 
-               if ( options.event ) {
-                       self.headers.bind( options.event.split( " " ).join( ".accordion " ) + ".accordion",
-                               $.proxy( self, "_eventHandler" ) );
-               }
+               this._setupEvents( options.event );
        },
 
        _createIcons: function() {
@@ -164,6 +161,10 @@ $.widget( "ui.accordion", {
                        this._activate( 0 );
                }
 
+               if ( key === "event" ) {
+                       this._setupEvents( value );
+               }
+
                if ( key === "icons" ) {
                        this._destroyIcons();
                        if ( value ) {
@@ -284,6 +285,14 @@ $.widget( "ui.accordion", {
                return typeof selector === "number" ? this.headers.eq( selector ) : $();
        },
 
+       _setupEvents: function( event ) {
+               this.headers.unbind( ".accordion" );
+               if ( event ) {
+                       this.headers.bind( event.split( " " ).join( ".accordion " ) + ".accordion",
+                               $.proxy( this, "_eventHandler" ) );
+               }
+       },
+
        _eventHandler: function( event ) {
                var options = this.options,
                        active = this.active,