r88625 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88624‎ | r88625 | r88626 >
Date:23:52, 22 May 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/tests/qunit/index.html (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/index.html
@@ -47,6 +47,7 @@
4848 <script src="suites/resources/jquery/jquery.mwPrototypes.js"></script>
4949 <script src="suites/resources/mediawiki.util/mediawiki.util.js"></script>
5050 <script src="suites/resources/jquery/jquery.autoEllipsis.js"></script>
 51+ <script src="suites/resources/jquery/jquery.colorUtil.js"></script>
5152 <script src="suites/resources/jquery/jquery.tabIndex.js"></script>
5253
5354 <!-- TestSwarm: If a test swarm is running this,
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js
@@ -12,15 +12,20 @@
1313 var testEnvironment =
1414 '<form>\
1515 <input tabindex="7" />\
16 - <input tabindex="2" />\
17 - <textarea tabindex="9">Foobar</textarea>\
 16+ <input tabindex="9" />\
 17+ <textarea tabindex="2">Foobar</textarea>\
 18+ <textarea tabindex="5">Foobar</textarea>\
1819 </form>';
19 - var $test = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
 20+ var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
2021
21 - deepEqual( $test.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
 22+ deepEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
2223
 24+ var $testB = $( '<div />' );
 25+
 26+ deepEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
 27+
2328 // Clean up
24 - $test.remove();
 29+ $testA.add( $testB).remove();
2530 });
2631
2732 test( 'lastTabIndex', function(){
@@ -28,13 +33,18 @@
2934 var testEnvironment =
3035 '<form>\
3136 <input tabindex="7" />\
32 - <input tabindex="2" />\
33 - <textarea tabindex="9">Foobar</textarea>\
 37+ <input tabindex="9" />\
 38+ <textarea tabindex="2">Foobar</textarea>\
 39+ <textarea tabindex="5">Foobar</textarea>\
3440 </form>';
35 - var $test = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
 41+ var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
3642
37 - deepEqual( $test.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
 43+ deepEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
3844
 45+ var $testB = $( '<div />' );
 46+
 47+ deepEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
 48+
3949 // Clean up
40 - $test.remove();
 50+ $testA.add( $testB).remove();
4151 });
\ No newline at end of file
Index: trunk/phase3/resources/jquery/jquery.tabIndex.js
@@ -8,11 +8,13 @@
99 * @return number Lowest tabindex on the page
1010 */
1111 $.fn.firstTabIndex = function() {
12 - var minTabIndex = 0;
13 - $(this).find( '[tabindex]' ).each( function() {
 12+ var minTabIndex = null;
 13+ $(this).find( '[tabindex]' ).each( function( i ) {
1414 var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 );
15 - if ( tabIndex > minTabIndex ) {
 15+ if ( i === 0 ) {
1616 minTabIndex = tabIndex;
 17+ } else if ( tabIndex < minTabIndex ) {
 18+ minTabIndex = tabIndex;
1719 }
1820 } );
1921 return minTabIndex;
@@ -24,13 +26,15 @@
2527 * @return number Highest tabindex on the page
2628 */
2729 $.fn.lastTabIndex = function() {
28 - var maxTabIndex = 0;
29 - $(this).find( '[tabindex]' ).each( function() {
 30+ var maxTabIndex = null;
 31+ $(this).find( '[tabindex]' ).each( function( i ) {
3032 var tabIndex = parseInt( $(this).attr( 'tabindex' ), 10 );
31 - if ( tabIndex > maxTabIndex ) {
 33+ if ( i === 0 ) {
3234 maxTabIndex = tabIndex;
 35+ } else if ( tabIndex > maxTabIndex ) {
 36+ maxTabIndex = tabIndex;
3337 }
3438 } );
3539 return maxTabIndex;
3640 };
37 -} )( jQuery );
\ No newline at end of file
 41+} )( jQuery );

Follow-up revisions

RevisionCommit summaryAuthorDate
r88627Release notes for r88625, r88553, r88511 (bringing back 'Other changes' like ...krinkle00:01, 23 May 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88622Adding test suite for jquery.tabIndex.js, currently broken per:...krinkle23:36, 22 May 2011

Comments

#Comment by Krinkle (talk | contribs)   19:17, 28 May 2011

now*

Status & tagging log