Debian Codegraph @

resources/src/mediawiki.action/mediawiki.action.history.js

raw symbols SCIP
1 /*!
2 * JavaScript for History action
3 */
4 $( () => {
5 'use strict';
6
7 const $pagehistory = $( '#pagehistory' );
8 const $lis = $pagehistory.find( '.mw-contributions-list > li' );
9
10 /**
11 * @ignore
12 * @this Element input
13 * @param {jQuery.Event} e
14 * @return {boolean} False to cancel the default event
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 // Disable the hidden radio because it can still be selected with
35 // arrow keys on Firefox
36 $diffRadio.prop( 'disabled', true );
37 } else if ( $diffRadio.prop( 'checked' ) ) {
38 // The following classes are used here:
39 // * before
40 // * after
41 $li.addClass( 'selected ' + nextState );
42 nextState = 'between';
43 // Disable the hidden radio because it can still be selected with
44 // arrow keys on Firefox
45 $oldidRadio.prop( 'disabled', true );
46 } else {
47 // This list item has neither checked
48 // apply the appropriate class following the previous item.
49 // The following classes are used here:
50 // * before
51 // * after
52 $li.addClass( nextState );
53 // Disable or re-enable for Firefox, provided the revision is accessible
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 // Set initial state
67 updateDiffRadios();
68 } );