Accordion: Update activate and beforeActivate event properties to newPanel/oldPanel (instead of content). Fixes #6840 and #6842

This commit is contained in:
Jörn Zaefferer 2012-05-30 14:40:03 +02:00
parent f5954fcd74
commit e0fe788ee0
2 changed files with 40 additions and 30 deletions

View File

@ -56,11 +56,11 @@ test( "beforeActivate", function() {
element.one( "accordionbeforeactivate", function( event, ui ) { element.one( "accordionbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ) ); ok( !( "originalEvent" in event ) );
equal( ui.oldHeader.length, 0 ); equal( ui.oldHeader.length, 0 );
equal( ui.oldContent.length, 0 ); equal( ui.oldPanel.length, 0 );
equal( ui.newHeader.length, 1 ); equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
equal( ui.newContent.length, 1 ); equal( ui.newPanel.length, 1 );
strictEqual( ui.newContent[ 0 ], content[ 0 ] ); strictEqual( ui.newPanel[ 0 ], content[ 0 ] );
state( element, 0, 0, 0 ); state( element, 0, 0, 0 );
}); });
element.accordion( "option", "active", 0 ); element.accordion( "option", "active", 0 );
@ -70,12 +70,12 @@ test( "beforeActivate", function() {
equal( event.originalEvent.type, "click" ); equal( event.originalEvent.type, "click" );
equal( ui.oldHeader.length, 1 ); equal( ui.oldHeader.length, 1 );
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
equal( ui.oldContent.length, 1 ); equal( ui.oldPanel.length, 1 );
strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); strictEqual( ui.oldPanel[ 0 ], content[ 0 ] );
equal( ui.newHeader.length, 1 ); equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
equal( ui.newContent.length, 1 ); equal( ui.newPanel.length, 1 );
strictEqual( ui.newContent[ 0 ], content[ 1 ] ); strictEqual( ui.newPanel[ 0 ], content[ 1 ] );
state( element, 1, 0, 0 ); state( element, 1, 0, 0 );
}); });
headers.eq( 1 ).click(); headers.eq( 1 ).click();
@ -85,10 +85,10 @@ test( "beforeActivate", function() {
ok( !( "originalEvent" in event ) ); ok( !( "originalEvent" in event ) );
equal( ui.oldHeader.length, 1 ); equal( ui.oldHeader.length, 1 );
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
equal( ui.oldContent.length, 1 ); equal( ui.oldPanel.length, 1 );
strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); strictEqual( ui.oldPanel[ 0 ], content[ 1 ] );
equal( ui.newHeader.length, 0 ); equal( ui.newHeader.length, 0 );
equal( ui.newContent.length, 0 ); equal( ui.newPanel.length, 0 );
state( element, 0, 1, 0 ); state( element, 0, 1, 0 );
}); });
element.accordion( "option", "active", false ); element.accordion( "option", "active", false );
@ -97,11 +97,11 @@ test( "beforeActivate", function() {
element.one( "accordionbeforeactivate", function( event, ui ) { element.one( "accordionbeforeactivate", function( event, ui ) {
ok( !( "originalEvent" in event ) ); ok( !( "originalEvent" in event ) );
equal( ui.oldHeader.length, 0 ); equal( ui.oldHeader.length, 0 );
equal( ui.oldContent.length, 0 ); equal( ui.oldPanel.length, 0 );
equal( ui.newHeader.length, 1 ); equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 2 ] ); strictEqual( ui.newHeader[ 0 ], headers[ 2 ] );
equal( ui.newContent.length, 1 ); equal( ui.newPanel.length, 1 );
strictEqual( ui.newContent[ 0 ], content[ 2 ] ); strictEqual( ui.newPanel[ 0 ], content[ 2 ] );
event.preventDefault(); event.preventDefault();
state( element, 0, 0, 0 ); state( element, 0, 0, 0 );
}); });
@ -120,33 +120,33 @@ test( "activate", function() {
element.one( "accordionactivate", function( event, ui ) { element.one( "accordionactivate", function( event, ui ) {
equal( ui.oldHeader.length, 0 ); equal( ui.oldHeader.length, 0 );
equal( ui.oldContent.length, 0 ); equal( ui.oldPanel.length, 0 );
equal( ui.newHeader.length, 1 ); equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
equal( ui.newContent.length, 1 ); equal( ui.newPanel.length, 1 );
strictEqual( ui.newContent[ 0 ], content[ 0 ] ); strictEqual( ui.newPanel[ 0 ], content[ 0 ] );
}); });
element.accordion( "option", "active", 0 ); element.accordion( "option", "active", 0 );
element.one( "accordionactivate", function( event, ui ) { element.one( "accordionactivate", function( event, ui ) {
equal( ui.oldHeader.length, 1 ); equal( ui.oldHeader.length, 1 );
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
equal( ui.oldContent.length, 1 ); equal( ui.oldPanel.length, 1 );
strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); strictEqual( ui.oldPanel[ 0 ], content[ 0 ] );
equal( ui.newHeader.length, 1 ); equal( ui.newHeader.length, 1 );
strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
equal( ui.newContent.length, 1 ); equal( ui.newPanel.length, 1 );
strictEqual( ui.newContent[ 0 ], content[ 1 ] ); strictEqual( ui.newPanel[ 0 ], content[ 1 ] );
}); });
headers.eq( 1 ).click(); headers.eq( 1 ).click();
element.one( "accordionactivate", function( event, ui ) { element.one( "accordionactivate", function( event, ui ) {
equal( ui.oldHeader.length, 1 ); equal( ui.oldHeader.length, 1 );
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
equal( ui.oldContent.length, 1 ); equal( ui.oldPanel.length, 1 );
strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); strictEqual( ui.oldPanel[ 0 ], content[ 1 ] );
equal( ui.newHeader.length, 0 ); equal( ui.newHeader.length, 0 );
equal( ui.newContent.length, 0 ); equal( ui.newPanel.length, 0 );
}); });
element.accordion( "option", "active", false ); element.accordion( "option", "active", false );

View File

@ -389,9 +389,9 @@ $.widget( "ui.accordion", {
toHide = active.next(), toHide = active.next(),
eventData = { eventData = {
oldHeader: active, oldHeader: active,
oldContent: toHide, oldPanel: toHide,
newHeader: collapsing ? $() : clicked, newHeader: collapsing ? $() : clicked,
newContent: toShow newPanel: toShow
}; };
event.preventDefault(); event.preventDefault();
@ -437,8 +437,8 @@ $.widget( "ui.accordion", {
}, },
_toggle: function( data ) { _toggle: function( data ) {
var toShow = data.newContent, var toShow = data.newPanel,
toHide = this.prevShow.length ? this.prevShow : data.oldContent; toHide = this.prevShow.length ? this.prevShow : data.oldPanel;
// handle activating a panel during the animation for another activation // handle activating a panel during the animation for another activation
this.prevShow.add( this.prevHide ).stop( true, true ); this.prevShow.add( this.prevHide ).stop( true, true );
@ -524,7 +524,7 @@ $.widget( "ui.accordion", {
}, },
_toggleComplete: function( data ) { _toggleComplete: function( data ) {
var toHide = data.oldContent; var toHide = data.oldPanel;
toHide toHide
.removeClass( "ui-accordion-content-active" ) .removeClass( "ui-accordion-content-active" )
@ -676,9 +676,19 @@ if ( $.uiBackCompat !== false ) {
} }
if ( type === "beforeActivate" ) { if ( type === "beforeActivate" ) {
ret = _trigger.call( this, "changestart", event, data ); ret = _trigger.call( this, "changestart", event, {
oldHeader: data.oldHeader,
oldContent: data.oldPanel,
newHeader: data.newHeader,
newContent: data.newPanel
});
} else if ( type === "activate" ) { } else if ( type === "activate" ) {
ret = _trigger.call( this, "change", event, data ); ret = _trigger.call( this, "change", event, {
oldHeader: data.oldHeader,
oldContent: data.oldPanel,
newHeader: data.newHeader,
newContent: data.newPanel
});
} }
return ret; return ret;
}; };