]> source.dussan.org Git - jquery-ui.git/commitdiff
Tab: modified init to display correct content of misordered div when hash present...
authorjenters <github@darkdark.net>
Wed, 29 Sep 2010 17:32:43 +0000 (12:32 -0500)
committerScott González <scott.gonzalez@gmail.com>
Mon, 4 Oct 2010 14:40:27 +0000 (10:40 -0400)
tests/unit/tabs/tabs.html
tests/unit/tabs/tabs_methods.js
ui/jquery.ui.tabs.js

index aa79ddabb69e6d819881f03876b10578140ed0b2..115a931f0f1a996eb5991fac4e709aa8e86e3c35 100644 (file)
@@ -61,7 +61,7 @@
                                <li><a href="#colon:test"><span>1</span></a></li>
                                <li><a href="#inline-style"><span>2</span></a></li>
                                <li><a href="data/test.html#test"><span>3</span></a></li>
-                               <li><a href="data/test.html" title="∫ßáö Սե"<span>4</span></a></li>
+                               <li><a href="data/test.html" title="∫ßáö Սե"><span>4</span></a></li>
                        </ul>
                        <div id="colon:test"></div>
                        <div style="height: 300px;" id="inline-style"></div>
                        <div id="tabs6-1"></div>
                        <div id="tabs6-2"></div>
                </div>
+               <div id="tabs7">
+                       <ul id="tabs7-list">
+                               <li><a href="#tabs7-1">1</a></li>
+                               <li><a href="#tabs7-2">2</a></li>
+                       </ul>
+                       <div id="tabs7-2"></div>
+                       <div id="tabs7-1"></div>
+               </div>
        </div>
 </body>
 </html>
index 3812c3e917f1d415c2e9bb7565d87007127abf6f..67a4d9b47928f0cae60cf9280d7cd879bd566d54 100644 (file)
@@ -21,6 +21,42 @@ test('init', function() {
        equals( $('div', el).index( $('div.ui-tabs-hide', '#tabs1') ), 1, 'second panel should be hidden' );
 });
 
+test('init with hash', function() {
+       expect(5);
+       
+       //set a hash in the url
+       location.hash = '#fragment-2';
+       
+       //selection of tab with divs ordered differently than list
+       el = $('#tabs1').tabs();
+       
+       equals(el.tabs('option', 'selected'), 1, 'second tab should be selected');
+       
+       ok(!$('#tabs1 ul li:eq(0)').is('.ui-tabs-selected.ui-state-active'), 'first tab should not be selected nor active');
+       ok($('#tabs1 div:eq(0)').is('.ui-tabs-hide'), 'first div for first tab should be hidden');
+       
+       ok($('#tabs1 ul li:eq(1)').is('.ui-tabs-selected.ui-state-active'), 'second tab should be selected and active');
+       ok(!$('#tabs1 div:eq(1)').is('.ui-tabs-hide'), 'second div for second tab should not be hidden');
+});
+
+test('init mismatched order with hash', function() {
+       expect(5);
+       
+       //set a hash in the url
+       location.hash = '#tabs7-2';
+       
+       //selection of tab with divs ordered differently than list
+       el = $('#tabs7').tabs();
+       
+       equals(el.tabs('option', 'selected'), 1, 'second tab should be selected');
+       
+       ok(!$('#tabs7-list li:eq(0)').is('.ui-tabs-selected.ui-state-active'), 'first tab should not be selected nor active');
+       ok($('#tabs7 div:eq(1)').is('.ui-tabs-hide'), 'second div for first tab should be hidden');
+       
+       ok($('#tabs7-list li:eq(1)').is('.ui-tabs-selected.ui-state-active'), 'second tab should be selected and active');
+       ok(!$('#tabs7 div:eq(0)').is('.ui-tabs-hide'), 'first div for second tab should not be hidden');
+});
+
 test('destroy', function() {
        expect(6);
 
index 7f7a631ee49cb05d791632a24bf3bbb262755a11..ad99a99b782990286fc6464ec2382ec26389b55f 100644 (file)
@@ -210,13 +210,13 @@ $.widget( "ui.tabs", {
                        this.lis.removeClass( "ui-tabs-selected ui-state-active" );
                        // check for length avoids error when initializing empty list
                        if ( o.selected >= 0 && this.anchors.length ) {
-                               this.panels.eq( o.selected ).removeClass( "ui-tabs-hide" );
+                               $( self._sanitizeSelector( self.anchors[ o.selected ].hash ) ).removeClass( "ui-tabs-hide" );
                                this.lis.eq( o.selected ).addClass( "ui-tabs-selected ui-state-active" );
 
                                // seems to be expected behavior that the show callback is fired
                                self.element.queue( "tabs", function() {
                                        self._trigger( "show", null,
-                                               self._ui( self.anchors[ o.selected ], self.panels[ o.selected ] ) );
+                                               self._ui( self.anchors[ o.selected ], $( self._sanitizeSelector( self.anchors[ o.selected ].hash ) ) ) );
                                });
 
                                this.load( o.selected );