2 * JavaScript for History action
4 jQuery( function( $ ) {
5 var $lis
= $( 'ul#pagehistory li' );
6 var updateDiffRadios = function() {
7 var diffLi
= false, // the li where the diff radio is checked
8 oldLi
= false; // the li where the oldid radio is checked
13 $lis
.removeClass( 'selected' );
14 $lis
.each( function() {
16 var $inputs
= $this.find( 'input[type=radio]' );
17 if ( $inputs
.length
!== 2 ) {
21 // this row has a checked radio button
22 if ( $inputs
.get(0).checked
) {
24 $this.addClass( 'selected' );
25 $inputs
.eq(0).css( 'visibility', 'visible' );
26 $inputs
.eq(1).css( 'visibility', 'hidden' );
27 } else if ( $inputs
.get(1).checked
) {
29 $this.addClass( 'selected' );
30 $inputs
.eq(0).css( 'visibility', 'hidden' );
31 $inputs
.eq(1).css( 'visibility', 'visible' );
33 // no radio is checked in this row
34 if ( diffLi
&& oldLi
) {
35 // We're below the selected radios
36 $inputs
.eq(0).css( 'visibility', 'visible' );
37 $inputs
.eq(1).css( 'visibility', 'hidden' );
38 } else if ( diffLi
) {
39 // We're between the selected radios
40 $inputs
.css( 'visibility', 'visible' );
42 // We're above the selected radios
43 $inputs
.eq(1).css( 'visibility', 'visible' );
44 $inputs
.eq(0).css( 'visibility', 'hidden' );
51 var fixCompare = function () {
52 var $diffList
= $( '#pagehistory' ),
53 $histForm
= $( '#mw-history-compare' ),
54 $buttons
= $histForm
.find( 'input.historysubmit' );
56 // There's only one rev, nothing to do here
57 if ( !$buttons
.length
) {
60 var copyAttrs
= ['title', 'accesskey'];
61 $buttons
.each(function() {
62 var $button
= $(this),
63 $compareLink
= $( '<a></a>', {
64 'class': 'compare-link',
67 $.each(copyAttrs
, function(i
, name
) {
68 var val
= $button
.attr(name
);
70 $compareLink
.attr(name
, val
);
73 $button
.replaceWith($compareLink
);
75 var updateCompare = function() {
76 var $radio
= $histForm
.find( 'input[type=radio]:checked' );
77 var genLink
= mw
.config
.get( 'wgScript' )
78 + '?title=' + mw
.util
.wikiUrlencode( mw
.config
.get( 'wgPageName' ) )
79 + '&diff=' + $radio
.eq(0).val()
80 + '&oldid=' + $radio
.eq(1).val();
81 $( '.compare-link' ).each( function() {
82 $(this).attr('href', genLink
);
86 $diffList
.change( updateCompare
);
89 $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( updateDiffRadios
);