mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Tabs: Fixed select event.
This commit is contained in:
parent
7fddb1c5b5
commit
85ac420a1e
@ -267,7 +267,7 @@ test( "show", function() {
|
|||||||
ok( !( "originalEvent" in event ), "originalEvent" );
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
||||||
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
|
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
|
||||||
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
|
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
|
||||||
equal( ui.index, 0 );
|
equal( ui.index, 0, "ui.index" );
|
||||||
tabs_state( element, 1, 0, 0 );
|
tabs_state( element, 1, 0, 0 );
|
||||||
});
|
});
|
||||||
element.tabs( "option", "active", 0 );
|
element.tabs( "option", "active", 0 );
|
||||||
@ -278,7 +278,7 @@ test( "show", function() {
|
|||||||
equals( event.originalEvent.type, "click", "originalEvent" );
|
equals( event.originalEvent.type, "click", "originalEvent" );
|
||||||
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
|
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
|
||||||
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
|
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
|
||||||
equal( ui.index, 1 );
|
equal( ui.index, 1, "ui.index" );
|
||||||
tabs_state( element, 0, 1, 0 );
|
tabs_state( element, 0, 1, 0 );
|
||||||
});
|
});
|
||||||
tabs.eq( 1 ).click();
|
tabs.eq( 1 ).click();
|
||||||
@ -292,25 +292,44 @@ test( "show", function() {
|
|||||||
tabs_state( element, 0, 0, 0 );
|
tabs_state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
test('select', function() {
|
test( "select", function() {
|
||||||
expect(7);
|
expect( 13 );
|
||||||
|
|
||||||
var eventObj;
|
var element = $( "#tabs1" ).tabs({
|
||||||
el = $('#tabs1').tabs({
|
active: false,
|
||||||
select: function(event, ui) {
|
collapsible: true
|
||||||
ok(true, 'select triggered after initialization');
|
}),
|
||||||
equals(this, el[0], "context of callback");
|
tabs = element.find( ".ui-tabs-nav a" ),
|
||||||
equals(event.type, 'tabsselect', 'event type in callback');
|
panels = element.find( ".ui-tabs-panel" );
|
||||||
equals(ui.tab, el.find('a')[1], 'contain tab as DOM anchor element');
|
|
||||||
equals(ui.panel, el.find('div')[1], 'contain panel as DOM div element');
|
// from collapsed
|
||||||
equals(ui.index, 1, 'contain index');
|
element.one( "tabsselect", function( event, ui ) {
|
||||||
evenObj = event;
|
ok( !( "originalEvent" in event ), "originalEvent" );
|
||||||
}
|
strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
|
||||||
|
strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
|
||||||
|
equal( ui.index, 0, "ui.index" );
|
||||||
|
tabs_state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
el.tabs('select', 1);
|
element.tabs( "option", "active", 0 );
|
||||||
|
tabs_state( element, 1, 0, 0 );
|
||||||
|
|
||||||
el.find( "li:eq(1) a" ).simulate( "click" );
|
// switching tabs
|
||||||
equals( evenObj.originalEvent.type, "click", "select triggered by click" );
|
element.one( "tabsselect", function( event, ui ) {
|
||||||
|
equals( event.originalEvent.type, "click", "originalEvent" );
|
||||||
|
strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
|
||||||
|
strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
|
||||||
|
equal( ui.index, 1, "ui.index" );
|
||||||
|
tabs_state( element, 1, 0, 0 );
|
||||||
|
});
|
||||||
|
tabs.eq( 1 ).click();
|
||||||
|
tabs_state( element, 0, 1, 0 );
|
||||||
|
|
||||||
|
// collapsing
|
||||||
|
element.one( "tabsselect", function( event, ui ) {
|
||||||
|
ok( false, "collapsing" );
|
||||||
|
});
|
||||||
|
element.tabs( "option", "active", false );
|
||||||
|
tabs_state( element, 0, 0, 0 );
|
||||||
});
|
});
|
||||||
|
|
||||||
module( "tabs (deprecated): methods" );
|
module( "tabs (deprecated): methods" );
|
||||||
|
19
ui/jquery.ui.tabs.js
vendored
19
ui/jquery.ui.tabs.js
vendored
@ -153,14 +153,6 @@ $.widget( "ui.tabs", {
|
|||||||
return hash ? hash.replace( /:/g, "\\:" ) : "";
|
return hash ? hash.replace( /:/g, "\\:" ) : "";
|
||||||
},
|
},
|
||||||
|
|
||||||
_ui: function( tab, panel ) {
|
|
||||||
return {
|
|
||||||
tab: tab,
|
|
||||||
panel: panel,
|
|
||||||
index: this.anchors.index( tab )
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
var self = this,
|
var self = this,
|
||||||
options = this.options,
|
options = this.options,
|
||||||
@ -651,6 +643,15 @@ $.extend( $.ui.tabs, {
|
|||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
if ( $.uiBackCompat !== false ) {
|
if ( $.uiBackCompat !== false ) {
|
||||||
|
|
||||||
|
// helper method for a lot of the back compat extensions
|
||||||
|
$.ui.tabs.prototype._ui = function( tab, panel ) {
|
||||||
|
return {
|
||||||
|
tab: tab,
|
||||||
|
panel: panel,
|
||||||
|
index: this.anchors.index( tab )
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// url method
|
// url method
|
||||||
(function( $, prototype ) {
|
(function( $, prototype ) {
|
||||||
prototype.url = function( index, url ) {
|
prototype.url = function( index, url ) {
|
||||||
@ -975,7 +976,7 @@ if ( $.uiBackCompat !== false ) {
|
|||||||
if ( !ret ) {
|
if ( !ret ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( type === "beforeActivate" ) {
|
if ( type === "beforeActivate" && data.newTab.length ) {
|
||||||
ret = _trigger.call( this, "select", event, {
|
ret = _trigger.call( this, "select", event, {
|
||||||
tab: data.newTab[ 0],
|
tab: data.newTab[ 0],
|
||||||
panel: data.newPanel[ 0 ],
|
panel: data.newPanel[ 0 ],
|
||||||
|
Loading…
Reference in New Issue
Block a user