2008-06-04 02:34:33 +00:00
|
|
|
/*
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Tabs @VERSION
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
|
|
|
* http://docs.jquery.com/UI/Tabs
|
|
|
|
*
|
|
|
|
* Depends:
|
2009-09-17 10:39:12 +00:00
|
|
|
* jquery.ui.core.js
|
2009-12-22 19:51:24 +00:00
|
|
|
* jquery.ui.widget.js
|
2008-06-04 02:34:33 +00:00
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2010-03-04 02:36:43 +00:00
|
|
|
var tabId = 0,
|
|
|
|
listId = 0;
|
2009-10-17 01:27:02 +00:00
|
|
|
|
2010-05-18 00:48:07 +00:00
|
|
|
function getNextTabId() {
|
|
|
|
return ++tabId;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNextListId() {
|
|
|
|
return ++listId;
|
|
|
|
}
|
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
$.widget( "ui.tabs", {
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2011-03-27 20:55:05 +00:00
|
|
|
activate: null,
|
2011-04-05 20:53:52 +00:00
|
|
|
active: null,
|
2011-03-27 21:02:58 +00:00
|
|
|
beforeActivate: null,
|
2011-04-05 20:53:52 +00:00
|
|
|
beforeLoad: null,
|
2010-01-07 03:19:50 +00:00
|
|
|
collapsible: false,
|
2010-07-28 15:28:14 +00:00
|
|
|
event: "click",
|
2010-01-07 03:19:50 +00:00
|
|
|
fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
|
2011-03-27 21:02:58 +00:00
|
|
|
load: null
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-07-28 15:28:14 +00:00
|
|
|
|
2010-01-15 18:58:20 +00:00
|
|
|
_create: function() {
|
2011-04-05 20:53:52 +00:00
|
|
|
var that = this,
|
|
|
|
options = that.options,
|
|
|
|
active = options.active;
|
2011-03-27 00:37:26 +00:00
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
that.running = false;
|
2011-03-27 00:49:59 +00:00
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
that.element.addClass( "ui-tabs ui-widget ui-widget-content ui-corner-all" );
|
2011-03-27 00:37:26 +00:00
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
that._processTabs();
|
2011-03-27 00:37:26 +00:00
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
if ( active === null ) {
|
|
|
|
// check the fragment identifier in the URL
|
2011-03-27 00:37:26 +00:00
|
|
|
if ( location.hash ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
that.anchors.each(function( i, tab ) {
|
|
|
|
if ( tab.hash === location.hash ) {
|
|
|
|
active = i;
|
2011-03-27 00:37:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-04-05 20:53:52 +00:00
|
|
|
|
|
|
|
// check for a tab marked active via a class
|
|
|
|
if ( active === null ) {
|
|
|
|
active = that.lis.filter( ".ui-tabs-active" ).index();
|
|
|
|
}
|
|
|
|
|
|
|
|
// no active tab, set to false
|
|
|
|
if ( active === null || active === -1 ) {
|
|
|
|
active = that.lis.length ? 0 : false;
|
2011-03-27 00:37:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
// handle numbers: negative, out of range
|
|
|
|
if ( active !== false ) {
|
|
|
|
active = this.lis.eq( active ).index();
|
|
|
|
if ( active === -1 ) {
|
|
|
|
active = options.collapsible ? false : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
options.active = active;
|
2011-03-27 00:37:26 +00:00
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
// don't allow collapsible: false and active: false
|
|
|
|
if ( !options.collapsible && options.active === false ) {
|
|
|
|
options.active = 0;
|
|
|
|
}
|
|
|
|
|
2011-03-27 00:37:26 +00:00
|
|
|
// Take disabling tabs via class attribute from HTML
|
|
|
|
// into account and update option properly.
|
2011-04-05 20:53:52 +00:00
|
|
|
if ( $.isArray( options.disabled ) ) {
|
|
|
|
options.disabled = $.unique( options.disabled.concat(
|
2011-03-27 00:37:26 +00:00
|
|
|
$.map( this.lis.filter( ".ui-state-disabled" ), function( n, i ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
return that.lis.index( n );
|
2011-03-27 00:37:26 +00:00
|
|
|
})
|
|
|
|
) ).sort();
|
|
|
|
}
|
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
this._setupFx( options.fx );
|
2011-03-27 00:37:26 +00:00
|
|
|
|
|
|
|
this._refresh();
|
|
|
|
|
|
|
|
// highlight selected tab
|
2011-03-29 11:44:01 +00:00
|
|
|
this.panels.hide();
|
|
|
|
this.lis.removeClass( "ui-tabs-active ui-state-active" );
|
2011-03-27 00:37:26 +00:00
|
|
|
// check for length avoids error when initializing empty list
|
2011-04-05 20:53:52 +00:00
|
|
|
if ( options.active !== false && this.anchors.length ) {
|
|
|
|
this.active = this._findActive( options.active );
|
|
|
|
var panel = that._getPanelForTab( this.active );
|
2011-03-27 02:14:17 +00:00
|
|
|
|
2011-03-29 11:44:01 +00:00
|
|
|
panel.show();
|
2011-03-27 00:37:26 +00:00
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
this.lis.eq( options.active ).addClass( "ui-tabs-active ui-state-active" );
|
2011-03-27 00:37:26 +00:00
|
|
|
|
2011-04-04 19:28:33 +00:00
|
|
|
// TODO: we need to remove this or add it to accordion
|
2011-03-27 20:55:05 +00:00
|
|
|
// seems to be expected behavior that the activate callback is fired
|
2011-04-05 20:53:52 +00:00
|
|
|
that.element.queue( "tabs", function() {
|
|
|
|
that._trigger( "activate", null, that._ui( that.active[ 0 ], panel[ 0 ] ) );
|
2011-03-27 00:37:26 +00:00
|
|
|
});
|
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
this.load( options.active );
|
2011-04-04 15:22:32 +00:00
|
|
|
} else {
|
|
|
|
this.active = $();
|
2011-03-27 00:37:26 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:48:06 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
_setOption: function( key, value ) {
|
2011-03-27 20:37:43 +00:00
|
|
|
if ( key == "active" ) {
|
2011-04-04 21:06:13 +00:00
|
|
|
// _activate() will handle invalid values and update this.options
|
2011-03-29 02:28:59 +00:00
|
|
|
this._activate( value );
|
2011-04-04 21:06:13 +00:00
|
|
|
return;
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2011-04-04 21:06:13 +00:00
|
|
|
|
2011-04-11 17:49:22 +00:00
|
|
|
// setting collapsible: false while collapsed; open first panel
|
|
|
|
if ( key === "collapsible" && !value && this.options.active === false ) {
|
|
|
|
this._activate( 0 );
|
|
|
|
}
|
|
|
|
|
2011-04-04 21:06:13 +00:00
|
|
|
this.options[ key ] = value;
|
|
|
|
this.refresh();
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:48:06 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
_tabId: function( a ) {
|
2011-04-06 01:39:02 +00:00
|
|
|
return $( a ).attr( "aria-controls" ) || "ui-tabs-" + getNextTabId();
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:48:06 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
_sanitizeSelector: function( hash ) {
|
|
|
|
// we need this because an id may contain a ":"
|
2011-03-29 11:44:01 +00:00
|
|
|
return hash ? hash.replace( /:/g, "\\:" ) : "";
|
2008-10-02 14:20:35 +00:00
|
|
|
},
|
2008-11-21 04:48:06 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
_ui: function( tab, panel ) {
|
2009-01-26 11:34:28 +00:00
|
|
|
return {
|
|
|
|
tab: tab,
|
|
|
|
panel: panel,
|
2010-07-28 15:28:14 +00:00
|
|
|
index: this.anchors.index( tab )
|
2009-01-26 11:34:28 +00:00
|
|
|
};
|
|
|
|
},
|
2008-11-21 04:48:06 +00:00
|
|
|
|
2011-03-27 00:37:26 +00:00
|
|
|
refresh: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._processTabs();
|
|
|
|
|
|
|
|
this._refresh();
|
|
|
|
|
|
|
|
// Remove panels that we created that are missing their tab
|
|
|
|
this.element.find(".ui-tabs-panel:data(destroy.tabs)").each( function( index, panel ) {
|
2011-04-05 15:28:05 +00:00
|
|
|
var anchor = self.anchors.filter( "[aria-controls='" + panel.id + "']");
|
2011-03-27 00:37:26 +00:00
|
|
|
if ( !anchor.length ) {
|
|
|
|
$( panel ).remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_refresh: function() {
|
2011-04-05 20:53:52 +00:00
|
|
|
var that = this,
|
|
|
|
options = that.options;
|
2011-03-27 00:37:26 +00:00
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
this.element.toggleClass( "ui-tabs-collapsible", options.collapsible );
|
|
|
|
this.list.addClass("ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" );
|
|
|
|
this.lis.addClass( "ui-state-default ui-corner-top" );
|
|
|
|
this.panels.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" );
|
2011-03-27 00:37:26 +00:00
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
if ( !options.disabled.length ) {
|
|
|
|
options.disabled = false;
|
2011-03-27 00:37:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// disable tabs
|
|
|
|
for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
$( li ).toggleClass( "ui-state-disabled", $.inArray( i, options.disabled ) !== -1 );
|
2011-03-27 00:37:26 +00:00
|
|
|
}
|
|
|
|
|
2011-04-05 20:53:52 +00:00
|
|
|
this._setupEvents( options.event );
|
2011-03-27 00:37:26 +00:00
|
|
|
|
|
|
|
// remove all handlers, may run on existing tabs
|
|
|
|
this.lis.unbind( ".tabs" );
|
|
|
|
this._focusable( this.lis );
|
|
|
|
this._hoverable( this.lis );
|
|
|
|
},
|
|
|
|
|
|
|
|
_processTabs: function() {
|
2010-07-28 15:28:14 +00:00
|
|
|
var self = this,
|
|
|
|
fragmentId = /^#.+/; // Safari 2 reports '#' for an empty hash
|
2009-01-22 13:10:18 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
this.list = this.element.find( "ol,ul" ).eq( 0 );
|
2010-08-12 03:06:41 +00:00
|
|
|
this.lis = $( " > li:has(a[href])", this.list );
|
2010-07-28 15:28:14 +00:00
|
|
|
this.anchors = this.lis.map(function() {
|
|
|
|
return $( "a", this )[ 0 ];
|
|
|
|
});
|
|
|
|
this.panels = $( [] );
|
2009-02-18 21:44:34 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
this.anchors.each(function( i, a ) {
|
2011-03-27 02:14:17 +00:00
|
|
|
var href = $( a ).attr( "href" ),
|
|
|
|
hrefBase = href.split( "#" )[ 0 ],
|
|
|
|
selector,
|
|
|
|
panel,
|
|
|
|
baseEl;
|
|
|
|
|
2009-02-19 20:19:13 +00:00
|
|
|
// For dynamically created HTML that contains a hash as href IE < 8 expands
|
|
|
|
// such href to the full page url with hash and then misinterprets tab as ajax.
|
|
|
|
// Same consideration applies for an added tab with a fragment identifier
|
|
|
|
// since a[href=#fragment-identifier] does unexpectedly not match.
|
|
|
|
// Thus normalize href attribute...
|
2010-07-28 15:28:14 +00:00
|
|
|
if ( hrefBase && ( hrefBase === location.toString().split( "#" )[ 0 ] ||
|
|
|
|
( baseEl = $( "base" )[ 0 ]) && hrefBase === baseEl.href ) ) {
|
2009-02-19 20:19:13 +00:00
|
|
|
href = a.hash;
|
|
|
|
a.href = href;
|
|
|
|
}
|
2009-02-22 17:40:16 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
// inline tab
|
2010-07-28 15:28:14 +00:00
|
|
|
if ( fragmentId.test( href ) ) {
|
2011-03-27 02:14:17 +00:00
|
|
|
selector = href;
|
|
|
|
panel = self.element.find( self._sanitizeSelector( selector ) );
|
2008-06-04 02:34:33 +00:00
|
|
|
// remote tab
|
2010-07-28 15:28:14 +00:00
|
|
|
// prevent loading the page itself if href is just "#"
|
2010-09-03 17:35:05 +00:00
|
|
|
} else if ( href && href !== "#" ) {
|
2010-07-28 15:28:14 +00:00
|
|
|
var id = self._tabId( a );
|
2011-03-27 02:14:17 +00:00
|
|
|
selector = "#" + id;
|
|
|
|
panel = self.element.find( selector );
|
|
|
|
if ( !panel.length ) {
|
2011-03-27 19:12:53 +00:00
|
|
|
panel = self._createPanel( id );
|
|
|
|
panel.insertAfter( self.panels[ i - 1 ] || self.list );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
// invalid tab href
|
2010-07-28 15:28:14 +00:00
|
|
|
} else {
|
2011-03-27 00:37:26 +00:00
|
|
|
self.options.disabled.push( i );
|
2009-02-19 20:19:13 +00:00
|
|
|
}
|
2011-03-27 02:14:17 +00:00
|
|
|
|
|
|
|
if ( panel.length) {
|
|
|
|
self.panels = self.panels.add( panel );
|
|
|
|
}
|
2011-04-05 15:28:05 +00:00
|
|
|
$( a ).attr( "aria-controls", selector.substring( 1 ) );
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2011-03-27 00:37:26 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-27 19:12:53 +00:00
|
|
|
_createPanel: function( id ) {
|
|
|
|
return $( "<div></div>" )
|
|
|
|
.attr( "id", id )
|
|
|
|
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
|
|
|
|
.data( "destroy.tabs", true );
|
|
|
|
},
|
|
|
|
|
2011-03-27 00:37:26 +00:00
|
|
|
_setupFx: function( fx ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
// set up animations
|
2011-03-27 00:37:26 +00:00
|
|
|
if ( fx ) {
|
|
|
|
if ( $.isArray( fx ) ) {
|
|
|
|
this.hideFx = fx[ 0 ];
|
|
|
|
this.showFx = fx[ 1 ];
|
2010-07-28 15:28:14 +00:00
|
|
|
} else {
|
2011-03-27 00:37:26 +00:00
|
|
|
this.hideFx = this.showFx = fx;
|
2009-02-22 14:00:11 +00:00
|
|
|
}
|
2008-11-05 10:59:55 +00:00
|
|
|
}
|
2011-03-26 16:04:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Reset certain styles left over from animation
|
|
|
|
// and prevent IE's ClearType bug...
|
|
|
|
_resetStyle: function ( $el, fx ) {
|
|
|
|
$el.css( "display", "" );
|
|
|
|
if ( !$.support.opacity && fx.opacity ) {
|
|
|
|
$el[ 0 ].style.removeAttribute( "filter" );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2011-03-26 16:04:14 +00:00
|
|
|
},
|
2008-11-05 10:59:55 +00:00
|
|
|
|
2011-04-04 19:28:33 +00:00
|
|
|
_showTab: function( event, eventData ) {
|
|
|
|
var that = this;
|
2011-03-26 16:04:14 +00:00
|
|
|
|
2011-04-04 19:28:33 +00:00
|
|
|
$( eventData.newTab ).closest( "li" ).addClass( "ui-tabs-active ui-state-active" );
|
2011-03-26 16:04:14 +00:00
|
|
|
|
2011-04-04 19:28:33 +00:00
|
|
|
if ( that.showFx ) {
|
|
|
|
that.running = true;
|
|
|
|
eventData.newPanel
|
|
|
|
// TODO: why are we hiding? old code?
|
|
|
|
.hide()
|
|
|
|
.animate( that.showFx, that.showFx.duration || "normal", function() {
|
|
|
|
that._resetStyle( $( this ), that.showFx );
|
|
|
|
that.running = false;
|
|
|
|
that._trigger( "activate", event, eventData );
|
2008-11-05 10:59:55 +00:00
|
|
|
});
|
2011-03-26 16:04:14 +00:00
|
|
|
} else {
|
2011-04-04 19:28:33 +00:00
|
|
|
eventData.newPanel.show();
|
|
|
|
that._trigger( "activate", event, eventData );
|
2011-03-26 16:04:14 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-04-04 19:28:33 +00:00
|
|
|
// TODO: combine with _showTab()
|
|
|
|
_hideTab: function( event, eventData ) {
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
if ( that.hideFx ) {
|
|
|
|
that.running = true;
|
|
|
|
eventData.oldPanel.animate( that.hideFx, that.hideFx.duration || "normal", function() {
|
|
|
|
that.running = false;
|
|
|
|
eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
|
|
|
|
that._resetStyle( $( this ), that.hideFx );
|
|
|
|
that.element.dequeue( "tabs" );
|
|
|
|
if ( !eventData.newPanel.length ) {
|
|
|
|
that._trigger( "activate", event, eventData );
|
|
|
|
}
|
2011-03-26 16:04:14 +00:00
|
|
|
});
|
|
|
|
} else {
|
2011-04-04 19:28:33 +00:00
|
|
|
eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
|
|
|
|
eventData.oldPanel.hide();
|
|
|
|
that.element.dequeue( "tabs" );
|
|
|
|
if ( !eventData.newPanel.length ) {
|
|
|
|
that._trigger( "activate", event, eventData );
|
|
|
|
}
|
2011-03-26 16:04:14 +00:00
|
|
|
}
|
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-27 00:37:26 +00:00
|
|
|
_setupEvents: function( event ) {
|
|
|
|
// attach tab event handler, unbind to avoid duplicates from former tabifying...
|
|
|
|
this.anchors.unbind( ".tabs" );
|
|
|
|
|
|
|
|
if ( event ) {
|
|
|
|
this.anchors.bind( event.split( " " ).join( ".tabs " ) + ".tabs",
|
|
|
|
$.proxy( this, "_eventHandler" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// disable click in any case
|
|
|
|
this.anchors.bind( "click.tabs", function( event ){
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-03-26 16:04:14 +00:00
|
|
|
_eventHandler: function( event ) {
|
2011-04-04 15:22:32 +00:00
|
|
|
var that = this,
|
|
|
|
options = that.options,
|
|
|
|
active = that.active,
|
2011-03-29 02:28:59 +00:00
|
|
|
clicked = $( event.currentTarget ),
|
2011-04-04 15:22:32 +00:00
|
|
|
clickedIsActive = clicked[ 0 ] === active[ 0 ],
|
|
|
|
collapsing = clickedIsActive && options.collapsible,
|
2011-04-05 15:28:05 +00:00
|
|
|
toShow = collapsing ? $() : that._getPanelForTab( clicked ),
|
|
|
|
toHide = !active.length ? $() : that._getPanelForTab( active ),
|
2011-04-04 15:22:32 +00:00
|
|
|
tab = clicked.closest( "li" ),
|
|
|
|
eventData = {
|
|
|
|
oldTab: active,
|
|
|
|
oldPanel: toHide,
|
|
|
|
newTab: collapsing ? $() : clicked,
|
|
|
|
newPanel: toShow
|
|
|
|
};
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if ( tab.hasClass( "ui-state-disabled" ) ||
|
|
|
|
// tab is already loading
|
|
|
|
tab.hasClass( "ui-tabs-loading" ) ||
|
|
|
|
// can't switch durning an animation
|
|
|
|
that.running ||
|
|
|
|
// click on active header, but not collapsible
|
|
|
|
( clickedIsActive && !options.collapsible ) ||
|
|
|
|
// allow canceling activation
|
|
|
|
( that._trigger( "beforeActivate", event, eventData ) === false ) ) {
|
2011-03-29 02:28:59 +00:00
|
|
|
clicked[ 0 ].blur();
|
2011-03-26 16:04:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-04-04 15:22:32 +00:00
|
|
|
options.active = collapsing ? false : that.anchors.index( clicked );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-04-04 18:27:38 +00:00
|
|
|
that.active = clickedIsActive ? $() : clicked;
|
2011-04-04 15:22:32 +00:00
|
|
|
if ( that.xhr ) {
|
|
|
|
that.xhr.abort();
|
2011-03-26 19:23:08 +00:00
|
|
|
}
|
2009-02-18 21:44:34 +00:00
|
|
|
|
2011-03-26 16:04:14 +00:00
|
|
|
// if tab may be closed
|
2011-04-04 15:22:32 +00:00
|
|
|
if ( options.collapsible ) {
|
|
|
|
if ( collapsing ) {
|
|
|
|
options.active = false;
|
2009-02-22 17:40:16 +00:00
|
|
|
|
2011-04-04 15:22:32 +00:00
|
|
|
that.element.queue( "tabs", function() {
|
2011-04-04 19:28:33 +00:00
|
|
|
that._hideTab( event, eventData );
|
2011-03-26 16:04:14 +00:00
|
|
|
}).dequeue( "tabs" );
|
2010-07-28 15:28:14 +00:00
|
|
|
|
2011-03-29 02:28:59 +00:00
|
|
|
clicked[ 0 ].blur();
|
2011-03-26 16:04:14 +00:00
|
|
|
return;
|
2011-04-04 15:22:32 +00:00
|
|
|
} else if ( !toHide.length ) {
|
|
|
|
that.element.queue( "tabs", function() {
|
2011-04-04 19:28:33 +00:00
|
|
|
that._showTab( event, eventData );
|
2011-03-26 16:04:14 +00:00
|
|
|
});
|
2009-02-25 22:09:45 +00:00
|
|
|
|
2011-03-26 16:04:14 +00:00
|
|
|
// TODO make passing in node possible, see also http://dev.jqueryui.com/ticket/3171
|
2011-04-05 15:28:05 +00:00
|
|
|
that.load( that.anchors.index( clicked ), event );
|
2010-07-28 15:28:14 +00:00
|
|
|
|
2011-03-29 02:28:59 +00:00
|
|
|
clicked[ 0 ].blur();
|
2011-03-26 16:04:14 +00:00
|
|
|
return;
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2011-03-26 16:04:14 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-26 16:04:14 +00:00
|
|
|
// show new tab
|
2011-04-04 15:22:32 +00:00
|
|
|
if ( toShow.length ) {
|
|
|
|
if ( toHide.length ) {
|
|
|
|
that.element.queue( "tabs", function() {
|
2011-04-04 19:28:33 +00:00
|
|
|
that._hideTab( event, eventData );
|
2009-02-25 22:09:45 +00:00
|
|
|
});
|
2009-02-18 21:44:34 +00:00
|
|
|
}
|
2011-04-04 15:22:32 +00:00
|
|
|
that.element.queue( "tabs", function() {
|
2011-04-04 19:28:33 +00:00
|
|
|
that._showTab( event, eventData );
|
2011-03-26 16:04:14 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-04-05 15:28:05 +00:00
|
|
|
that.load( that.anchors.index( clicked ), event );
|
2011-03-26 16:04:14 +00:00
|
|
|
} else {
|
|
|
|
throw "jQuery UI Tabs: Mismatching fragment identifier.";
|
|
|
|
}
|
2009-01-19 20:40:51 +00:00
|
|
|
|
2011-03-26 16:04:14 +00:00
|
|
|
// Prevent IE from keeping other link focussed when using the back button
|
|
|
|
// and remove dotted border from clicked link. This is controlled via CSS
|
|
|
|
// in modern browsers; blur() removes focus from address bar in Firefox
|
|
|
|
// which can become a usability
|
|
|
|
if ( $.browser.msie ) {
|
2011-03-29 02:28:59 +00:00
|
|
|
clicked[ 0 ].blur();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_activate: function( index ) {
|
|
|
|
var active = this._findActive( index )[ 0 ];
|
|
|
|
|
|
|
|
// trying to activate the already active panel
|
2011-04-04 18:27:38 +00:00
|
|
|
if ( active === this.active[ 0 ] ) {
|
2011-03-29 02:28:59 +00:00
|
|
|
return;
|
2011-03-26 16:04:14 +00:00
|
|
|
}
|
2011-03-29 02:28:59 +00:00
|
|
|
|
|
|
|
// trying to collapse, simulate a click on the current active header
|
2011-04-04 18:27:38 +00:00
|
|
|
active = active || this.active[ 0 ];
|
2011-03-29 02:28:59 +00:00
|
|
|
|
|
|
|
this._eventHandler({
|
|
|
|
target: active,
|
|
|
|
currentTarget: active,
|
|
|
|
preventDefault: $.noop
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_findActive: function( selector ) {
|
|
|
|
return typeof selector === "number" ? this.anchors.eq( selector ) :
|
|
|
|
typeof selector === "string" ? this.anchors.filter( "[href$='" + selector + "']" ) : $();
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2009-01-31 00:45:14 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
_getIndex: function( index ) {
|
2010-07-16 16:37:54 +00:00
|
|
|
// meta-function to give users option to provide a href string instead of a numerical index.
|
|
|
|
// also sanitizes numerical indexes to valid values.
|
2010-07-28 15:28:14 +00:00
|
|
|
if ( typeof index == "string" ) {
|
|
|
|
index = this.anchors.index( this.anchors.filter( "[href$=" + index + "]" ) );
|
2010-07-16 16:37:54 +00:00
|
|
|
}
|
2010-07-28 15:28:14 +00:00
|
|
|
|
2010-07-16 16:37:54 +00:00
|
|
|
return index;
|
|
|
|
},
|
|
|
|
|
2011-02-01 02:56:55 +00:00
|
|
|
_destroy: function() {
|
2009-01-26 11:34:28 +00:00
|
|
|
var o = this.options;
|
|
|
|
|
2011-03-26 19:23:08 +00:00
|
|
|
if ( this.xhr ) {
|
|
|
|
this.xhr.abort();
|
|
|
|
}
|
2009-01-26 11:34:28 +00:00
|
|
|
|
2011-02-01 02:56:55 +00:00
|
|
|
this.element.removeClass( "ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible" );
|
2010-07-28 15:28:14 +00:00
|
|
|
|
|
|
|
this.list.removeClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" );
|
2009-01-26 11:34:28 +00:00
|
|
|
|
2009-02-25 22:15:49 +00:00
|
|
|
this.anchors.each(function() {
|
2010-07-28 15:28:14 +00:00
|
|
|
var $this = $( this ).unbind( ".tabs" );
|
2011-03-26 19:00:39 +00:00
|
|
|
$.each( [ "href", "load" ], function( i, prefix ) {
|
2010-07-28 15:28:14 +00:00
|
|
|
$this.removeData( prefix + ".tabs" );
|
2009-01-26 11:34:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
this.lis.unbind( ".tabs" ).add( this.panels ).each(function() {
|
|
|
|
if ( $.data( this, "destroy.tabs" ) ) {
|
|
|
|
$( this ).remove();
|
|
|
|
} else {
|
|
|
|
$( this ).removeClass([
|
|
|
|
"ui-state-default",
|
|
|
|
"ui-corner-top",
|
2011-03-29 11:44:01 +00:00
|
|
|
"ui-tabs-active",
|
2010-07-28 15:28:14 +00:00
|
|
|
"ui-state-active",
|
|
|
|
"ui-state-disabled",
|
|
|
|
"ui-tabs-panel",
|
|
|
|
"ui-widget-content",
|
2011-03-29 11:44:01 +00:00
|
|
|
"ui-corner-bottom"
|
2010-07-28 15:28:14 +00:00
|
|
|
].join( " " ) );
|
2009-02-22 14:00:11 +00:00
|
|
|
}
|
2009-01-26 11:34:28 +00:00
|
|
|
});
|
|
|
|
|
2009-04-15 02:33:28 +00:00
|
|
|
return this;
|
2009-01-26 11:34:28 +00:00
|
|
|
},
|
2008-11-21 04:48:06 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
enable: function( index ) {
|
2011-02-06 19:49:42 +00:00
|
|
|
if ( index === undefined ) {
|
|
|
|
for ( var i = 0, len = this.lis.length; i < len; i++ ) {
|
|
|
|
this.enable( i );
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
2010-07-28 15:28:14 +00:00
|
|
|
index = this._getIndex( index );
|
2008-06-04 02:34:33 +00:00
|
|
|
var o = this.options;
|
2011-02-06 19:49:42 +00:00
|
|
|
if ( !o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) == -1 ) ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
return;
|
2009-02-22 14:00:11 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
this.lis.eq( index ).removeClass( "ui-state-disabled" );
|
2011-02-06 19:49:42 +00:00
|
|
|
o.disabled = this.lis.map( function( i ) {
|
|
|
|
return $(this).is( ".ui-state-disabled" ) ? i : null;
|
|
|
|
}).get();
|
|
|
|
|
|
|
|
if ( !o.disabled.length ) {
|
|
|
|
o.disabled = false;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2009-04-15 02:33:28 +00:00
|
|
|
return this;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:48:06 +00:00
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
disable: function( index ) {
|
2011-02-06 19:49:42 +00:00
|
|
|
if ( index === undefined ) {
|
|
|
|
for ( var i = 0, len = this.lis.length; i < len; i++ ) {
|
|
|
|
this.disable( i );
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
2010-07-28 15:28:14 +00:00
|
|
|
index = this._getIndex( index );
|
2011-02-06 19:49:42 +00:00
|
|
|
var o = this.options;
|
|
|
|
if ( !o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) == -1 ) ) {
|
2010-07-28 15:28:14 +00:00
|
|
|
this.lis.eq( index ).addClass( "ui-state-disabled" );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-02-06 19:49:42 +00:00
|
|
|
o.disabled = this.lis.map( function( i ) {
|
|
|
|
return $(this).is( ".ui-state-disabled" ) ? i : null;
|
|
|
|
}).get();
|
|
|
|
|
|
|
|
if ( o.disabled.length === this.anchors.length ) {
|
|
|
|
o.disabled = true;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2009-04-15 02:33:28 +00:00
|
|
|
|
|
|
|
return this;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:48:06 +00:00
|
|
|
|
2011-04-05 15:28:05 +00:00
|
|
|
load: function( index, event ) {
|
2010-07-28 15:28:14 +00:00
|
|
|
index = this._getIndex( index );
|
|
|
|
var self = this,
|
|
|
|
o = this.options,
|
|
|
|
a = this.anchors.eq( index )[ 0 ],
|
2011-04-05 15:28:05 +00:00
|
|
|
panel = self._getPanelForTab( a ),
|
2011-03-27 02:14:17 +00:00
|
|
|
// TODO until #3808 is fixed strip fragment identifier from url
|
|
|
|
// (IE fails to load from such url)
|
|
|
|
url = $( a ).attr( "href" ).replace( /#.*$/, "" ),
|
2011-04-05 15:28:05 +00:00
|
|
|
eventData = {
|
|
|
|
tab: $( a ),
|
|
|
|
panel: panel
|
|
|
|
};
|
2009-02-18 21:44:34 +00:00
|
|
|
|
2011-03-26 19:23:08 +00:00
|
|
|
if ( this.xhr ) {
|
|
|
|
this.xhr.abort();
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-26 19:00:39 +00:00
|
|
|
// not remote
|
|
|
|
if ( !url ) {
|
2010-07-28 15:28:14 +00:00
|
|
|
this.element.dequeue( "tabs" );
|
2008-06-04 02:34:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-26 19:00:39 +00:00
|
|
|
this.xhr = $.ajax({
|
2008-06-04 02:34:33 +00:00
|
|
|
url: url,
|
2011-03-26 19:00:39 +00:00
|
|
|
beforeSend: function( jqXHR, settings ) {
|
2011-04-05 15:28:05 +00:00
|
|
|
return self._trigger( "beforeLoad", event,
|
|
|
|
$.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
|
2011-03-26 19:00:39 +00:00
|
|
|
}
|
|
|
|
});
|
2009-02-18 21:44:34 +00:00
|
|
|
|
2011-03-26 19:00:39 +00:00
|
|
|
if ( this.xhr ) {
|
|
|
|
// load remote from here on
|
2011-03-29 11:44:01 +00:00
|
|
|
this.lis.eq( index ).addClass( "ui-tabs-loading" );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-03-26 19:00:39 +00:00
|
|
|
this.xhr
|
2011-04-05 15:28:05 +00:00
|
|
|
.success(function( response ) {
|
2011-03-27 02:14:17 +00:00
|
|
|
panel.html( response );
|
2011-03-26 19:00:39 +00:00
|
|
|
})
|
2011-04-05 15:28:05 +00:00
|
|
|
.complete(function( jqXHR, status ) {
|
2011-03-26 19:23:08 +00:00
|
|
|
if ( status === "abort" ) {
|
|
|
|
// stop possibly running animations
|
|
|
|
self.element.queue( [] );
|
|
|
|
self.panels.stop( false, true );
|
|
|
|
|
|
|
|
// "tabs" queue must not contain more than two elements,
|
|
|
|
// which are the callbacks for the latest clicked tab...
|
|
|
|
self.element.queue( "tabs", self.element.queue( "tabs" ).splice( -2, 2 ) );
|
|
|
|
|
|
|
|
delete this.xhr;
|
|
|
|
}
|
2011-03-26 19:48:53 +00:00
|
|
|
|
2011-03-29 11:44:01 +00:00
|
|
|
self.lis.eq( index ).removeClass( "ui-tabs-loading" );
|
2011-03-26 19:00:39 +00:00
|
|
|
|
2011-04-05 15:28:05 +00:00
|
|
|
self._trigger( "load", event, eventData );
|
2011-03-26 19:00:39 +00:00
|
|
|
});
|
|
|
|
}
|
2009-04-15 02:33:28 +00:00
|
|
|
|
2010-02-24 18:43:33 +00:00
|
|
|
// last, so that load event is fired before show...
|
2010-07-28 15:28:14 +00:00
|
|
|
self.element.dequeue( "tabs" );
|
2010-02-24 18:43:33 +00:00
|
|
|
|
2009-04-15 02:33:28 +00:00
|
|
|
return this;
|
2011-04-04 21:06:13 +00:00
|
|
|
},
|
2011-03-27 02:14:17 +00:00
|
|
|
|
2011-04-04 21:06:13 +00:00
|
|
|
_getPanelForTab: function( tab ) {
|
|
|
|
var id = $( tab ).attr( "aria-controls" );
|
|
|
|
return this.element.find( this._sanitizeSelector( "#" + id ) );
|
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
$.extend( $.ui.tabs, {
|
|
|
|
version: "@VERSION"
|
2008-10-08 10:09:55 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-03-26 19:00:39 +00:00
|
|
|
// DEPRECATED
|
|
|
|
if ( $.uiBackCompat !== false ) {
|
|
|
|
// ajaxOptions and cache options
|
|
|
|
(function( $, prototype ) {
|
|
|
|
$.extend( prototype.options, {
|
|
|
|
ajaxOptions: null,
|
|
|
|
cache: false
|
|
|
|
});
|
|
|
|
|
|
|
|
var _create = prototype._create,
|
|
|
|
_setOption = prototype._setOption,
|
|
|
|
_destroy = prototype._destroy,
|
|
|
|
oldurl = prototype._url;
|
|
|
|
|
|
|
|
$.extend( prototype, {
|
|
|
|
_create: function() {
|
|
|
|
_create.call( this );
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.element.bind( "tabsbeforeload", function( event, ui ) {
|
|
|
|
// tab is already cached
|
2011-04-05 15:28:05 +00:00
|
|
|
if ( $.data( ui.tab[ 0 ], "cache.tabs" ) ) {
|
2011-03-26 19:00:39 +00:00
|
|
|
event.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-05 15:28:05 +00:00
|
|
|
$.extend( ui.ajaxSettings, self.options.ajaxOptions, {
|
2011-03-26 19:00:39 +00:00
|
|
|
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)
|
2011-04-05 15:28:05 +00:00
|
|
|
self.options.ajaxOptions.error( xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
|
2011-03-26 19:00:39 +00:00
|
|
|
}
|
|
|
|
catch ( e ) {}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ui.jqXHR.success( function() {
|
|
|
|
if ( self.options.cache ) {
|
2011-04-05 15:28:05 +00:00
|
|
|
$.data( ui.tab[ 0 ], "cache.tabs", true );
|
2011-03-26 19:00:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_setOption: function( key, value ) {
|
|
|
|
// reset cache if switching from cached to not cached
|
|
|
|
if ( key === "cache" && value === false ) {
|
|
|
|
this.anchors.removeData( "cache.tabs" );
|
|
|
|
}
|
|
|
|
_setOption.apply( this, arguments );
|
|
|
|
},
|
|
|
|
|
|
|
|
_destroy: function() {
|
|
|
|
this.anchors.removeData( "cache.tabs" );
|
|
|
|
_destroy.call( this );
|
|
|
|
},
|
|
|
|
|
|
|
|
url: function( index, url ){
|
|
|
|
this.anchors.eq( index ).removeData( "cache.tabs" );
|
|
|
|
oldurl.apply( this, arguments );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-26 19:23:08 +00:00
|
|
|
|
|
|
|
// abort method
|
|
|
|
(function( $, prototype ) {
|
|
|
|
prototype.abort = function() {
|
|
|
|
if ( this.xhr ) {
|
|
|
|
this.xhr.abort();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-26 19:48:53 +00:00
|
|
|
|
|
|
|
// spinner
|
|
|
|
(function( $, prototype ) {
|
|
|
|
$.extend( prototype.options, {
|
|
|
|
spinner: "<em>Loading…</em>"
|
|
|
|
});
|
|
|
|
|
|
|
|
var _create = prototype._create;
|
|
|
|
prototype._create = function() {
|
|
|
|
_create.call( this );
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.element.bind( "tabsbeforeload", function( event, ui ) {
|
|
|
|
if ( self.options.spinner ) {
|
|
|
|
var span = $( "span", ui.tab );
|
|
|
|
if ( span.length ) {
|
|
|
|
span.data( "label.tabs", span.html() ).html( self.options.spinner );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui.jqXHR.complete( function() {
|
|
|
|
if ( self.options.spinner ) {
|
|
|
|
var span = $( "span", ui.tab );
|
|
|
|
if ( span.length ) {
|
|
|
|
span.html( span.data( "label.tabs" ) ).removeData( "label.tabs" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-26 20:12:05 +00:00
|
|
|
|
|
|
|
// enable/disable events
|
|
|
|
(function( $, prototype ) {
|
|
|
|
$.extend( prototype.options, {
|
|
|
|
enable: null,
|
|
|
|
disable: null
|
|
|
|
});
|
|
|
|
|
|
|
|
var enable = prototype.enable,
|
|
|
|
disable = prototype.disable;
|
|
|
|
|
|
|
|
prototype.enable = function( index ) {
|
|
|
|
var o = this.options,
|
|
|
|
trigger;
|
|
|
|
|
|
|
|
if ( index && o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) !== -1 ) ) {
|
|
|
|
trigger = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
enable.apply( this, arguments );
|
|
|
|
|
|
|
|
if ( trigger ) {
|
|
|
|
this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
prototype.disable = function( index ) {
|
|
|
|
var o = this.options,
|
|
|
|
trigger;
|
|
|
|
|
|
|
|
if ( index && !o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) == -1 ) ) {
|
|
|
|
trigger = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
disable.apply( this, arguments );
|
|
|
|
|
|
|
|
if ( trigger ) {
|
|
|
|
this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
|
|
// add/remove methods and events
|
|
|
|
(function( $, prototype ) {
|
|
|
|
$.extend( prototype.options, {
|
|
|
|
add: null,
|
2011-03-27 19:12:53 +00:00
|
|
|
remove: null,
|
|
|
|
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
|
2011-03-26 20:29:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
prototype.add = function( url, label, index ) {
|
|
|
|
if ( index === undefined ) {
|
|
|
|
index = this.anchors.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this,
|
|
|
|
o = this.options,
|
|
|
|
$li = $( o.tabTemplate.replace( /#\{href\}/g, url ).replace( /#\{label\}/g, label ) ),
|
|
|
|
id = !url.indexOf( "#" ) ? url.replace( "#", "" ) : this._tabId( $( "a", $li )[ 0 ] );
|
|
|
|
|
|
|
|
$li.addClass( "ui-state-default ui-corner-top" ).data( "destroy.tabs", true );
|
|
|
|
|
|
|
|
// try to find an existing element before creating a new one
|
|
|
|
var $panel = self.element.find( "#" + id );
|
|
|
|
if ( !$panel.length ) {
|
2011-03-27 19:12:53 +00:00
|
|
|
$panel = self._createPanel( id );
|
2011-03-26 20:29:57 +00:00
|
|
|
}
|
2011-03-29 11:44:01 +00:00
|
|
|
$panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide();
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
|
|
if ( index >= this.lis.length ) {
|
|
|
|
$li.appendTo( this.list );
|
|
|
|
$panel.appendTo( this.list[ 0 ].parentNode );
|
|
|
|
} else {
|
|
|
|
$li.insertBefore( this.lis[ index ] );
|
|
|
|
$panel.insertBefore( this.panels[ index ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
o.disabled = $.map( o.disabled, function( n, i ) {
|
|
|
|
return n >= index ? ++n : n;
|
|
|
|
});
|
|
|
|
|
2011-03-27 00:37:26 +00:00
|
|
|
this.refresh();
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
|
|
if ( this.anchors.length == 1 ) {
|
2011-03-27 20:37:43 +00:00
|
|
|
o.active = o.selected = 0;
|
2011-03-29 11:44:01 +00:00
|
|
|
$li.addClass( "ui-tabs-active ui-state-active" );
|
|
|
|
$panel.show();
|
2011-03-26 20:29:57 +00:00
|
|
|
this.element.queue( "tabs", function() {
|
2011-03-27 20:55:05 +00:00
|
|
|
self._trigger( "activate", null, self._ui( self.anchors[ 0 ], self.panels[ 0 ] ) );
|
2011-03-26 20:29:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.load( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
prototype.remove = function( index ) {
|
|
|
|
index = this._getIndex( index );
|
|
|
|
var o = this.options,
|
|
|
|
$li = this.lis.eq( index ).remove(),
|
|
|
|
$panel = this.panels.eq( index ).remove();
|
|
|
|
|
|
|
|
// If selected tab was removed focus tab to the right or
|
|
|
|
// in case the last tab was removed the tab to the left.
|
2011-03-29 11:44:01 +00:00
|
|
|
if ( $li.hasClass( "ui-tabs-active" ) && this.anchors.length > 1) {
|
2011-03-29 02:28:59 +00:00
|
|
|
this._activate( index + ( index + 1 < this.anchors.length ? 1 : -1 ) );
|
2011-03-26 20:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
o.disabled = $.map(
|
|
|
|
$.grep( o.disabled, function(n, i) {
|
|
|
|
return n != index;
|
|
|
|
}),
|
|
|
|
function( n, i ) {
|
|
|
|
return n >= index ? --n : n;
|
|
|
|
});
|
|
|
|
|
2011-03-27 00:37:26 +00:00
|
|
|
this.refresh();
|
2011-03-26 20:29:57 +00:00
|
|
|
|
|
|
|
this._trigger( "remove", null, this._ui( $li.find( "a" )[ 0 ], $panel[ 0 ] ) );
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
|
|
|
|
2011-03-26 20:49:14 +00:00
|
|
|
// length method
|
|
|
|
(function( $, prototype ) {
|
|
|
|
prototype.length = function() {
|
|
|
|
return this.anchors.length;
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-27 02:14:17 +00:00
|
|
|
|
|
|
|
// url method
|
|
|
|
(function( $, prototype ) {
|
|
|
|
prototype.url = function( index, url ) {
|
|
|
|
this.anchors.eq( index ).attr( "href", url );
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
|
|
|
|
2011-04-06 01:39:02 +00:00
|
|
|
// panel ids (idPrefix option + title attribute)
|
2011-03-27 02:14:17 +00:00
|
|
|
(function( $, prototype ) {
|
2011-03-27 19:12:53 +00:00
|
|
|
$.extend( prototype.options, {
|
|
|
|
idPrefix: "ui-tabs-"
|
|
|
|
});
|
|
|
|
|
2011-03-27 02:14:17 +00:00
|
|
|
var _tabId = prototype._tabId;
|
|
|
|
prototype._tabId = function( a ) {
|
2011-04-06 01:39:02 +00:00
|
|
|
return $( a ).attr( "aria-controls" ) ||
|
2011-03-27 19:12:53 +00:00
|
|
|
a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) ||
|
|
|
|
this.options.idPrefix + getNextTabId();
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
|
|
|
|
2011-04-06 01:39:02 +00:00
|
|
|
// _createPanel method
|
2011-03-27 19:12:53 +00:00
|
|
|
(function( $, prototype ) {
|
|
|
|
$.extend( prototype.options, {
|
|
|
|
panelTemplate: "<div></div>"
|
|
|
|
});
|
|
|
|
|
|
|
|
var _createPanel = prototype._createPanel;
|
|
|
|
prototype._createPanel = function( id ) {
|
|
|
|
return $( this.options.panelTemplate )
|
|
|
|
.attr( "id", id )
|
|
|
|
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
|
|
|
|
.data( "destroy.tabs", true );
|
2011-03-27 02:14:17 +00:00
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-27 20:37:43 +00:00
|
|
|
|
|
|
|
// selected option
|
|
|
|
(function( $, prototype ) {
|
|
|
|
var _create = prototype._create,
|
|
|
|
_setOption = prototype._setOption,
|
|
|
|
_eventHandler = prototype._eventHandler;
|
|
|
|
|
|
|
|
prototype._create = function() {
|
|
|
|
var options = this.options;
|
2011-04-05 20:53:52 +00:00
|
|
|
if ( options.active === null && options.selected !== undefined ) {
|
|
|
|
options.active = options.selected === -1 ? false : options.selected;
|
2011-03-27 20:37:43 +00:00
|
|
|
}
|
|
|
|
_create.call( this );
|
|
|
|
options.selected = options.active;
|
2011-04-05 20:53:52 +00:00
|
|
|
if ( options.selected === false ) {
|
|
|
|
options.selected = -1;
|
|
|
|
}
|
2011-03-27 20:37:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
prototype._setOption = function( key, value ) {
|
|
|
|
var options = this.options;
|
|
|
|
if ( key === "selected" ) {
|
|
|
|
key = "active";
|
|
|
|
}
|
|
|
|
_setOption.apply( this, arguments );
|
|
|
|
if ( key === "active" ) {
|
2011-04-05 20:53:52 +00:00
|
|
|
if ( key === - 1 ) {
|
|
|
|
key = false;
|
|
|
|
}
|
|
|
|
options.selected = options.active;
|
|
|
|
if ( options.selected === false ) {
|
|
|
|
options.selected = -1;
|
|
|
|
}
|
2011-03-27 20:37:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
prototype._eventHandler = function( event ) {
|
|
|
|
_eventHandler.apply( this, arguments );
|
2011-04-05 20:53:52 +00:00
|
|
|
this.options.selected = this.options.active;
|
|
|
|
if ( this.options.selected === false ) {
|
|
|
|
this.options.selected = -1;
|
|
|
|
}
|
2011-03-27 20:37:43 +00:00
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-27 20:55:05 +00:00
|
|
|
|
2011-03-27 21:02:58 +00:00
|
|
|
// show and select event
|
2011-03-27 20:55:05 +00:00
|
|
|
(function( $, prototype ) {
|
|
|
|
$.extend( prototype.options, {
|
2011-03-27 21:02:58 +00:00
|
|
|
show: null,
|
|
|
|
select: null
|
2011-03-27 20:55:05 +00:00
|
|
|
});
|
|
|
|
var _trigger = prototype._trigger;
|
|
|
|
|
|
|
|
prototype._trigger = function( type, event, data ) {
|
|
|
|
var ret = _trigger.apply( this, arguments );
|
|
|
|
if ( !ret ) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-27 21:02:58 +00:00
|
|
|
if ( type === "beforeActivate" ) {
|
2011-04-04 15:22:32 +00:00
|
|
|
ret = _trigger.call( this, "select", event, {
|
|
|
|
tab: data.newTab[ 0],
|
|
|
|
panel: data.newPanel[ 0 ],
|
|
|
|
index: data.newTab.closest( "li" ).index()
|
|
|
|
});
|
2011-03-27 21:02:58 +00:00
|
|
|
} else if ( type === "activate" ) {
|
2011-03-27 20:55:05 +00:00
|
|
|
ret = _trigger.call( this, "show", event, data );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-29 02:28:59 +00:00
|
|
|
|
|
|
|
// select method
|
|
|
|
(function( $, prototype ) {
|
|
|
|
prototype.select = function( index ) {
|
|
|
|
index = this._getIndex( index );
|
|
|
|
if ( index == -1 ) {
|
|
|
|
if ( this.options.collapsible && this.options.selected != -1 ) {
|
|
|
|
index = this.options.selected;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.anchors.eq( index ).trigger( this.options.event + ".tabs" );
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-29 02:46:31 +00:00
|
|
|
|
|
|
|
// cookie option
|
|
|
|
(function( $, prototype ) {
|
|
|
|
$.extend( prototype.options, {
|
|
|
|
cookie: null // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
|
|
|
|
});
|
|
|
|
|
|
|
|
var _create = prototype._create,
|
|
|
|
_refresh = prototype._refresh,
|
|
|
|
_eventHandler = prototype._eventHandler,
|
|
|
|
_destroy = prototype._destroy;
|
|
|
|
|
|
|
|
prototype._create = function() {
|
|
|
|
var o = this.options;
|
|
|
|
if ( o.active === undefined ) {
|
|
|
|
if ( typeof o.active !== "number" && o.cookie ) {
|
|
|
|
o.active = parseInt( this._cookie(), 10 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_create.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
prototype._cookie = function() {
|
|
|
|
var cookie = this.cookie ||
|
|
|
|
( this.cookie = this.options.cookie.name || "ui-tabs-" + getNextListId() );
|
|
|
|
return $.cookie.apply( null, [ cookie ].concat( $.makeArray( arguments ) ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
prototype._refresh = function() {
|
|
|
|
_refresh.call( this );
|
|
|
|
|
|
|
|
// set or update cookie after init and add/remove respectively
|
|
|
|
if ( this.options.cookie ) {
|
|
|
|
this._cookie( this.options.active, this.options.cookie );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
prototype._eventHandler = function( event ) {
|
|
|
|
_eventHandler.apply( this, arguments );
|
|
|
|
|
|
|
|
if ( this.options.cookie ) {
|
|
|
|
this._cookie( this.options.active, this.options.cookie );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
prototype._destroy = function() {
|
|
|
|
_destroy.call( this );
|
|
|
|
|
|
|
|
if ( this.options.cookie ) {
|
|
|
|
this._cookie( null, this.options.cookie );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}( jQuery, jQuery.ui.tabs.prototype ) );
|
2011-03-26 19:00:39 +00:00
|
|
|
}
|
|
|
|
|
2010-07-28 15:28:14 +00:00
|
|
|
})( jQuery );
|