* This is nothing more than the pure jquery UI tabs implementation.
*/
(function($) {
-
+
// if the UI scope is not availalable, add it
$.ui = $.ui || {};
-
+
$.fn.tabs = function(initial, options) {
if (initial && initial.constructor == Object) { // shift arguments
options = initial;
initial = null;
}
options = options || {};
-
+
// first get initial tab from options
initial = initial && initial.constructor == Number && --initial || 0;
-
+
return this.each(function() {
new $.ui.tabs(this, $.extend(options, { initial: initial }));
});
};
-
+
// chainable tabs methods
$.each(['add', 'remove', 'enable', 'disable', 'click', 'load'], function(i, method) {
$.fn[method + 'Tab'] = function() {
$.fn.selectedTab = function(returnElement) {
var selected;
if (returnElement) {
-
+
} else {
-
+
}
return selected;
};
$.ui.tabs = function(el, options) {
-
+
this.source = el;
-
+
this.options = $.extend({
-
+
// basic setup
initial: 0,
event: 'click',
// TODO bookmarkable: $.ajaxHistory ? true : false,
unselected: false,
toggle: options.unselected ? true : false,
-
+
// Ajax
spinner: 'Loading…',
cache: false,
hashPrefix: 'tab-',
-
+
// animations
/*fxFade: null,
fxSlide: null,
fxSpeed: 'normal',
/*fxShowSpeed: null,
fxHideSpeed: null,*/
-
+
// callbacks
add: function() {},
remove: function() {},
hide: function() {},
show: function() {},
load: function() {},
-
+
// CSS classes
navClass: 'ui-tabs-nav',
selectedClass: 'ui-tabs-selected',
containerClass: 'ui-tabs-container',
hideClass: 'ui-tabs-hide',
loadingClass: 'ui-tabs-loading'
-
+
}, options);
-
+
this.tabify(true);
-
+
// save instance for later
var uuid = 'instance-' + $.ui.tabs.prototype.count++;
$.ui.tabs.instances[uuid] = this;
this.source['UI_TABS_UUID'] = uuid;
-
+
};
-
+
// static
$.ui.tabs.instances = {};
-
+
$.extend($.ui.tabs.prototype, {
animating: false,
count: 0,
tabify: function(init) {
-
+
this.$tabs = $('a:first-child', this.source);
this.$containers = $([]);
-
+
var self = this, o = this.options;
-
+
this.$tabs.each(function(i, a) {
// inline tab
if (a.hash && a.hash.replace('#', '')) { // safari 2 reports '#' for an empty hash
);
}
});
-
+
if (init) {
-
+
// Try to retrieve initial tab from fragment identifier in url if present,
// otherwise try to find selected class attribute on <li>.
this.$tabs.each(function(i, a) {
return false; // break
}
});
-
+
// attach necessary classes for styling if not present
$(this.source).is('.' + o.navClass) || $(this.source).addClass(o.navClass);
this.$containers.each(function() {
var $this = $(this);
$this.is('.' + o.containerClass) || $this.addClass(o.containerClass);
});
-
+
// highlight tab accordingly
var $lis = $('li', this.source);
this.$containers.addClass(o.hideClass);
this.$containers.slice(o.initial, o.initial + 1).show();
$lis.slice(o.initial, o.initial + 1).addClass(o.selectedClass);
}
-
+
// trigger load of initial tab is remote tab
if (this.$tabs[o.initial].url) {
this.load(o.initial + 1, this.$tabs[o.initial].url);
this.$tabs[o.initial].url = null; // if loaded once do not load them again
}
}
-
+
// disabled tabs
for (var i = 0, position; position = o.disabled[i]; i++) {
this.disable(position);
}
-
+
}
-
+
// setup animations
var showAnim = {}, hideAnim = {}, showSpeed = o.fxShowSpeed || o.fxSpeed,
hideSpeed = o.fxHideSpeed || o.fxSpeed;
hideSpeed = 1; // as little as 1 is sufficient
}
}
-
+
// callbacks
var click = o.click, hide = o.hide, show = o.show;
-
+
// reset some styles to maintain print style sheets etc.
var resetCSS = { display: '', overflow: '', height: '' };
if (!$.browser.msie) { // not in IE to prevent ClearType font issue
}
});
}
-
+
// show a tab, animation prevents browser scrolling to fragment
function showTab(clicked, $hide, $show) {
// show next tab
show(clicked, $show[0], $hide[0]);
self.animating = false;
});
-
+
}
-
+
// switch a tab
function switchTab(clicked, $hide, $show) {
/*if (o.bookmarkable && trueClick) { // add to history only if true click occured, not a triggered click
.siblings().removeClass(o.selectedClass);
hideTab(clicked, $hide, $show);
}
-
+
// tab click handler
function tabClick(e) {
//var trueClick = e.clientX; // add to history only if true click occured, not a triggered click
var $li = $(this).parents('li:eq(0)'), $hide = self.$containers.filter(':visible'), $show = $(this.hash);
-
+
// if tab may be closed
if (o.toggle && !$li.is('.' + o.disabledClass) && !self.animating) {
if ($li.is('.' + o.selectedClass)) {
return false;
}
}
-
+
// If tab is already selected or disabled, animation is still running or click callback
// returns false stop here.
// Check if click handler returns false last so that it is not executed for a disabled tab!
$show.attr('id', showId); // restore id
}, 0);
}*/
-
+
if (this.url) { // remote tab
var a = this;
self.load(self.$tabs.index(this) + 1, this.url, function() {
//return o.bookmarkable && !!trueClick; // convert trueClick == undefined to Boolean required in IE
return false;
-
+
}
-
+
// attach click event, avoid duplicates from former tabifying
this.$tabs.unbind(o.event, tabClick).bind(o.event, tabClick);
-
+
},
add: function(url, text, position) {
if (url && text) {
o.add(this.$tabs[position - 1], this.$containers[position - 1]); // callback
} else {
throw Drupal.t('jQuery UI Tabs: Not enough arguments to add tab.');
- }
+ }
},
remove: function(position) {
if (position && position.constructor == Number) {
$a = this.$tabs.slice(position - 1, position).addClass(o.loadingClass),
$span = $('span', $a),
text = $span.html();
-
+
// shift arguments
if (url && url.constructor == Function) {
callback = url;
}
-
+
// set new URL
if (url) {
$a[0].url = url;
}
-
+
// load
if (o.spinner) {
$span.html('<em>' + o.spinner + '</em>');
}
o.load(self.$tabs[position - 1], self.$containers[position - 1]); // callback
});
- }, 0);
+ }, 0);
}
});
})(jQuery);