var el;
-// need to wait a bit for the pseudo animation...
-function defer(defered, ms) {
- var queue = defer.queue || (defer.queue = []);
- if (!queue.length) stop();
- queue.push(defered);
- setTimeout(function() {
- queue.shift()();
- if (!queue.length) start();
- }, ms || 100);
-}
-
module('tabs');
test('init', function() {
expect(9);
- var el = $('#tabs1').tabs();
+ el = $('#tabs1').tabs();
ok(true, '.tabs() called on element');
ok( el.is('.ui-tabs.ui-widget.ui-widget-content.ui-corner-all'), 'attach classes to container');
test('destroy', function() {
expect(5);
- var el = $('#tabs1').tabs();
+ el = $('#tabs1').tabs();
el.tabs('destroy');
ok( el.is(':not(.ui-tabs, .ui-widget, .ui-widget-content, .ui-corner-all)'), 'remove classes from container');
});
test("defaults", function() {
- el = $('#tabs1 > ul').tabs();
+ el = $('#tabs1').tabs();
$.each(defaults, function(key, val) {
var actual = el.data(key + '.tabs'), expected = val;
same(actual, expected, key);
test('remove', function() {
expect(4);
- var el = $('#tabs1').tabs();
+ el = $('#tabs1').tabs();
el.tabs('remove', 0);
equals(el.tabs('length'), 2, 'remove tab');
test('selected: null', function() {
expect(2);
- var el = $('#tabs1');
+ el = $('#tabs1');
el.tabs({ selected: null });
equals( $('li.ui-tabs-selected', el).length, 0, 'no tab should be selected' );
test('deselectable: true', function() {
expect(7);
- var el = $('#tabs1 > ul');
+ el = $('#tabs1');
el.tabs({ deselectable: true });
equals( el.data('deselectable.tabs'), true, 'option set' );
el.tabs('select', 1);
equals( $('li.ui-tabs-deselectable', el).length, 0, 'class "ui-tabs-deselectable" not attached');
- defer(function() {
- equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' );
- });
+ equals( $('div.ui-tabs-hide', '#tabs1').length, 3, 'all panels should be hidden' );
});
test('cookie', function() {
expect(6);
- var el = $('#tabs1 > ul');
- var cookieName = 'ui-tabs-' + $.data(el[0]);
+ el = $('#tabs1');
+ var cookieName = 'tabs_test', cookieObj = { name: cookieName };
$.cookie(cookieName, null); // blank state
var cookie = function() {
return parseInt($.cookie(cookieName), 10);
};
- el.tabs({ cookie: {} });
- equals(cookie(), 0, 'initial cookie value, no cookie given');
+ el.tabs({ cookie: cookieObj });
+ equals(cookie(), 0, 'initial cookie value');
el.tabs('destroy');
- el.tabs({ selected: 1, cookie: {} });
- equals(cookie(), 1, 'initial cookie value, given selected');
+ el.tabs({ selected: 1, cookie: cookieObj });
+ equals(cookie(), 1, 'initial cookie value, from selected property');
el.tabs('select', 2);
- equals(cookie(), 2, 'cookie value after tabs select');
-
+ equals(cookie(), 2, 'cookie value updated after select');
+
el.tabs('destroy');
$.cookie(cookieName, 1);
- el.tabs({ cookie: {} });
+ el.tabs({ cookie: cookieObj });
equals(cookie(), 1, 'initial cookie value, from existing cookie');
-
+
el.tabs('destroy');
- el.tabs({ cookie: {}, deselectable: true });
+ el.tabs({ cookie: cookieObj, deselectable: true });
el.tabs('select', 0);
- equals(cookie(), -1, 'cookie value for all unselected tabs');
+ equals(cookie(), -1, 'cookie value for all tabs unselected');
el.tabs('destroy');
ok($.cookie(cookieName) === null, 'erase cookie after destroy');
test('id containing colon, #2715', function() { // http://ui.jquery.com/bugs/ticket/2715
expect(4);
- var el = $('#tabs2 > ul').tabs();
+ el = $('#tabs2').tabs();
ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' );
ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' );
el.tabs('select', 1).tabs('select', 0);
- defer(function() {
- ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' );
- ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' );
- });
+ ok( $('div.ui-tabs-panel:eq(0)', '#tabs2').is(':visible'), 'first panel should be visible' );
+ ok( $('div.ui-tabs-panel:eq(1)', '#tabs2').is(':hidden'), 'second panel should be hidden' );
});
};
var expected = inlineStyle('height');
- var el = $('#tabs2').tabs();
+ el = $('#tabs2').tabs();
equals(inlineStyle('height'), expected, 'init should not remove inline style');
el.tabs('select', 1);
- defer(function() {
- equals(inlineStyle('height'), expected, 'show tab should not remove inline style');
+ equals(inlineStyle('height'), expected, 'show tab should not remove inline style');
- el.tabs('select', 0);
- defer(function() {
- equals(inlineStyle('height'), expected, 'hide tab should not remove inline style');
- });
-
- });
+ el.tabs('select', 0);
+ equals(inlineStyle('height'), expected, 'hide tab should not remove inline style');
});
test('Ajax tab with url containing a fragment identifier fails to load, #3627', function() { // http://ui.jquery.com/bugs/ticket/3627
expect(1);
- var el = $('#tabs2').tabs();
+ el = $('#tabs2').tabs();
equals( $('a:eq(2)', el).data('load.tabs'), 'test.html', 'should ignore fragment identifier' );
var cookie = this.cookie || (this.cookie = this.options.cookie.name || 'ui-tabs-' + $.data(this.list[0]));
return $.cookie.apply(null, [cookie].concat($.makeArray(arguments)));
},
-
+
_ui: function(tab, panel) {
return {
tab: tab,
// invalid tab href
else
- o.disabled.push(i + 1);
+ o.disabled.push(i);
});
// initialization from scratch
// attach tab event handler, unbind to avoid duplicates from former tabifying...
this.$tabs.unbind('.tabs').bind(o.event + '.tabs', function() {
-
var $li = $(this).parents('li:eq(0)'),
$hide = self.$panels.filter(':visible'),
$show = $(self._sanitizeSelector(this.hash));
if (o.event != 'click') this.$tabs.bind('click.tabs', function(){return false;});
},
-
+
destroy: function() {
var o = this.options;
- this.element
- .removeClass('ui-tabs ui-widget ui-widget-content ui-corner-all');
+ this.element.unbind('.tabs')
+ .removeClass('ui-tabs ui-widget ui-widget-content ui-corner-all')
+ .removeData('tabs');
this.list.unbind('.tabs')
.removeClass('ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all')
'ui-corner-top ' +
'ui-tabs-selected ' +
'ui-state-active ' +
+ 'ui-state-hover ' +
'ui-tabs-deselectable ' +
'ui-state-disabled ' +
'ui-tabs-panel ' +
// no remote or from cache - just finish with callback
// TODO in any case: insert cancel running load here..!
-
+
if (!url || !bypassCache && $.data(a, 'cache.tabs')) {
callback();
return;
url: function(index, url) {
this.$tabs.eq(index).removeData('cache.tabs').data('load.tabs', url);
},
-
+
length: function() {
return this.$tabs.length;
}