aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKlaus Hartl <klaus.hartl@googlemail.com>2009-02-05 19:02:47 +0000
committerKlaus Hartl <klaus.hartl@googlemail.com>2009-02-05 19:02:47 +0000
commit8aee174cdb1846688b7c720c50ea6c715db5f0f3 (patch)
tree60d0fe10155c178a2796b9ab8aabbb2c6d128544
parentdd3636c97afe68ab931dfa2c5a8d2a1f60cbee2e (diff)
downloadjquery-ui-8aee174cdb1846688b7c720c50ea6c715db5f0f3.tar.gz
jquery-ui-8aee174cdb1846688b7c720c50ea6c715db5f0f3.zip
Tabs: Added tests for select method while at the same time implemented consistent handling of possible values to pass, addresses #4051
-rw-r--r--tests/unit/tabs/tabs_methods.js39
-rw-r--r--ui/ui.tabs.js21
2 files changed, 48 insertions, 12 deletions
diff --git a/tests/unit/tabs/tabs_methods.js b/tests/unit/tabs/tabs_methods.js
index 65f7f7a78..2fc309b57 100644
--- a/tests/unit/tabs/tabs_methods.js
+++ b/tests/unit/tabs/tabs_methods.js
@@ -19,7 +19,6 @@ test('init', function() {
equals( el.data('selected.tabs'), 0, 'selected.tabs set' );
equals( $('li', el).index( $('li.ui-tabs-selected', el) ), 0, 'second tab active');
equals( $('div', el).index( $('div.ui-tabs-hide', '#tabs1') ), 1, 'second panel should be hidden' );
-
});
test('destroy', function() {
@@ -33,7 +32,6 @@ test('destroy', function() {
ok( $('div:eq(1)', el).is(':not(.ui-tabs-panel, .ui-widget-content, .ui-corner-bottom, .ui-tabs-hide)'), 'remove classes to panel' );
ok( $('li:eq(0)', el).is(':not(.ui-tabs-selected, .ui-state-active, .ui-corner-top)'), 'remove classes from active li');
ok( $('li:eq(1)', el).is(':not(.ui-state-default, .ui-corner-top)'), 'remove classes from inactive li');
-
});
test('enable', function() {
@@ -67,7 +65,41 @@ test('remove', function() {
});
test('select', function() {
- ok(false, "missing test - untested code is broken code.");
+ expect(9);
+
+ el = $('#tabs1').tabs();
+
+ el.tabs('select', 1);
+ equals(el.data('selected.tabs'), 1, 'should select tab');
+
+ el.tabs('destroy');
+ el.tabs({ collapsible: true });
+ el.tabs('select', 0);
+ equals(el.data('selected.tabs'), -1, 'should collapse tab passing in the already selected tab');
+
+ el.tabs('destroy');
+ el.tabs({ collapsible: true });
+ el.tabs('select', -1);
+ equals(el.data('selected.tabs'), -1, 'should collapse tab passing in -1');
+
+ el.tabs('destroy');
+ el.tabs({ collapsible: true });
+ el.tabs('select', null);
+ equals(el.data('selected.tabs'), -1, 'should collapse tab passing in null (deprecated)');
+ el.tabs('select', null);
+ equals(el.data('selected.tabs'), -1, 'should not select tab passing in null a second time (deprecated)');
+
+ el.tabs('destroy');
+ el.tabs();
+ el.tabs('select', 0);
+ equals(el.data('selected.tabs'), 0, 'should not collapse tab if collapsible is not set to true');
+ el.tabs('select', -1);
+ equals(el.data('selected.tabs'), 0, 'should not collapse tab if collapsible is not set to true');
+ el.tabs('select', null);
+ equals(el.data('selected.tabs'), 0, 'should not collapse tab if collapsible is not set to true');
+
+ el.tabs('select', '#fragment-2');
+ equals(el.data('selected.tabs'), 1, 'should select tab by id');
});
test('load', function() {
@@ -83,7 +115,6 @@ test('length', function() {
el = $('#tabs1').tabs();
equals(el.tabs('length'), $('ul a', el).length, ' should return length');
-
});
test('rotate', function() {
diff --git a/ui/ui.tabs.js b/ui/ui.tabs.js
index 7d077b173..b80e51759 100644
--- a/ui/ui.tabs.js
+++ b/ui/ui.tabs.js
@@ -21,8 +21,9 @@ $.widget("ui.tabs", {
},
_setData: function(key, value) {
- if ((/^selected/).test(key))
+ if (key == 'selected')
this.select(value);
+
else {
this.options[key] = value;
if (key == 'deselectable')
@@ -311,7 +312,7 @@ $.widget("ui.tabs", {
if (o.cookie) self._cookie(o.selected, o.cookie);
// stop possibly running animations
- self.$panels.stop();
+ self.$panels.stop(false, true);
// show new tab
if ($show.length) {
@@ -474,19 +475,23 @@ $.widget("ui.tabs", {
select: function(index) {
if (typeof index == 'string')
index = this.$tabs.index(this.$tabs.filter('[href$=' + index + ']'));
+
+ else if (index === null)
+ index = -1;
+
+ if (index == -1 && this.options.collapsible)
+ index = this.options.selected;
+
this.$tabs.eq(index).trigger(this.options.event + '.tabs');
},
load: function(index, callback) { // callback is for internal usage only
-
+ callback = callback || function() {};
+
var self = this, o = this.options, $a = this.$tabs.eq(index), a = $a[0],
bypassCache = callback == undefined, url = $a.data('load.tabs');
- callback = callback || function() {};
-
- // no remote or from cache - just finish with callback
- // TODO in any case: insert cancel running load here..!
-
+ // not remote or from cache - just finish with callback
if (!url || !bypassCache && $.data(a, 'cache.tabs')) {
callback();
return;