http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88625

Revision: 88625
Author:   krinkle
Date:     2011-05-22 23:52:16 +0000 (Sun, 22 May 2011)
Log Message:
-----------
jquery.tabIndex.js was broken, not it works (for the first time?)
* Defaulting to null
* Setting to initial value during first iteration (instead of outside the 
loop), that way we dont have to set minTabIndex to some insane high value to 
let if (  .. > .. ) work
* (bug 29048) jQuery.tabIndex: firstTabIndex() outputs the same as 
lastTabIndex()
* Added extra <textarea> to test suite to make sure the 'correct answer' is not 
the first or last element

Modified Paths:
--------------
    trunk/phase3/resources/jquery/jquery.tabIndex.js
    trunk/phase3/tests/qunit/index.html
    trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js

Modified: trunk/phase3/resources/jquery/jquery.tabIndex.js
===================================================================
--- trunk/phase3/resources/jquery/jquery.tabIndex.js    2011-05-22 23:52:07 UTC 
(rev 88624)
+++ trunk/phase3/resources/jquery/jquery.tabIndex.js    2011-05-22 23:52:16 UTC 
(rev 88625)
@@ -8,11 +8,13 @@
  * @return number Lowest tabindex on the page
  */
 $.fn.firstTabIndex = function() {
-       var minTabIndex = 0;
-       $(this).find( '[tabindex]' ).each( function() {
+       var minTabIndex = null;
+       $(this).find( '[tabindex]' ).each( function( i ) {
                var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 );
-               if ( tabIndex > minTabIndex ) {
+               if ( i === 0 ) {
                        minTabIndex = tabIndex;
+               } else if ( tabIndex < minTabIndex ) {
+                       minTabIndex = tabIndex;
                }
        } );
        return minTabIndex;
@@ -24,13 +26,15 @@
  * @return number Highest tabindex on the page
  */
 $.fn.lastTabIndex = function() {
-       var maxTabIndex = 0;
-       $(this).find( '[tabindex]' ).each( function() {
+       var maxTabIndex = null;
+       $(this).find( '[tabindex]' ).each( function( i ) {
                var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 );
-               if ( tabIndex > maxTabIndex ) {
+               if ( i === 0 ) {
                        maxTabIndex = tabIndex;
+               } else if ( tabIndex > maxTabIndex ) {
+                       maxTabIndex = tabIndex;
                }
        } );
        return maxTabIndex;
 };
-} )( jQuery );
\ No newline at end of file
+} )( jQuery );

Modified: trunk/phase3/tests/qunit/index.html
===================================================================
--- trunk/phase3/tests/qunit/index.html 2011-05-22 23:52:07 UTC (rev 88624)
+++ trunk/phase3/tests/qunit/index.html 2011-05-22 23:52:16 UTC (rev 88625)
@@ -47,6 +47,7 @@
        <script src="suites/resources/jquery/jquery.mwPrototypes.js"></script>
        <script 
src="suites/resources/mediawiki.util/mediawiki.util.js"></script>
        <script src="suites/resources/jquery/jquery.autoEllipsis.js"></script>
+       <script src="suites/resources/jquery/jquery.colorUtil.js"></script>
        <script src="suites/resources/jquery/jquery.tabIndex.js"></script>
 
        <!-- TestSwarm: If a test swarm is running this,

Modified: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js
===================================================================
--- trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js 
2011-05-22 23:52:07 UTC (rev 88624)
+++ trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js 
2011-05-22 23:52:16 UTC (rev 88625)
@@ -12,15 +12,20 @@
        var testEnvironment = 
 '<form>\
        <input tabindex="7" />\
-       <input tabindex="2" />\
-       <textarea tabindex="9">Foobar</textarea>\
+       <input tabindex="9" />\
+       <textarea tabindex="2">Foobar</textarea>\
+       <textarea tabindex="5">Foobar</textarea>\
 </form>';
-       var $test = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
+       var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
 
-       deepEqual( $test.firstTabIndex(), 2, 'First tabindex should be 2 within 
this context.' );
+       deepEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 
within this context.' );
 
+       var $testB = $( '<div />' );
+
+       deepEqual( $testB.firstTabIndex(), null, 'Return null if none 
available.' );
+
        // Clean up
-       $test.remove();
+       $testA.add( $testB).remove();
 });
 
 test( 'lastTabIndex', function(){
@@ -28,13 +33,18 @@
        var testEnvironment = 
 '<form>\
        <input tabindex="7" />\
-       <input tabindex="2" />\
-       <textarea tabindex="9">Foobar</textarea>\
+       <input tabindex="9" />\
+       <textarea tabindex="2">Foobar</textarea>\
+       <textarea tabindex="5">Foobar</textarea>\
 </form>';
-       var $test = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
+       var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
 
-       deepEqual( $test.lastTabIndex(), 9, 'Last tabindex should be 9 within 
this context.' );
+       deepEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within 
this context.' );
 
+       var $testB = $( '<div />' );
+
+       deepEqual( $testB.lastTabIndex(), null, 'Return null if none 
available.' );
+
        // Clean up
-       $test.remove();
+       $testA.add( $testB).remove();
 });
\ No newline at end of file


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to