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