Debian Codegraph @

resources/src/mediawiki.action/mediawiki.action.edit.collapsibleFooter.js

raw symbols SCIP
1 ( function () {
2 // Collapsible lists of categories and templates
3 // If changing or removing a storeKey, ensure there is a strategy for old keys.
4 // E.g. detect existence via requestIdleCallback and remove. (T121646)
5 const collapsibleLists = [
6 {
7 listSel: '.templatesUsed ul',
8 togglerSel: '.mw-templatesUsedExplanation',
9 storeKey: 'mwedit-state-templatesUsed'
10 },
11 {
12 listSel: '.hiddencats ul',
13 togglerSel: '.mw-hiddenCategoriesExplanation',
14 storeKey: 'mwedit-state-hiddenCategories'
15 },
16 {
17 listSel: '.preview-limit-report-wrapper',
18 togglerSel: '.mw-limitReportExplanation',
19 storeKey: 'mwedit-state-limitReport'
20 }
21 ];
22
23 const handleOne = function ( $list, $toggler, storeKey ) {
24 const collapsedVal = '0',
25 expandedVal = '1',
26 // Default to collapsed if not set
27 isCollapsed = mw.storage.get( storeKey ) !== expandedVal;
28
29 // Style the toggler with an arrow icon and add a tabIndex and a role for accessibility
30 $toggler.addClass( 'mw-editfooter-toggler' ).prop( 'tabIndex', 0 ).attr( 'role', 'button' );
31 $list.addClass( 'mw-editfooter-list' );
32
33 $list.makeCollapsible( {
34 $customTogglers: $toggler,
35 linksPassthru: true,
36 plainMode: true,
37 collapsed: isCollapsed
38 } );
39
40 if ( isCollapsed ) {
41 $toggler.addClass( 'mw-editfooter-toggler-collapsed' );
42 }
43
44 $list.on( 'beforeExpand.mw-collapsible', () => {
45 $toggler.removeClass( 'mw-editfooter-toggler-collapsed' );
46 mw.storage.set( storeKey, expandedVal );
47 } );
48
49 $list.on( 'beforeCollapse.mw-collapsible', () => {
50 $toggler.addClass( 'mw-editfooter-toggler-collapsed' );
51 mw.storage.set( storeKey, collapsedVal );
52 } );
53 };
54
55 mw.hook( 'wikipage.editform' ).add( ( $editForm ) => {
56 for ( let i = 0; i < collapsibleLists.length; i++ ) {
57 // Pass to a function for iteration-local variables
58 handleOne(
59 $editForm.find( collapsibleLists[ i ].listSel ),
60 $editForm.find( collapsibleLists[ i ].togglerSel ),
61 collapsibleLists[ i ].storeKey
62 );
63 }
64 } );
65 }() );