https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108373
Revision: 108373
Author: krinkle
Date: 2012-01-08 22:36:13 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
[mediawiki.action.history.js] Clean up
* Using named variables instead of eq(0) and eq(1), also future proof by
checking name="" instead of depending on their respective position in the DOM.
Modified Paths:
--------------
trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js
Modified: trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js
===================================================================
--- trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js
2012-01-08 22:32:11 UTC (rev 108372)
+++ trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js
2012-01-08 22:36:13 UTC (rev 108373)
@@ -1,53 +1,71 @@
-/*
+/**
* JavaScript for History action
*/
-jQuery( function( $ ) {
- var $lis = $( 'ul#pagehistory li' );
- var updateDiffRadios = function() {
+jQuery( document ).ready( function ( $ ) {
+ var $lis = $( '#pagehistory > li' ),
+ $radios;
+
+ /**
+ * @context {Element} input
+ * @param e {jQuery.Event}
+ */
+ function updateDiffRadios() {
var diffLi = false, // the li where the diff radio is checked
oldLi = false; // the li where the oldid radio is
checked
if ( !$lis.length ) {
return true;
}
- $lis.removeClass( 'selected' );
- $lis.each( function() {
- var $this = $(this);
- var $inputs = $this.find( 'input[type="radio"]' );
- if ( $inputs.length !== 2 ) {
+
+ $lis
+ .removeClass( 'selected' )
+ .each( function () {
+ var $li = $(this),
+ $inputs = $li.find( 'input[type="radio"]' ),
+ $oldidRadio = $inputs.filter( '[name="oldid"]'
).eq(0),
+ $diffRadio = $inputs.filter( '[name="diff"]'
).eq(0);
+
+ if ( !$oldidRadio.length || !$diffRadio.length ) {
return true;
}
- // this row has a checked radio button
- if ( $inputs.get(0).checked ) {
+ if ( $oldidRadio.prop( 'checked' ) ) {
oldLi = true;
- $this.addClass( 'selected' );
- $inputs.eq(0).css( 'visibility', 'visible' );
- $inputs.eq(1).css( 'visibility', 'hidden' );
- } else if ( $inputs.get(1).checked ) {
+ $li.addClass( 'selected' );
+ $oldidRadio.css( 'visibility', 'visible' );
+ $diffRadio.css( 'visibility', 'hidden' );
+
+ } else if ( $diffRadio.prop( 'checked' ) ) {
diffLi = true;
- $this.addClass( 'selected' );
- $inputs.eq(0).css( 'visibility', 'hidden' );
- $inputs.eq(1).css( 'visibility', 'visible' );
+ $li.addClass( 'selected' );
+ $oldidRadio.css( 'visibility', 'hidden' );
+ $diffRadio.css( 'visibility', 'visible' );
+
+ // This list item has neither checked
} else {
- // no radio is checked in this row
+ // We're below the selected radios
if ( diffLi && oldLi ) {
- // We're below the selected radios
- $inputs.eq(0).css( 'visibility',
'visible' );
- $inputs.eq(1).css( 'visibility',
'hidden' );
+ $oldidRadio.css( 'visibility',
'visible' );
+ $diffRadio.css( 'visibility', 'hidden'
);
+
+ // We're between the selected radios
} else if ( diffLi ) {
- // We're between the selected radios
- $inputs.css( 'visibility', 'visible' );
+ $diffRadio.css( 'visibility', 'visible'
);
+ $oldidRadio.css( 'visibility',
'visible' );
+
+ // We're above the selected radios
} else {
- // We're above the selected radios
- $inputs.eq(1).css( 'visibility',
'visible' );
- $inputs.eq(0).css( 'visibility',
'hidden' );
+ $diffRadio.css( 'visibility', 'visible'
);
+ $oldidRadio.css( 'visibility', 'hidden'
);
}
}
});
+
return true;
- };
+ }
- $( '#pagehistory li input[name="diff"], #pagehistory li
input[name="oldid"]' ).click( updateDiffRadios );
+ $radios = $( '#pagehistory li input[name="diff"], #pagehistory li
input[name="oldid"]' ).click( updateDiffRadios );
+
+ // Set initial state
updateDiffRadios();
-});
\ No newline at end of file
+} );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs