Merge "registration: Fix 'ResourceModules' in schema"
[lhc/web/wiklou.git] / resources / src / mediawiki.action / mediawiki.action.edit.collapsibleFooter.js
1 ( function ( mw, $ ) {
2 var collapsibleLists, handleOne;
3
4 // Collapsible lists of categories and templates
5 collapsibleLists = [
6 {
7 listSel: '.templatesUsed ul',
8 togglerSel: '.mw-templatesUsedExplanation',
9 cookieName: 'templates-used-list'
10 },
11 {
12 listSel: '.hiddencats ul',
13 togglerSel: '.mw-hiddenCategoriesExplanation',
14 cookieName: 'hidden-categories-list'
15 },
16 {
17 listSel: '.preview-limit-report-wrapper',
18 togglerSel: '.mw-limitReportExplanation',
19 cookieName: 'preview-limit-report'
20 }
21 ];
22
23 handleOne = function ( $list, $toggler, cookieName ) {
24 var isCollapsed = $.cookie( cookieName ) !== 'expanded';
25
26 // Style the toggler with an arrow icon and add a tabIndex and a role for accessibility
27 $toggler.addClass( 'mw-editfooter-toggler' ).prop( 'tabIndex', 0 ).attr( 'role', 'button' );
28 $list.addClass( 'mw-editfooter-list' );
29
30 $list.makeCollapsible( {
31 $customTogglers: $toggler,
32 linksPassthru: true,
33 plainMode: true,
34 collapsed: isCollapsed
35 } );
36
37 $toggler.addClass( isCollapsed ? 'mw-icon-arrow-collapsed' : 'mw-icon-arrow-expanded' );
38
39 $list.on( 'beforeExpand.mw-collapsible', function () {
40 $toggler.removeClass( 'mw-icon-arrow-collapsed' ).addClass( 'mw-icon-arrow-expanded' );
41 $.cookie( cookieName, 'expanded' );
42 } );
43
44 $list.on( 'beforeCollapse.mw-collapsible', function () {
45 $toggler.removeClass( 'mw-icon-arrow-expanded' ).addClass( 'mw-icon-arrow-collapsed' );
46 $.cookie( cookieName, 'collapsed' );
47 } );
48 };
49
50 mw.hook( 'wikipage.editform' ).add( function ( $editForm ) {
51 var i;
52 for ( i = 0; i < collapsibleLists.length; i++ ) {
53 // Pass to a function for iteration-local variables
54 handleOne(
55 $editForm.find( collapsibleLists[i].listSel ),
56 $editForm.find( collapsibleLists[i].togglerSel ),
57 collapsibleLists[i].cookieName
58 );
59 }
60 } );
61 }( mediaWiki, jQuery ) );