diff options
Diffstat (limited to 'ui/jquery.ui.tabs.js')
-rw-r--r-- | ui/jquery.ui.tabs.js | 86 |
1 files changed, 35 insertions, 51 deletions
diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 68c182c31..026c50993 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -95,8 +95,8 @@ $.widget( "ui.tabs", { // into account and update option properly. if ( $.isArray( options.disabled ) ) { options.disabled = $.unique( options.disabled.concat( - $.map( this.lis.filter( ".ui-state-disabled" ), function( n, i ) { - return that.lis.index( n ); + $.map( this.lis.filter( ".ui-state-disabled" ), function( li ) { + return that.lis.index( li ); }) ) ).sort(); } @@ -162,13 +162,11 @@ $.widget( "ui.tabs", { }, _sanitizeSelector: function( hash ) { - // we need this because an id may contain a ":" - return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@[\]^`{|}~]/g, "\\$&" ) : ""; + return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : ""; }, refresh: function() { var next, - self = this, options = this.options, lis = this.list.children( ":has(a[href])" ); @@ -216,14 +214,14 @@ $.widget( "ui.tabs", { }, _processTabs: function() { - var self = this; + var that = this; this.list = this._getList(); - this.lis = $( " > li:has(a[href])", this.list ); + this.lis = this.list.find( "> li:has(a[href])" ); this.anchors = this.lis.map(function() { return $( "a", this )[ 0 ]; }); - this.panels = $( [] ); + this.panels = $(); this.anchors.each(function( i, a ) { var selector, panel, id; @@ -231,20 +229,20 @@ $.widget( "ui.tabs", { // inline tab if ( isLocal( a ) ) { selector = a.hash; - panel = self.element.find( self._sanitizeSelector( selector ) ); + panel = that.element.find( that._sanitizeSelector( selector ) ); // remote tab } else { - id = self._tabId( a ); + id = that._tabId( a ); selector = "#" + id; - panel = self.element.find( selector ); + panel = that.element.find( selector ); if ( !panel.length ) { - panel = self._createPanel( id ); - panel.insertAfter( self.panels[ i - 1 ] || self.list ); + panel = that._createPanel( id ); + panel.insertAfter( that.panels[ i - 1 ] || that.list ); } } if ( panel.length) { - self.panels = self.panels.add( panel ); + that.panels = that.panels.add( panel ); } $( a ).attr( "aria-controls", selector.substring( 1 ) ); }); @@ -256,10 +254,10 @@ $.widget( "ui.tabs", { }, _createPanel: function( id ) { - return $( "<div></div>" ) - .attr( "id", id ) - .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ) - .data( "ui-tabs-destroy", true ); + return $( "<div>" ) + .attr( "id", id ) + .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ) + .data( "ui-tabs-destroy", true ); }, _setupDisabled: function( disabled ) { @@ -273,7 +271,8 @@ $.widget( "ui.tabs", { // disable tabs for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) { - $( li ).toggleClass( "ui-state-disabled", ( disabled === true || $.inArray( i, disabled ) !== -1 ) ); + $( li ).toggleClass( "ui-state-disabled", + ( disabled === true || $.inArray( i, disabled ) !== -1 ) ); } this.options.disabled = disabled; @@ -291,22 +290,17 @@ $.widget( "ui.tabs", { } }, - // TODO: remove once jQuery core properly removes filters - see #4621 - _resetStyle: function ( $el, fx ) { - if ( !$.support.opacity && fx.opacity ) { - $el[ 0 ].style.removeAttribute( "filter" ); - } - }, - _setupEvents: function( event ) { // attach tab event handler, unbind to avoid duplicates from former tabifying... this.anchors.unbind( ".tabs" ); + // TODO: use event delegation via _bind() if ( event ) { this.anchors.bind( event.split( " " ).join( ".tabs " ) + ".tabs", $.proxy( this, "_eventHandler" ) ); } + // TODO: use event delegation via _bind() // disable click in any case this.anchors.bind( "click.tabs", function( event ){ event.preventDefault(); @@ -353,14 +347,12 @@ $.widget( "ui.tabs", { } if ( !toHide.length && !toShow.length ) { - throw "jQuery UI Tabs: Mismatching fragment identifier."; + jQuery.error( "jQuery UI Tabs: Mismatching fragment identifier." ); } if ( toShow.length ) { - // TODO make passing in node possible that.load( that.anchors.index( clicked ), event ); - clicked[ 0 ].blur(); } that._toggle( event, eventData ); @@ -369,7 +361,6 @@ $.widget( "ui.tabs", { // handles show/hide for selecting tabs _toggle: function( event, eventData ) { var that = this, - options = that.options, toShow = eventData.newPanel, toHide = eventData.oldPanel; @@ -386,7 +377,6 @@ $.widget( "ui.tabs", { if ( toShow.length && that.showFx ) { toShow .animate( that.showFx, that.showFx.duration || "normal", function() { - that._resetStyle( $( this ), that.showFx ); complete(); }); } else { @@ -399,7 +389,6 @@ $.widget( "ui.tabs", { if ( toHide.length && that.hideFx ) { toHide.animate( that.hideFx, that.hideFx.duration || "normal", function() { eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" ); - that._resetStyle( $( this ), that.hideFx ); show(); }); } else { @@ -429,7 +418,7 @@ $.widget( "ui.tabs", { _findActive: function( selector ) { return typeof selector === "number" ? this.anchors.eq( selector ) : - typeof selector === "string" ? this.anchors.filter( "[href$='" + selector + "']" ) : $(); + typeof selector === "string" ? this.anchors.filter( "[href$='" + selector + "']" ) : $(); }, _getIndex: function( index ) { @@ -443,8 +432,6 @@ $.widget( "ui.tabs", { }, _destroy: function() { - var o = this.options; - if ( this.xhr ) { this.xhr.abort(); } @@ -525,10 +512,9 @@ $.widget( "ui.tabs", { load: function( index, event ) { index = this._getIndex( index ); - var self = this, - options = this.options, + var that = this, anchor = this.anchors.eq( index ), - panel = self._getPanelForTab( anchor ), + panel = that._getPanelForTab( anchor ), eventData = { tab: anchor, panel: panel @@ -542,7 +528,7 @@ $.widget( "ui.tabs", { this.xhr = $.ajax({ url: anchor.attr( "href" ), beforeSend: function( jqXHR, settings ) { - return self._trigger( "beforeLoad", event, + return that._trigger( "beforeLoad", event, $.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) ); } }); @@ -556,7 +542,7 @@ $.widget( "ui.tabs", { // remove when core #10467 is fixed setTimeout(function() { panel.html( response ); - self._trigger( "load", event, eventData ); + that._trigger( "load", event, eventData ); }, 1 ); }) .complete(function( jqXHR, status ) { @@ -564,19 +550,17 @@ $.widget( "ui.tabs", { // remove when core #10467 is fixed setTimeout(function() { if ( status === "abort" ) { - self.panels.stop( false, true ); + that.panels.stop( false, true ); } - self.lis.eq( index ).removeClass( "ui-tabs-loading" ); + that.lis.eq( index ).removeClass( "ui-tabs-loading" ); - if ( jqXHR === self.xhr ) { - delete self.xhr; + if ( jqXHR === that.xhr ) { + delete that.xhr; } }, 1 ); }); } - - return this; }, _getPanelForTab: function( tab ) { @@ -614,7 +598,7 @@ if ( $.uiBackCompat !== false ) { _create: function() { this._super(); - var self = this; + var that = this; this.element.bind( "tabsbeforeload.tabs", function( event, ui ) { // tab is already cached @@ -623,21 +607,21 @@ if ( $.uiBackCompat !== false ) { return; } - $.extend( ui.ajaxSettings, self.options.ajaxOptions, { + $.extend( ui.ajaxSettings, that.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.tab.closest( "li" ).index(), ui.tab[ 0 ] ); + that.options.ajaxOptions.error( xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] ); } catch ( e ) {} } }); ui.jqXHR.success(function() { - if ( self.options.cache ) { + if ( that.options.cache ) { $.data( ui.tab[ 0 ], "cache.tabs", true ); } }); @@ -843,7 +827,7 @@ if ( $.uiBackCompat !== false ) { _tabId: function( a ) { return $( a ).attr( "aria-controls" ) || - a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) || + a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF\-]/g, "" ) || this.options.idPrefix + getNextTabId(); } }); |