summaryrefslogtreecommitdiff
path: root/resources/mediawiki.action/mediawiki.action.history.js
blob: 1b5b3a00a7c2b0041ae0efc771e3af51632b8ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * JavaScript for History action
 */
jQuery( function( $ ) {
	var $lis = $( 'ul#pagehistory li' );
	var updateDiffRadios = function() {
		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 ) {
				return true;
			}

			// this row has a checked radio button
			if ( $inputs.get(0).checked ) { 
				oldLi = true;
				$this.addClass( 'selected' );
				$inputs.eq(0).css( 'visibility', 'visible' );
				$inputs.eq(1).css( 'visibility', 'hidden' );
			} else if ( $inputs.get(1).checked ) {
				diffLi = true;
				$this.addClass( 'selected' );
				$inputs.eq(0).css( 'visibility', 'hidden' );
				$inputs.eq(1).css( 'visibility', 'visible' );
			} else { 
				// no radio is checked in this row
				if ( diffLi && oldLi ) {
					// We're below the selected radios
					$inputs.eq(0).css( 'visibility', 'visible' );
					$inputs.eq(1).css( 'visibility', 'hidden' );
	 			} else if ( diffLi ) {
					// We're between the selected radios
					$inputs.css( 'visibility', 'visible' );
				} else {
					// We're above the selected radios
					$inputs.eq(1).css( 'visibility', 'visible' );
					$inputs.eq(0).css( 'visibility', 'hidden' );
				}
			}
		});
		return true;
	};

	$( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( updateDiffRadios );
	updateDiffRadios();
});