| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
$( () => { |
| 5 |
'use strict'; |
| 6 |
|
| 7 |
const $pagehistory = $( '#pagehistory' ); |
| 8 |
const $lis = $pagehistory.find( '.mw-contributions-list > li' ); |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
function updateDiffRadios() { |
| 17 |
let nextState = 'before'; |
| 18 |
|
| 19 |
$lis.each( function () { |
| 20 |
const $li = $( this ); |
| 21 |
const $inputs = $li.find( 'input[type="radio"]' ); |
| 22 |
const $oldidRadio = $inputs.filter( '[name="oldid"]' ).eq( 0 ); |
| 23 |
const $diffRadio = $inputs.filter( '[name="diff"]' ).eq( 0 ); |
| 24 |
|
| 25 |
$li.removeClass( 'selected between before after' ); |
| 26 |
|
| 27 |
if ( !$oldidRadio.length || !$diffRadio.length ) { |
| 28 |
return true; |
| 29 |
} |
| 30 |
|
| 31 |
if ( $oldidRadio.prop( 'checked' ) ) { |
| 32 |
$li.addClass( 'selected after' ); |
| 33 |
nextState = 'after'; |
| 34 |
|
| 35 |
|
| 36 |
$diffRadio.prop( 'disabled', true ); |
| 37 |
} else if ( $diffRadio.prop( 'checked' ) ) { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
$li.addClass( 'selected ' + nextState ); |
| 42 |
nextState = 'between'; |
| 43 |
|
| 44 |
|
| 45 |
$oldidRadio.prop( 'disabled', true ); |
| 46 |
} else { |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
$li.addClass( nextState ); |
| 53 |
|
| 54 |
if ( $li.find( 'a.mw-changeslist-date' ).length ) { |
| 55 |
$oldidRadio.prop( 'disabled', nextState === 'before' ); |
| 56 |
$diffRadio.prop( 'disabled', nextState === 'after' ); |
| 57 |
} |
| 58 |
} |
| 59 |
} ); |
| 60 |
|
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
$pagehistory.on( 'change', 'input[name="diff"], input[name="oldid"]', updateDiffRadios ); |
| 65 |
|
| 66 |
|
| 67 |
updateDiffRadios(); |
| 68 |
} ); |