});
test( "beforeLoad", function() {
- expect( 5 );
-
- el = $( "#tabs2" );
-
- el.tabs({
- active: 2,
- beforeLoad: function( event, ui ) {
- ok( $.isFunction( ui.jqXHR.promise ), 'contain jqXHR object');
- equals( ui.settings.url, "data/test.html", 'contain ajax settings url');
- equals( ui.tab, el.find('a')[ 2 ], 'contain tab as DOM anchor element');
- equals( ui.panel, el.find('div')[ 2 ], 'contain panel as DOM div element');
- equals( ui.index, 2, 'contain index');
- event.preventDefault();
- }
+ expect( 21 );
+
+ var tab, panelId, panel,
+ element = $( "#tabs2" ).tabs();
+
+ // TODO: init
+// element.one( "tabsbeforeload", function( event, ui ) {
+// });
+// element.tabs({ active: 2 });
+
+ // .option()
+ element.one( "tabsbeforeload", function( event, ui ) {
+ tab = element.find( ".ui-tabs-nav a" ).eq( 2 );
+ panelId = tab.attr( "aria-controls" );
+ panel = $( "#" + panelId );
+
+ ok( !( "originalEvent" in event ), "originalEvent" );
+ ok( "abort" in ui.jqXHR, "jqXHR" );
+ ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" );
+ equals( ui.tab.size(), 1, "tab size" );
+ strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
+ equals( ui.panel.size(), 1, "panel size" );
+ strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
+ equals( ui.panel.html(), "", "panel html" );
+ event.preventDefault();
+ tabs_state( element, 1, 0, 0, 0 );
+ });
+ element.tabs( "option", "active", 2 );
+ tabs_state( element, 0, 0, 1, 0 );
+ equals( panel.html(), "", "panel html after" );
+
+ // click
+ element.one( "tabsbeforeload", function( event, ui ) {
+ tab = element.find( ".ui-tabs-nav a" ).eq( 3 );
+ panelId = tab.attr( "aria-controls" );
+ panel = $( "#" + panelId );
+
+ equals( event.originalEvent.type, "click", "originalEvent" );
+ ok( "abort" in ui.jqXHR, "jqXHR" );
+ ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" );
+ equals( ui.tab.size(), 1, "tab size" );
+ strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
+ equals( ui.panel.size(), 1, "panel size" );
+ strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
+ ui.panel.html( "<p>testing</p>" );
+ event.preventDefault();
+ tabs_state( element, 0, 0, 1, 0 );
});
+ element.find( ".ui-tabs-nav a" ).eq( 3 ).click();
+ tabs_state( element, 0, 0, 0, 1 );
+ equals( panel.html(), "<p>testing</p>", "panel html after" );
});
test('load', function() {
// check for length avoids error when initializing empty list
if ( o.active >= 0 && this.anchors.length ) {
this.active = this._findActive( o.active );
- var panel = self.element.find( self._sanitizeSelector( this.active.attr( "aria-controls" ) ) );
+ var panel = self._getPanelForTab( this.active );
panel.show();
},
_tabId: function( a ) {
- return ( $( a ).attr( "aria-controls" ) || "" ).replace( /^#/ , "" ) ||
+ return ( $( a ).attr( "aria-controls" ) || "" ) ||
"ui-tabs-" + getNextTabId();
},
// Remove panels that we created that are missing their tab
this.element.find(".ui-tabs-panel:data(destroy.tabs)").each( function( index, panel ) {
- var anchor = self.anchors.filter( "[aria-controls='#" + panel.id + "']");
+ var anchor = self.anchors.filter( "[aria-controls='" + panel.id + "']");
if ( !anchor.length ) {
$( panel ).remove();
}
if ( panel.length) {
self.panels = self.panels.add( panel );
}
- $( a ).attr( "aria-controls", selector );
+ $( a ).attr( "aria-controls", selector.substring( 1 ) );
});
},
clicked = $( event.currentTarget ),
clickedIsActive = clicked[ 0 ] === active[ 0 ],
collapsing = clickedIsActive && options.collapsible,
- toShow = collapsing ? $() : that.element.find( that._sanitizeSelector( clicked.attr( "aria-controls" ) ) ),
- toHide = !active.length ? $() : that.element.find( that._sanitizeSelector( active.attr( "aria-controls" ) ) ),
+ toShow = collapsing ? $() : that._getPanelForTab( clicked ),
+ toHide = !active.length ? $() : that._getPanelForTab( active ),
tab = clicked.closest( "li" ),
eventData = {
oldTab: active,
});
// TODO make passing in node possible, see also http://dev.jqueryui.com/ticket/3171
- that.load( that.anchors.index( clicked ) );
+ that.load( that.anchors.index( clicked ), event );
clicked[ 0 ].blur();
return;
that._showTab( event, eventData );
});
- that.load( that.anchors.index( clicked ) );
+ that.load( that.anchors.index( clicked ), event );
} else {
throw "jQuery UI Tabs: Mismatching fragment identifier.";
}
return this;
},
- load: function( index ) {
+ load: function( index, event ) {
index = this._getIndex( index );
var self = this,
o = this.options,
a = this.anchors.eq( index )[ 0 ],
- panel = self.element.find( self._sanitizeSelector( $( a ).attr( "aria-controls" ) ) ),
+ panel = self._getPanelForTab( a ),
// TODO until #3808 is fixed strip fragment identifier from url
// (IE fails to load from such url)
url = $( a ).attr( "href" ).replace( /#.*$/, "" ),
- eventData = self._ui( a, panel[ 0 ] );
+ eventData = {
+ tab: $( a ),
+ panel: panel
+ };
if ( this.xhr ) {
this.xhr.abort();
this.xhr = $.ajax({
url: url,
beforeSend: function( jqXHR, settings ) {
- // TODO: pass relevant event
- return self._trigger( "beforeLoad", null,
- $.extend( { jqXHR : jqXHR, settings: settings }, eventData ) );
+ return self._trigger( "beforeLoad", event,
+ $.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
}
});
this.lis.eq( index ).addClass( "ui-tabs-loading" );
this.xhr
- .success( function( response ) {
+ .success(function( response ) {
panel.html( response );
})
- .complete( function( jqXHR, status ) {
+ .complete(function( jqXHR, status ) {
if ( status === "abort" ) {
// stop possibly running animations
self.element.queue( [] );
self.lis.eq( index ).removeClass( "ui-tabs-loading" );
- self._trigger( "load", null, eventData );
+ self._trigger( "load", event, eventData );
});
}
this.element.bind( "tabsbeforeload", function( event, ui ) {
// tab is already cached
- if ( $.data( ui.tab, "cache.tabs" ) ) {
+ if ( $.data( ui.tab[ 0 ], "cache.tabs" ) ) {
event.preventDefault();
return;
}
- $.extend( ui.settings, self.options.ajaxOptions, {
+ $.extend( ui.ajaxSettings, self.options.ajaxOptions, {
error: function( xhr, s, e ) {
try {
// Passing index avoid a race condition when this method is
// called after the user has selected another tab.
// Pass the anchor that initiated this request allows
// loadError to manipulate the tab content panel via $(a.hash)
- self.options.ajaxOptions.error( xhr, s, ui.index, ui.tab );
+ self.options.ajaxOptions.error( xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
}
catch ( e ) {}
}
ui.jqXHR.success( function() {
if ( self.options.cache ) {
- $.data( ui.tab, "cache.tabs", true );
+ $.data( ui.tab[ 0 ], "cache.tabs", true );
}
});
});
var _tabId = prototype._tabId;
prototype._tabId = function( a ) {
- return ( $( a ).attr( "aria-controls" ) || "" ).replace( /^#/ , "" ) ||
+ return ( $( a ).attr( "aria-controls" ) || "" ) ||
a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) ||
this.options.idPrefix + getNextTabId();
};