mirror of
https://github.com/jquery/jquery-ui.git
synced 2026-04-20 03:02:41 -04:00
Tabs: cookie was not considered if page url contains some fragment identifier, fixes #4210; fixed issue with jQuery 1.3.2 :visible selector; started to fix JSLint warnings...
This commit is contained in:
@@ -15,30 +15,31 @@
|
||||
$.widget("ui.tabs", {
|
||||
|
||||
_init: function() {
|
||||
if (this.options.deselectable !== undefined)
|
||||
if (this.options.deselectable !== undefined) {
|
||||
this.options.collapsible = this.options.deselectable;
|
||||
}
|
||||
this._tabify(true);
|
||||
},
|
||||
|
||||
_setData: function(key, value) {
|
||||
if (key == 'selected') {
|
||||
if (this.options.collapsible
|
||||
&& value == this.options.selected) return;
|
||||
|
||||
if (this.options.collapsible && value == this.options.selected) {
|
||||
return;
|
||||
}
|
||||
this.select(value);
|
||||
}
|
||||
else {
|
||||
this.options[key] = value;
|
||||
if (key == 'deselectable')
|
||||
if (key == 'deselectable') {
|
||||
this.options.collapsible = value;
|
||||
|
||||
}
|
||||
this._tabify();
|
||||
}
|
||||
},
|
||||
|
||||
_tabId: function(a) {
|
||||
return a.title && a.title.replace(/\s/g, '_').replace(/[^A-Za-z0-9\-_:\.]/g, '')
|
||||
|| this.options.idPrefix + $.data(a);
|
||||
return a.title && a.title.replace(/\s/g, '_').replace(/[^A-Za-z0-9\-_:\.]/g, '') ||
|
||||
this.options.idPrefix + $.data(a);
|
||||
},
|
||||
|
||||
_sanitizeSelector: function(hash) {
|
||||
@@ -144,21 +145,20 @@ $.widget("ui.tabs", {
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (o.cookie)
|
||||
if (!o.selected && o.cookie) {
|
||||
o.selected = parseInt(self._cookie(), 10);
|
||||
|
||||
else if (this.$lis.filter('.ui-tabs-selected').length)
|
||||
}
|
||||
if (!o.selected && this.$lis.filter('.ui-tabs-selected').length) {
|
||||
o.selected = this.$lis.index(this.$lis.filter('.ui-tabs-selected'));
|
||||
|
||||
else
|
||||
o.selected = 0;
|
||||
|
||||
}
|
||||
o.selected = o.selected || 0;
|
||||
}
|
||||
else if (o.selected === null)
|
||||
else if (o.selected === null) { // usage of null is deprecated, TODO remove in next release
|
||||
o.selected = -1;
|
||||
}
|
||||
|
||||
// sanity check
|
||||
o.selected = ((o.selected >= 0 && this.$tabs[o.selected]) || o.selected < 0) ? o.selected : 0; // default to first tab
|
||||
// sanity check - default to first tab...
|
||||
o.selected = ((o.selected >= 0 && this.$tabs[o.selected]) || o.selected < 0) ? o.selected : 0
|
||||
|
||||
// Take disabling tabs via class attribute from HTML
|
||||
// into account and update option properly.
|
||||
@@ -179,15 +179,12 @@ $.widget("ui.tabs", {
|
||||
|
||||
// seems to be expected behavior that the show callback is fired
|
||||
var onShow = function() {
|
||||
self._trigger('show', null,
|
||||
self._ui(self.$tabs[o.selected], self.$panels[o.selected]));
|
||||
self._trigger('show', null, self._ui(self.$tabs[o.selected], self.$panels[o.selected]));
|
||||
};
|
||||
|
||||
// load if remote tab
|
||||
if ($.data(this.$tabs[o.selected], 'load.tabs'))
|
||||
this.load(o.selected, onShow);
|
||||
// just trigger show event
|
||||
else onShow();
|
||||
// load if remote tab else just trigger show event
|
||||
$.data(this.$tabs[o.selected], 'load.tabs') ? this.load(o.selected, onShow): onShow();
|
||||
|
||||
}
|
||||
|
||||
// clean up to avoid memory leaks in certain versions of IE 6
|
||||
@@ -285,7 +282,7 @@ $.widget("ui.tabs", {
|
||||
|
||||
// attach tab event handler, unbind to avoid duplicates from former tabifying...
|
||||
this.$tabs.bind(o.event + '.tabs', function() {
|
||||
var $li = $(this).closest('li'), $hide = self.$panels.filter(':visible'),
|
||||
var $li = $(this).closest('li'), $hide = self.$panels.filter(':not(.ui-tabs-hide)'),
|
||||
$show = $(self._sanitizeSelector(this.hash));
|
||||
|
||||
// If tab is already selected and not collapsible or tab disabled or
|
||||
@@ -305,7 +302,8 @@ $.widget("ui.tabs", {
|
||||
|
||||
self.abort();
|
||||
|
||||
// if tab may be closed TODO avoid redundant code in this block
|
||||
// if tab may be closed
|
||||
// TODO avoid redundant code in this block
|
||||
if (o.collapsible) {
|
||||
if ($li.hasClass('ui-tabs-selected')) {
|
||||
o.selected = -1;
|
||||
@@ -315,7 +313,8 @@ $.widget("ui.tabs", {
|
||||
hideTab(this, $hide);
|
||||
this.blur();
|
||||
return false;
|
||||
} else if (!$hide.length) {
|
||||
}
|
||||
else if (!$hide.length) {
|
||||
if (o.cookie) self._cookie(o.selected, o.cookie);
|
||||
var a = this;
|
||||
self.load(self.$tabs.index(this), function() {
|
||||
@@ -436,8 +435,7 @@ $.widget("ui.tabs", {
|
||||
$panel.removeClass('ui-tabs-hide');
|
||||
var href = $.data(this.$tabs[0], 'load.tabs');
|
||||
if (href) this.load(0, function() {
|
||||
self._trigger('show', null,
|
||||
self._ui(self.$tabs[0], self.$panels[0]));
|
||||
self._trigger('show', null, self._ui(self.$tabs[0], self.$panels[0]));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -489,15 +487,16 @@ $.widget("ui.tabs", {
|
||||
},
|
||||
|
||||
select: function(index) {
|
||||
if (typeof index == 'string')
|
||||
if (typeof index == 'string') {
|
||||
index = this.$tabs.index(this.$tabs.filter('[href$=' + index + ']'));
|
||||
|
||||
else if (index === null)
|
||||
}
|
||||
else if (index === null) { // usage of null is deprecated, TODO remove in next release
|
||||
index = -1;
|
||||
|
||||
if (index == -1 && this.options.collapsible)
|
||||
}
|
||||
if (index == -1 && this.options.collapsible) {
|
||||
index = this.options.selected;
|
||||
|
||||
}
|
||||
|
||||
this.$tabs.eq(index).trigger(this.options.event + '.tabs');
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user