2019-04-04 21:20:39 +00:00
|
|
|
( function ( M ) {
|
|
|
|
var
|
|
|
|
mobile = M.require( 'mobile.startup' ),
|
2021-10-19 18:45:43 +00:00
|
|
|
ToggleList = require( '../../includes/Skins/ToggleList/ToggleList.js' ),
|
2019-04-04 21:20:39 +00:00
|
|
|
Icon = mobile.Icon,
|
2019-07-31 23:17:20 +00:00
|
|
|
page = mobile.currentPage(),
|
2019-04-04 21:20:39 +00:00
|
|
|
/** The top level menu. */
|
|
|
|
toolbarSelector = '.page-actions-menu',
|
|
|
|
/** The secondary overflow submenu component container. */
|
|
|
|
overflowSubmenuSelector = '#page-actions-overflow',
|
2019-06-20 19:17:50 +00:00
|
|
|
overflowListSelector = '.toggle-list__list';
|
2019-04-04 21:20:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Window} window
|
|
|
|
* @param {Element} toolbar
|
|
|
|
*/
|
2019-07-31 17:36:19 +00:00
|
|
|
function bind( window, toolbar ) {
|
2019-06-20 19:17:50 +00:00
|
|
|
var overflowSubmenu = toolbar.querySelector( overflowSubmenuSelector );
|
2019-04-04 21:20:39 +00:00
|
|
|
if ( overflowSubmenu ) {
|
2019-07-31 17:36:19 +00:00
|
|
|
ToggleList.bind( window, overflowSubmenu );
|
2019-04-04 21:20:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Window} window
|
|
|
|
* @param {Element} toolbar
|
|
|
|
*/
|
|
|
|
function render( window, toolbar ) {
|
2019-07-31 17:36:19 +00:00
|
|
|
var overflowList = toolbar.querySelector( overflowListSelector );
|
2019-04-04 21:20:39 +00:00
|
|
|
renderEditButton();
|
|
|
|
renderDownloadButton( window, overflowList );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize page edit action link (#ca-edit)
|
|
|
|
*
|
|
|
|
* Mark the edit link as disabled if the user is not actually able to edit the page for some
|
|
|
|
* reason (e.g. page is protected or user is blocked).
|
|
|
|
*
|
|
|
|
* Note that the link is still clickable, but clicking it will probably open a view-source
|
|
|
|
* form or display an error message, rather than open an edit form.
|
|
|
|
*
|
|
|
|
* FIXME: Review this code as part of T206262
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function renderEditButton() {
|
|
|
|
var
|
|
|
|
// FIXME: create a utility method to generate class names instead of
|
|
|
|
// constructing temporary objects. This affects disabledEditIcon,
|
|
|
|
// enabledEditIcon, enabledEditIcon, and disabledClass and
|
|
|
|
// a number of other places in the code base.
|
|
|
|
disabledEditIcon = new Icon( {
|
2020-03-25 02:02:02 +00:00
|
|
|
name: 'editLock-base20',
|
|
|
|
glyphPrefix: 'wikimedia'
|
2019-04-04 21:20:39 +00:00
|
|
|
} ),
|
|
|
|
enabledEditIcon = new Icon( {
|
2020-03-25 02:02:02 +00:00
|
|
|
name: 'edit-base20',
|
|
|
|
glyphPrefix: 'wikimedia'
|
2019-04-04 21:20:39 +00:00
|
|
|
} ),
|
|
|
|
enabledClass = enabledEditIcon.getGlyphClassName(),
|
|
|
|
disabledClass = disabledEditIcon.getGlyphClassName();
|
|
|
|
|
|
|
|
if ( mw.config.get( 'wgMinervaReadOnly' ) ) {
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2023-09-27 00:17:21 +00:00
|
|
|
$( '#ca-edit,#ca-editsource,#ca-ve-edit' )
|
2019-04-04 21:20:39 +00:00
|
|
|
.removeClass( enabledClass )
|
|
|
|
.addClass( disabledClass );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize and inject the download button
|
|
|
|
*
|
|
|
|
* There are many restrictions when we can show the download button, this function should handle
|
|
|
|
* all device/os/operating system related checks and if device supports printing it will inject
|
|
|
|
* the Download icon
|
2020-06-02 21:21:44 +00:00
|
|
|
*
|
2019-04-04 21:20:39 +00:00
|
|
|
* @param {Window} window
|
|
|
|
* @param {Element|null} overflowList
|
|
|
|
*/
|
|
|
|
function renderDownloadButton( window, overflowList ) {
|
2019-12-18 21:15:26 +00:00
|
|
|
var downloadPageAction = require( './downloadPageAction.js' ).downloadPageAction,
|
|
|
|
$downloadAction = downloadPageAction( page,
|
|
|
|
mw.config.get( 'wgMinervaDownloadNamespaces', [] ), window, !!overflowList );
|
2019-04-04 21:20:39 +00:00
|
|
|
|
|
|
|
if ( $downloadAction ) {
|
|
|
|
mw.track( 'minerva.downloadAsPDF', {
|
|
|
|
action: 'buttonVisible'
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 21:10:10 +00:00
|
|
|
module.exports = {
|
2019-04-04 21:20:39 +00:00
|
|
|
selector: toolbarSelector,
|
|
|
|
bind: bind,
|
|
|
|
render: render
|
2019-07-02 21:10:10 +00:00
|
|
|
};
|
2019-09-27 18:53:01 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line no-restricted-properties
|
2019-04-04 21:20:39 +00:00
|
|
|
}( mw.mobileFrontend ) );
|