Debian Codegraph @

skins/MinervaNeue/resources/skins.minerva.scripts/Toolbar.js

raw symbols SCIP
1 const
2 mobile = require( 'mobile.startup' ),
3 ToggleList = require( '../../includes/Skins/ToggleList/ToggleList.js' ),
4 page = mobile.currentPage(),
5 // The top level menu.
6 selector = '.page-actions-menu',
7 // The secondary overflow submenu component container.
8 overflowSubmenuSelector = '#page-actions-overflow',
9 overflowListSelector = '.toggle-list__list';
10
11 /**
12 * @param {Window} window
13 * @param {Element} toolbar
14 * @ignore
15 */
16 function bind( window, toolbar ) {
17 const overflowSubmenu = toolbar.querySelector( overflowSubmenuSelector );
18 if ( overflowSubmenu ) {
19 ToggleList.bind( window, overflowSubmenu );
20 }
21 }
22
23 /**
24 * @param {Window} window
25 * @param {Element} toolbar
26 * @ignore
27 */
28 function render( window, toolbar ) {
29 const overflowList = toolbar.querySelector( overflowListSelector );
30 checkForReadOnlyMode();
31 renderDownloadButton( window, overflowList );
32 }
33
34 /**
35 * Initialize page edit action link (#ca-edit) for read only mode.
36 * (e.g. when $wgReadOnly is set in LocalSettings.php)
37 *
38 * Mark the edit link as disabled if the user is not actually able to edit the page for some
39 * reason (e.g. page is protected or user is blocked).
40 *
41 * Note that the link is still clickable, but clicking it will probably open a view-source
42 * form or display an error message, rather than open an edit form.
43 *
44 * This check occurs in JavaScript as anonymous page views are cached
45 * in Varnish.
46 *
47 * @ignore
48 */
49 function checkForReadOnlyMode() {
50 if ( mw.config.get( 'wgMinervaReadOnly' ) ) {
51 document.body.classList.add( 'minerva-read-only' );
52 }
53 }
54
55 /**
56 * Initialize and inject the download button
57 *
58 * There are many restrictions when we can show the download button, this function should handle
59 * all device/os/operating system related checks and if device supports printing it will inject
60 * the Download icon
61 *
62 * @ignore
63 * @param {Window} window
64 * @param {Element|null} overflowList
65 */
66 function renderDownloadButton( window, overflowList ) {
67 const downloadPageAction = require( './downloadPageAction.js' ).downloadPageAction,
68 $downloadAction = downloadPageAction( page,
69 mw.config.get( 'wgMinervaDownloadNamespaces', [] ), window, !!overflowList );
70
71 if ( $downloadAction ) {
72 mw.track( 'minerva.downloadAsPDF', {
73 action: 'buttonVisible'
74 } );
75 }
76 }
77
78 module.exports = {
79 selector,
80 bind,
81 render
82 };