Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / resources / src / mediawiki.action / mediawiki.action.edit.collapsibleFooter.js
blob011f9c55efc6e18b0b8459ab9421069f20619989
1 ( function ( mw ) {
2         var collapsibleLists, handleOne;
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         ];
23         handleOne = function ( $list, $toggler, cookieName ) {
24                 // Collapsed by default
25                 var isCollapsed = mw.cookie.get( cookieName ) !== 'expanded';
27                 // Style the toggler with an arrow icon and add a tabIndex and a role for accessibility
28                 $toggler.addClass( 'mw-editfooter-toggler' ).prop( 'tabIndex', 0 ).attr( 'role', 'button' );
29                 $list.addClass( 'mw-editfooter-list' );
31                 $list.makeCollapsible( {
32                         $customTogglers: $toggler,
33                         linksPassthru: true,
34                         plainMode: true,
35                         collapsed: isCollapsed
36                 } );
38                 $toggler.addClass( isCollapsed ? 'mw-icon-arrow-collapsed' : 'mw-icon-arrow-expanded' );
40                 $list.on( 'beforeExpand.mw-collapsible', function () {
41                         $toggler.removeClass( 'mw-icon-arrow-collapsed' ).addClass( 'mw-icon-arrow-expanded' );
42                         mw.cookie.set( cookieName, 'expanded' );
43                 } );
45                 $list.on( 'beforeCollapse.mw-collapsible', function () {
46                         $toggler.removeClass( 'mw-icon-arrow-expanded' ).addClass( 'mw-icon-arrow-collapsed' );
47                         mw.cookie.set( cookieName, 'collapsed' );
48                 } );
49         };
51         mw.hook( 'wikipage.editform' ).add( function ( $editForm ) {
52                 var i;
53                 for ( i = 0; i < collapsibleLists.length; i++ ) {
54                         // Pass to a function for iteration-local variables
55                         handleOne(
56                                 $editForm.find( collapsibleLists[ i ].listSel ),
57                                 $editForm.find( collapsibleLists[ i ].togglerSel ),
58                                 collapsibleLists[ i ].cookieName
59                         );
60                 }
61         } );
62 }( mediaWiki ) );