Merge branch 'accordion-cleanup'

This commit is contained in:
Jörn Zaefferer 2012-03-18 15:46:11 +01:00
commit 6de8030f01
4 changed files with 19 additions and 14 deletions

View File

@ -10,15 +10,19 @@ test( "destroy", function() {
}); });
test( "enable/disable", function() { test( "enable/disable", function() {
expect( 3 ); expect( 4 );
var element = $( "#list1" ).accordion(); var element = $( "#list1" ).accordion();
accordion_state( element, 1, 0, 0 ); accordion_state( element, 1, 0, 0 );
element.accordion( "disable" ); element.accordion( "disable" );
element.accordion( "option", "active", 1 ); // event does nothing
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "click" );
accordion_state( element, 1, 0, 0 ); accordion_state( element, 1, 0, 0 );
element.accordion( "enable" ); // option still works
element.accordion( "option", "active", 1 ); element.accordion( "option", "active", 1 );
accordion_state( element, 0, 1, 0 ); accordion_state( element, 0, 1, 0 );
element.accordion( "enable" );
element.accordion( "option", "active", 2 );
accordion_state( element, 0, 0, 1 );
}); });
test( "refresh", function() { test( "refresh", function() {

View File

@ -152,6 +152,7 @@ test( "{ event: custom }", function() {
// ensure old event handlers are unbound // ensure old event handlers are unbound
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" ); element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" );
element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom2" );
equal( element.accordion( "option", "active" ), 2 ); equal( element.accordion( "option", "active" ), 2 );
accordion_state( element, 0, 0, 1 ); accordion_state( element, 0, 0, 1 );

View File

@ -3,7 +3,7 @@ function accordion_state( accordion ) {
var actual = accordion.find( ".ui-accordion-content" ).map(function() { var actual = accordion.find( ".ui-accordion-content" ).map(function() {
return $( this ).css( "display" ) === "none" ? 0 : 1; return $( this ).css( "display" ) === "none" ? 0 : 1;
}).get(); }).get();
deepEqual( actual, expected ); QUnit.push( QUnit.equiv(actual, expected), actual, expected );
} }
function accordion_equalHeights( accordion, min, max ) { function accordion_equalHeights( accordion, min, max ) {

View File

@ -68,8 +68,6 @@ $.widget( "ui.accordion", {
this.headers this.headers
.attr( "role", "tab" ) .attr( "role", "tab" )
// TODO: use _bind()
.bind( "keydown.accordion", $.proxy( this, "_keydown" ) )
.next() .next()
.attr( "role", "tabpanel" ); .attr( "role", "tabpanel" );
@ -161,8 +159,7 @@ $.widget( "ui.accordion", {
if ( key === "event" ) { if ( key === "event" ) {
if ( this.options.event ) { if ( this.options.event ) {
// TODO: this is incorrect for multiple events (see _setupEvents) this.headers.unbind( ".accordion" );
this.headers.unbind( this.options.event + ".accordion", this._eventHandler );
} }
this._setupEvents( value ); this._setupEvents( value );
} }
@ -190,8 +187,7 @@ $.widget( "ui.accordion", {
}, },
_keydown: function( event ) { _keydown: function( event ) {
// TODO: remove disabled check when using _bind() if ( event.altKey || event.ctrlKey ) {
if ( this.options.disabled || event.altKey || event.ctrlKey ) {
return; return;
} }
@ -300,11 +296,15 @@ $.widget( "ui.accordion", {
}, },
_setupEvents: function( event ) { _setupEvents: function( event ) {
var events = {
keydown: "_keydown"
};
if ( event ) { if ( event ) {
// TODO: use _bind() $.each( event.split(" "), function( index, eventName ) {
this.headers.bind( event.split( " " ).join( ".accordion " ) + ".accordion", events[ eventName ] = "_eventHandler";
$.proxy( this, "_eventHandler" ) ); });
} }
this._bind( this.headers, events );
}, },
_eventHandler: function( event ) { _eventHandler: function( event ) {
@ -324,7 +324,7 @@ $.widget( "ui.accordion", {
event.preventDefault(); event.preventDefault();
if ( options.disabled || if (
// click on active header, but not collapsible // click on active header, but not collapsible
( clickedIsActive && !options.collapsible ) || ( clickedIsActive && !options.collapsible ) ||
// allow canceling activation // allow canceling activation