Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js |
— | — | @@ -1,53 +1,71 @@ |
2 | | -/* |
| 2 | +/** |
3 | 3 | * JavaScript for History action |
4 | 4 | */ |
5 | | -jQuery( function( $ ) { |
6 | | - var $lis = $( 'ul#pagehistory li' ); |
7 | | - var updateDiffRadios = function() { |
| 5 | +jQuery( document ).ready( function ( $ ) { |
| 6 | + var $lis = $( '#pagehistory > li' ), |
| 7 | + $radios; |
| 8 | + |
| 9 | + /** |
| 10 | + * @context {Element} input |
| 11 | + * @param e {jQuery.Event} |
| 12 | + */ |
| 13 | + function updateDiffRadios() { |
8 | 14 | var diffLi = false, // the li where the diff radio is checked |
9 | 15 | oldLi = false; // the li where the oldid radio is checked |
10 | 16 | |
11 | 17 | if ( !$lis.length ) { |
12 | 18 | return true; |
13 | 19 | } |
14 | | - $lis.removeClass( 'selected' ); |
15 | | - $lis.each( function() { |
16 | | - var $this = $(this); |
17 | | - var $inputs = $this.find( 'input[type="radio"]' ); |
18 | | - if ( $inputs.length !== 2 ) { |
| 20 | + |
| 21 | + $lis |
| 22 | + .removeClass( 'selected' ) |
| 23 | + .each( function () { |
| 24 | + var $li = $(this), |
| 25 | + $inputs = $li.find( 'input[type="radio"]' ), |
| 26 | + $oldidRadio = $inputs.filter( '[name="oldid"]' ).eq(0), |
| 27 | + $diffRadio = $inputs.filter( '[name="diff"]' ).eq(0); |
| 28 | + |
| 29 | + if ( !$oldidRadio.length || !$diffRadio.length ) { |
19 | 30 | return true; |
20 | 31 | } |
21 | 32 | |
22 | | - // this row has a checked radio button |
23 | | - if ( $inputs.get(0).checked ) { |
| 33 | + if ( $oldidRadio.prop( 'checked' ) ) { |
24 | 34 | oldLi = true; |
25 | | - $this.addClass( 'selected' ); |
26 | | - $inputs.eq(0).css( 'visibility', 'visible' ); |
27 | | - $inputs.eq(1).css( 'visibility', 'hidden' ); |
28 | | - } else if ( $inputs.get(1).checked ) { |
| 35 | + $li.addClass( 'selected' ); |
| 36 | + $oldidRadio.css( 'visibility', 'visible' ); |
| 37 | + $diffRadio.css( 'visibility', 'hidden' ); |
| 38 | + |
| 39 | + } else if ( $diffRadio.prop( 'checked' ) ) { |
29 | 40 | diffLi = true; |
30 | | - $this.addClass( 'selected' ); |
31 | | - $inputs.eq(0).css( 'visibility', 'hidden' ); |
32 | | - $inputs.eq(1).css( 'visibility', 'visible' ); |
| 41 | + $li.addClass( 'selected' ); |
| 42 | + $oldidRadio.css( 'visibility', 'hidden' ); |
| 43 | + $diffRadio.css( 'visibility', 'visible' ); |
| 44 | + |
| 45 | + // This list item has neither checked |
33 | 46 | } else { |
34 | | - // no radio is checked in this row |
| 47 | + // We're below the selected radios |
35 | 48 | if ( diffLi && oldLi ) { |
36 | | - // We're below the selected radios |
37 | | - $inputs.eq(0).css( 'visibility', 'visible' ); |
38 | | - $inputs.eq(1).css( 'visibility', 'hidden' ); |
| 49 | + $oldidRadio.css( 'visibility', 'visible' ); |
| 50 | + $diffRadio.css( 'visibility', 'hidden' ); |
| 51 | + |
| 52 | + // We're between the selected radios |
39 | 53 | } else if ( diffLi ) { |
40 | | - // We're between the selected radios |
41 | | - $inputs.css( 'visibility', 'visible' ); |
| 54 | + $diffRadio.css( 'visibility', 'visible' ); |
| 55 | + $oldidRadio.css( 'visibility', 'visible' ); |
| 56 | + |
| 57 | + // We're above the selected radios |
42 | 58 | } else { |
43 | | - // We're above the selected radios |
44 | | - $inputs.eq(1).css( 'visibility', 'visible' ); |
45 | | - $inputs.eq(0).css( 'visibility', 'hidden' ); |
| 59 | + $diffRadio.css( 'visibility', 'visible' ); |
| 60 | + $oldidRadio.css( 'visibility', 'hidden' ); |
46 | 61 | } |
47 | 62 | } |
48 | 63 | }); |
| 64 | + |
49 | 65 | return true; |
50 | | - }; |
| 66 | + } |
51 | 67 | |
52 | | - $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( updateDiffRadios ); |
| 68 | + $radios = $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( updateDiffRadios ); |
| 69 | + |
| 70 | + // Set initial state |
53 | 71 | updateDiffRadios(); |
54 | | -}); |
\ No newline at end of file |
| 72 | +} ); |