mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Accordion: Renamed changestart and change events to beforeActivate and activate, respectively. Fixes #6840 - Accordion: Rename changestart event to beforeActivate. Fixes #6842 - Accordion: Rename change event to activate.
This commit is contained in:
parent
06d61f5f23
commit
088ef05142
@ -221,4 +221,94 @@ test( "{ navigation: true, navigationFilter: content }", function() {
|
|||||||
state( ac, 0, 0, 1 );
|
state( ac, 0, 0, 1 );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module( "accordion (deprecated) - changestart/change events", accordionSetupTeardown() );
|
||||||
|
|
||||||
|
test( "changestart", function() {
|
||||||
|
expect( 20 );
|
||||||
|
var ac = $( "#list1" ).accordion({
|
||||||
|
active: false,
|
||||||
|
collapsible: true
|
||||||
|
});
|
||||||
|
var headers = ac.find( ".ui-accordion-header" );
|
||||||
|
var content = ac.find( ".ui-accordion-content" );
|
||||||
|
|
||||||
|
ac.one( "accordionchangestart", function( event, ui ) {
|
||||||
|
equals( ui.oldHeader.size(), 0 );
|
||||||
|
equals( ui.oldContent.size(), 0 );
|
||||||
|
equals( ui.newHeader.size(), 1 );
|
||||||
|
strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
|
||||||
|
equals( ui.newContent.size(), 1 );
|
||||||
|
strictEqual( ui.newContent[ 0 ], content[ 0 ] );
|
||||||
|
});
|
||||||
|
ac.accordion( "option", "active", 0 );
|
||||||
|
|
||||||
|
ac.one( "accordionchangestart", function( event, ui ) {
|
||||||
|
equals( ui.oldHeader.size(), 1 );
|
||||||
|
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
|
||||||
|
equals( ui.oldContent.size(), 1 );
|
||||||
|
strictEqual( ui.oldContent[ 0 ], content[ 0 ] );
|
||||||
|
equals( ui.newHeader.size(), 1 );
|
||||||
|
strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
|
||||||
|
equals( ui.newContent.size(), 1 );
|
||||||
|
strictEqual( ui.newContent[ 0 ], content[ 1 ] );
|
||||||
|
});
|
||||||
|
headers.eq( 1 ).click();
|
||||||
|
|
||||||
|
ac.one( "accordionchangestart", function( event, ui ) {
|
||||||
|
equals( ui.oldHeader.size(), 1 );
|
||||||
|
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
|
||||||
|
equals( ui.oldContent.size(), 1 );
|
||||||
|
strictEqual( ui.oldContent[ 0 ], content[ 1 ] );
|
||||||
|
equals( ui.newHeader.size(), 0 );
|
||||||
|
equals( ui.newContent.size(), 0 );
|
||||||
|
});
|
||||||
|
ac.accordion( "option", "active", false );
|
||||||
|
});
|
||||||
|
|
||||||
|
test( "change", function() {
|
||||||
|
expect( 20 );
|
||||||
|
var ac = $( "#list1" ).accordion({
|
||||||
|
active: false,
|
||||||
|
collapsible: true
|
||||||
|
});
|
||||||
|
var headers = ac.find( ".ui-accordion-header" );
|
||||||
|
var content = ac.find( ".ui-accordion-content" );
|
||||||
|
|
||||||
|
ac.one( "accordionchange", function( event, ui ) {
|
||||||
|
equals( ui.oldHeader.size(), 0 );
|
||||||
|
equals( ui.oldContent.size(), 0 );
|
||||||
|
equals( ui.newHeader.size(), 1 );
|
||||||
|
strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
|
||||||
|
equals( ui.newContent.size(), 1 );
|
||||||
|
strictEqual( ui.newContent[ 0 ], content[ 0 ] );
|
||||||
|
});
|
||||||
|
ac.accordion( "option", "active", 0 );
|
||||||
|
|
||||||
|
ac.one( "accordionchange", function( event, ui ) {
|
||||||
|
equals( ui.oldHeader.size(), 1 );
|
||||||
|
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
|
||||||
|
equals( ui.oldContent.size(), 1 );
|
||||||
|
strictEqual( ui.oldContent[ 0 ], content[ 0 ] );
|
||||||
|
equals( ui.newHeader.size(), 1 );
|
||||||
|
strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
|
||||||
|
equals( ui.newContent.size(), 1 );
|
||||||
|
strictEqual( ui.newContent[ 0 ], content[ 1 ] );
|
||||||
|
});
|
||||||
|
headers.eq( 1 ).click();
|
||||||
|
|
||||||
|
ac.one( "accordionchange", function( event, ui ) {
|
||||||
|
equals( ui.oldHeader.size(), 1 );
|
||||||
|
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
|
||||||
|
equals( ui.oldContent.size(), 1 );
|
||||||
|
strictEqual( ui.oldContent[ 0 ], content[ 1 ] );
|
||||||
|
equals( ui.newHeader.size(), 0 );
|
||||||
|
equals( ui.newContent.size(), 0 );
|
||||||
|
});
|
||||||
|
ac.accordion( "option", "active", false );
|
||||||
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
module( "accordion: events", accordionSetupTeardown() );
|
module( "accordion: events", accordionSetupTeardown() );
|
||||||
|
|
||||||
test( "changestart", function() {
|
test( "beforeActivate", function() {
|
||||||
expect( 20 );
|
expect( 20 );
|
||||||
var ac = $( "#list1" ).accordion({
|
var ac = $( "#list1" ).accordion({
|
||||||
active: false,
|
active: false,
|
||||||
@ -11,7 +11,7 @@ test( "changestart", function() {
|
|||||||
var headers = ac.find( ".ui-accordion-header" );
|
var headers = ac.find( ".ui-accordion-header" );
|
||||||
var content = ac.find( ".ui-accordion-content" );
|
var content = ac.find( ".ui-accordion-content" );
|
||||||
|
|
||||||
ac.one( "accordionchangestart", function( event, ui ) {
|
ac.one( "accordionbeforeactivate", function( event, ui ) {
|
||||||
equals( ui.oldHeader.size(), 0 );
|
equals( ui.oldHeader.size(), 0 );
|
||||||
equals( ui.oldContent.size(), 0 );
|
equals( ui.oldContent.size(), 0 );
|
||||||
equals( ui.newHeader.size(), 1 );
|
equals( ui.newHeader.size(), 1 );
|
||||||
@ -21,7 +21,7 @@ test( "changestart", function() {
|
|||||||
});
|
});
|
||||||
ac.accordion( "option", "active", 0 );
|
ac.accordion( "option", "active", 0 );
|
||||||
|
|
||||||
ac.one( "accordionchangestart", function( event, ui ) {
|
ac.one( "accordionbeforeactivate", function( event, ui ) {
|
||||||
equals( ui.oldHeader.size(), 1 );
|
equals( ui.oldHeader.size(), 1 );
|
||||||
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
|
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
|
||||||
equals( ui.oldContent.size(), 1 );
|
equals( ui.oldContent.size(), 1 );
|
||||||
@ -33,7 +33,7 @@ test( "changestart", function() {
|
|||||||
});
|
});
|
||||||
headers.eq( 1 ).click();
|
headers.eq( 1 ).click();
|
||||||
|
|
||||||
ac.one( "accordionchangestart", function( event, ui ) {
|
ac.one( "accordionbeforeactivate", function( event, ui ) {
|
||||||
equals( ui.oldHeader.size(), 1 );
|
equals( ui.oldHeader.size(), 1 );
|
||||||
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
|
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
|
||||||
equals( ui.oldContent.size(), 1 );
|
equals( ui.oldContent.size(), 1 );
|
||||||
@ -44,7 +44,7 @@ test( "changestart", function() {
|
|||||||
ac.accordion( "option", "active", false );
|
ac.accordion( "option", "active", false );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "change", function() {
|
test( "activate", function() {
|
||||||
expect( 20 );
|
expect( 20 );
|
||||||
var ac = $( "#list1" ).accordion({
|
var ac = $( "#list1" ).accordion({
|
||||||
active: false,
|
active: false,
|
||||||
@ -53,7 +53,7 @@ test( "change", function() {
|
|||||||
var headers = ac.find( ".ui-accordion-header" );
|
var headers = ac.find( ".ui-accordion-header" );
|
||||||
var content = ac.find( ".ui-accordion-content" );
|
var content = ac.find( ".ui-accordion-content" );
|
||||||
|
|
||||||
ac.one( "accordionchange", function( event, ui ) {
|
ac.one( "accordionactivate", function( event, ui ) {
|
||||||
equals( ui.oldHeader.size(), 0 );
|
equals( ui.oldHeader.size(), 0 );
|
||||||
equals( ui.oldContent.size(), 0 );
|
equals( ui.oldContent.size(), 0 );
|
||||||
equals( ui.newHeader.size(), 1 );
|
equals( ui.newHeader.size(), 1 );
|
||||||
@ -63,7 +63,7 @@ test( "change", function() {
|
|||||||
});
|
});
|
||||||
ac.accordion( "option", "active", 0 );
|
ac.accordion( "option", "active", 0 );
|
||||||
|
|
||||||
ac.one( "accordionchange", function( event, ui ) {
|
ac.one( "accordionactivate", function( event, ui ) {
|
||||||
equals( ui.oldHeader.size(), 1 );
|
equals( ui.oldHeader.size(), 1 );
|
||||||
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
|
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
|
||||||
equals( ui.oldContent.size(), 1 );
|
equals( ui.oldContent.size(), 1 );
|
||||||
@ -75,7 +75,7 @@ test( "change", function() {
|
|||||||
});
|
});
|
||||||
headers.eq( 1 ).click();
|
headers.eq( 1 ).click();
|
||||||
|
|
||||||
ac.one( "accordionchange", function( event, ui ) {
|
ac.one( "accordionactivate", function( event, ui ) {
|
||||||
equals( ui.oldHeader.size(), 1 );
|
equals( ui.oldHeader.size(), 1 );
|
||||||
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
|
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
|
||||||
equals( ui.oldContent.size(), 1 );
|
equals( ui.oldContent.size(), 1 );
|
||||||
|
@ -34,12 +34,14 @@ var privateMethods = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function testWidgetOverrides( widget ) {
|
function testWidgetOverrides( widget ) {
|
||||||
test( "$.widget overrides", function() {
|
if ( $.uiBackCompat === false ) {
|
||||||
$.each( privateMethods, function( i, method ) {
|
test( "$.widget overrides", function() {
|
||||||
strictEqual( $.ui[ widget ].prototype[ method ],
|
$.each( privateMethods, function( i, method ) {
|
||||||
$.Widget.prototype[ method ], "should not override " + method );
|
strictEqual( $.ui[ widget ].prototype[ method ],
|
||||||
|
$.Widget.prototype[ method ], "should not override " + method );
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testBasicUsage( widget ) {
|
function testBasicUsage( widget ) {
|
||||||
|
22
ui/jquery.ui.accordion.js
vendored
22
ui/jquery.ui.accordion.js
vendored
@ -381,8 +381,7 @@ $.widget( "ui.accordion", {
|
|||||||
return self._completed.apply( self, arguments );
|
return self._completed.apply( self, arguments );
|
||||||
};
|
};
|
||||||
|
|
||||||
// trigger changestart event
|
self._trigger( "beforeActivate", null, self.data );
|
||||||
self._trigger( "changestart", null, self.data );
|
|
||||||
|
|
||||||
// count elements to animate
|
// count elements to animate
|
||||||
self.running = toHide.size() === 0 ? toShow.size() : toHide.size();
|
self.running = toHide.size() === 0 ? toShow.size() : toHide.size();
|
||||||
@ -487,7 +486,7 @@ $.widget( "ui.accordion", {
|
|||||||
this.toHide.parent()[0].className = this.toHide.parent()[0].className;
|
this.toHide.parent()[0].className = this.toHide.parent()[0].className;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._trigger( "change", null, this.data );
|
this._trigger( "activate", null, this.data );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -711,6 +710,23 @@ if ( $.uiBackCompat !== false ) {
|
|||||||
|
|
||||||
// resize method
|
// resize method
|
||||||
jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh;
|
jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh;
|
||||||
|
|
||||||
|
(function( $, prototype ) {
|
||||||
|
var _trigger = prototype._trigger;
|
||||||
|
prototype._trigger = function( type, event, data ) {
|
||||||
|
var ret = _trigger.apply( this, arguments );
|
||||||
|
if ( !ret ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type === "beforeActivate" ) {
|
||||||
|
ret = _trigger.call( this, "changestart", event, data );
|
||||||
|
} else if ( type === "activate" ) {
|
||||||
|
ret = _trigger.call( this, "change", event, data );
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}( jQuery, jQuery.ui.accordion.prototype ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
Loading…
Reference in New Issue
Block a user