mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
tabs: formatting changes - moved some things around for consistency.
_init and destroy at the top. ui last. Sorted defaults alphabetically.
This commit is contained in:
parent
f2ad7ea32a
commit
1c97a20d01
110
ui/ui.tabs.js
110
ui/ui.tabs.js
@ -13,10 +13,36 @@
|
|||||||
(function($) {
|
(function($) {
|
||||||
|
|
||||||
$.widget("ui.tabs", {
|
$.widget("ui.tabs", {
|
||||||
|
|
||||||
_init: function() {
|
_init: function() {
|
||||||
// create tabs
|
// create tabs
|
||||||
this._tabify(true);
|
this._tabify(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
destroy: function() {
|
||||||
|
var o = this.options;
|
||||||
|
this.element.unbind('.tabs')
|
||||||
|
.removeClass(o.navClass).removeData('tabs');
|
||||||
|
this.$tabs.each(function() {
|
||||||
|
var href = $.data(this, 'href.tabs');
|
||||||
|
if (href)
|
||||||
|
this.href = href;
|
||||||
|
var $this = $(this).unbind('.tabs');
|
||||||
|
$.each(['href', 'load', 'cache'], function(i, prefix) {
|
||||||
|
$this.removeData(prefix + '.tabs');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.$lis.add(this.$panels).each(function() {
|
||||||
|
if ($.data(this, 'destroy.tabs'))
|
||||||
|
$(this).remove();
|
||||||
|
else
|
||||||
|
$(this).removeClass([o.selectedClass, o.deselectableClass,
|
||||||
|
o.disabledClass, o.panelClass, o.hideClass].join(' '));
|
||||||
|
});
|
||||||
|
if (o.cookie)
|
||||||
|
this._cookie(null, o.cookie);
|
||||||
|
},
|
||||||
|
|
||||||
_setData: function(key, value) {
|
_setData: function(key, value) {
|
||||||
if ((/^selected/).test(key))
|
if ((/^selected/).test(key))
|
||||||
this.select(value);
|
this.select(value);
|
||||||
@ -25,28 +51,25 @@ $.widget("ui.tabs", {
|
|||||||
this._tabify();
|
this._tabify();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
length: function() {
|
length: function() {
|
||||||
return this.$tabs.length;
|
return this.$tabs.length;
|
||||||
},
|
},
|
||||||
|
|
||||||
_tabId: function(a) {
|
_tabId: function(a) {
|
||||||
return a.title && a.title.replace(/\s/g, '_').replace(/[^A-Za-z0-9\-_:\.]/g, '')
|
return a.title && a.title.replace(/\s/g, '_').replace(/[^A-Za-z0-9\-_:\.]/g, '')
|
||||||
|| this.options.idPrefix + $.data(a);
|
|| this.options.idPrefix + $.data(a);
|
||||||
},
|
},
|
||||||
ui: function(tab, panel) {
|
|
||||||
return {
|
|
||||||
options: this.options,
|
|
||||||
tab: tab,
|
|
||||||
panel: panel,
|
|
||||||
index: this.$tabs.index(tab)
|
|
||||||
};
|
|
||||||
},
|
|
||||||
_sanitizeSelector: function(hash) {
|
_sanitizeSelector: function(hash) {
|
||||||
return hash.replace(/:/g, '\\:'); // we need this because an id may contain a ":"
|
return hash.replace(/:/g, '\\:'); // we need this because an id may contain a ":"
|
||||||
},
|
},
|
||||||
|
|
||||||
_cookie: function() {
|
_cookie: function() {
|
||||||
var cookie = this.cookie || (this.cookie = 'ui-tabs-' + $.data(this.element[0]));
|
var cookie = this.cookie || (this.cookie = 'ui-tabs-' + $.data(this.element[0]));
|
||||||
return $.cookie.apply(null, [cookie].concat($.makeArray(arguments)));
|
return $.cookie.apply(null, [cookie].concat($.makeArray(arguments)));
|
||||||
},
|
},
|
||||||
|
|
||||||
_tabify: function(init) {
|
_tabify: function(init) {
|
||||||
|
|
||||||
this.$lis = $('li:has(a[href])', this.element);
|
this.$lis = $('li:has(a[href])', this.element);
|
||||||
@ -292,6 +315,7 @@ $.widget("ui.tabs", {
|
|||||||
if (o.event != 'click') this.$tabs.bind('click.tabs', function(){return false;});
|
if (o.event != 'click') this.$tabs.bind('click.tabs', function(){return false;});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
add: function(url, label, index) {
|
add: function(url, label, index) {
|
||||||
if (index == undefined)
|
if (index == undefined)
|
||||||
index = this.$tabs.length; // append by default
|
index = this.$tabs.length; // append by default
|
||||||
@ -334,6 +358,7 @@ $.widget("ui.tabs", {
|
|||||||
// callback
|
// callback
|
||||||
this._trigger('add', null, this.ui(this.$tabs[index], this.$panels[index]));
|
this._trigger('add', null, this.ui(this.$tabs[index], this.$panels[index]));
|
||||||
},
|
},
|
||||||
|
|
||||||
remove: function(index) {
|
remove: function(index) {
|
||||||
var o = this.options, $li = this.$lis.eq(index).remove(),
|
var o = this.options, $li = this.$lis.eq(index).remove(),
|
||||||
$panel = this.$panels.eq(index).remove();
|
$panel = this.$panels.eq(index).remove();
|
||||||
@ -351,6 +376,7 @@ $.widget("ui.tabs", {
|
|||||||
// callback
|
// callback
|
||||||
this._trigger('remove', null, this.ui($li.find('a')[0], $panel[0]));
|
this._trigger('remove', null, this.ui($li.find('a')[0], $panel[0]));
|
||||||
},
|
},
|
||||||
|
|
||||||
enable: function(index) {
|
enable: function(index) {
|
||||||
var o = this.options;
|
var o = this.options;
|
||||||
if ($.inArray(index, o.disabled) == -1)
|
if ($.inArray(index, o.disabled) == -1)
|
||||||
@ -369,6 +395,7 @@ $.widget("ui.tabs", {
|
|||||||
// callback
|
// callback
|
||||||
this._trigger('enable', null, this.ui(this.$tabs[index], this.$panels[index]));
|
this._trigger('enable', null, this.ui(this.$tabs[index], this.$panels[index]));
|
||||||
},
|
},
|
||||||
|
|
||||||
disable: function(index) {
|
disable: function(index) {
|
||||||
var self = this, o = this.options;
|
var self = this, o = this.options;
|
||||||
if (index != o.selected) { // cannot disable already selected tab
|
if (index != o.selected) { // cannot disable already selected tab
|
||||||
@ -381,12 +408,14 @@ $.widget("ui.tabs", {
|
|||||||
this._trigger('disable', null, this.ui(this.$tabs[index], this.$panels[index]));
|
this._trigger('disable', null, this.ui(this.$tabs[index], this.$panels[index]));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
select: function(index) {
|
select: function(index) {
|
||||||
// TODO make null as argument work
|
// TODO make null as argument work
|
||||||
if (typeof index == 'string')
|
if (typeof index == 'string')
|
||||||
index = this.$tabs.index( this.$tabs.filter('[href$=' + index + ']')[0] );
|
index = this.$tabs.index( this.$tabs.filter('[href$=' + index + ']')[0] );
|
||||||
this.$tabs.eq(index).trigger(this.options.event + '.tabs');
|
this.$tabs.eq(index).trigger(this.options.event + '.tabs');
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function(index, callback) { // callback is for internal usage only
|
load: function(index, callback) { // callback is for internal usage only
|
||||||
|
|
||||||
var self = this, o = this.options, $a = this.$tabs.eq(index), a = $a[0],
|
var self = this, o = this.options, $a = this.$tabs.eq(index), a = $a[0],
|
||||||
@ -451,61 +480,44 @@ $.widget("ui.tabs", {
|
|||||||
$a.addClass(o.loadingClass);
|
$a.addClass(o.loadingClass);
|
||||||
self.xhr = $.ajax(ajaxOptions);
|
self.xhr = $.ajax(ajaxOptions);
|
||||||
},
|
},
|
||||||
|
|
||||||
url: function(index, url) {
|
url: function(index, url) {
|
||||||
this.$tabs.eq(index).removeData('cache.tabs').data('load.tabs', url);
|
this.$tabs.eq(index).removeData('cache.tabs').data('load.tabs', url);
|
||||||
},
|
},
|
||||||
destroy: function() {
|
|
||||||
var o = this.options;
|
ui: function(tab, panel) {
|
||||||
this.element.unbind('.tabs')
|
return {
|
||||||
.removeClass(o.navClass).removeData('tabs');
|
options: this.options,
|
||||||
this.$tabs.each(function() {
|
tab: tab,
|
||||||
var href = $.data(this, 'href.tabs');
|
panel: panel,
|
||||||
if (href)
|
index: this.$tabs.index(tab)
|
||||||
this.href = href;
|
};
|
||||||
var $this = $(this).unbind('.tabs');
|
|
||||||
$.each(['href', 'load', 'cache'], function(i, prefix) {
|
|
||||||
$this.removeData(prefix + '.tabs');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.$lis.add(this.$panels).each(function() {
|
|
||||||
if ($.data(this, 'destroy.tabs'))
|
|
||||||
$(this).remove();
|
|
||||||
else
|
|
||||||
$(this).removeClass([o.selectedClass, o.deselectableClass,
|
|
||||||
o.disabledClass, o.panelClass, o.hideClass].join(' '));
|
|
||||||
});
|
|
||||||
if (o.cookie)
|
|
||||||
this._cookie(null, o.cookie);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$.extend($.ui.tabs, {
|
$.extend($.ui.tabs, {
|
||||||
version: '@VERSION',
|
version: '@VERSION',
|
||||||
getter: 'length',
|
getter: 'length',
|
||||||
defaults: {
|
defaults: {
|
||||||
// basic setup
|
|
||||||
deselectable: false,
|
|
||||||
event: 'click',
|
|
||||||
disabled: [],
|
|
||||||
cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
|
|
||||||
// Ajax
|
|
||||||
spinner: 'Loading…',
|
|
||||||
cache: false,
|
|
||||||
idPrefix: 'ui-tabs-',
|
|
||||||
ajaxOptions: null,
|
ajaxOptions: null,
|
||||||
// animations
|
cache: false,
|
||||||
fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
|
cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
|
||||||
// templates
|
deselectable: false,
|
||||||
tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>',
|
|
||||||
panelTemplate: '<div></div>',
|
|
||||||
// CSS class names
|
|
||||||
navClass: 'ui-tabs-nav',
|
|
||||||
selectedClass: 'ui-tabs-selected',
|
|
||||||
deselectableClass: 'ui-tabs-deselectable',
|
deselectableClass: 'ui-tabs-deselectable',
|
||||||
|
disabled: [],
|
||||||
disabledClass: 'ui-tabs-disabled',
|
disabledClass: 'ui-tabs-disabled',
|
||||||
panelClass: 'ui-tabs-panel',
|
event: 'click',
|
||||||
|
fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
|
||||||
hideClass: 'ui-tabs-hide',
|
hideClass: 'ui-tabs-hide',
|
||||||
loadingClass: 'ui-tabs-loading'
|
idPrefix: 'ui-tabs-',
|
||||||
|
loadingClass: 'ui-tabs-loading',
|
||||||
|
navClass: 'ui-tabs-nav',
|
||||||
|
panelClass: 'ui-tabs-panel',
|
||||||
|
panelTemplate: '<div></div>',
|
||||||
|
selectedClass: 'ui-tabs-selected',
|
||||||
|
spinner: 'Loading…',
|
||||||
|
tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user