2018-11-16 15:16:25 +00:00
|
|
|
( function ( M, track, config ) {
|
2017-10-27 17:09:46 +00:00
|
|
|
var
|
2019-02-07 16:34:18 +00:00
|
|
|
mobile = M.require( 'mobile.startup' ),
|
2019-02-08 19:29:14 +00:00
|
|
|
PageGateway = mobile.PageGateway,
|
2019-02-07 16:34:18 +00:00
|
|
|
toast = mobile.toast,
|
|
|
|
time = mobile.time,
|
2017-10-18 21:03:51 +00:00
|
|
|
skin = M.require( 'mobile.init/skin' ),
|
2018-08-16 19:00:38 +00:00
|
|
|
issues = M.require( 'skins.minerva.scripts/pageIssues' ),
|
2018-11-08 00:06:54 +00:00
|
|
|
downloadPageAction = M.require( 'skins.minerva.scripts/downloadPageAction' ),
|
2019-02-07 16:34:18 +00:00
|
|
|
loader = mobile.rlModuleLoader,
|
2017-07-12 15:12:40 +00:00
|
|
|
router = require( 'mediawiki.router' ),
|
2019-02-07 16:34:18 +00:00
|
|
|
OverlayManager = mobile.OverlayManager,
|
|
|
|
CtaDrawer = mobile.CtaDrawer,
|
|
|
|
Icon = mobile.Icon,
|
|
|
|
Button = mobile.Button,
|
|
|
|
Anchor = mobile.Anchor,
|
2018-11-08 15:12:53 +00:00
|
|
|
overlayManager = OverlayManager.getSingleton(),
|
2017-07-12 15:12:40 +00:00
|
|
|
page = M.getCurrentPage(),
|
2018-07-26 10:47:05 +00:00
|
|
|
api = new mw.Api(),
|
2018-12-04 22:13:38 +00:00
|
|
|
thumbs = page.getThumbnails(),
|
2019-02-07 16:34:18 +00:00
|
|
|
eventBus = mobile.eventBusSingleton;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for clicking on an image thumbnail
|
2018-07-03 14:50:09 +00:00
|
|
|
* @param {JQuery.Event} ev
|
2017-07-12 15:12:40 +00:00
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function onClickImage( ev ) {
|
2018-11-19 20:00:47 +00:00
|
|
|
// Do not interfere with non-left clicks or if modifier keys are pressed.
|
|
|
|
if ( ( ev.button !== 0 && ev.which !== 1 ) ||
|
|
|
|
ev.altKey || ev.ctrlKey || ev.shiftKey || ev.metaKey ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
ev.preventDefault();
|
2018-03-05 20:42:00 +00:00
|
|
|
routeThumbnail( $( this ).data( 'thumb' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-03 14:50:09 +00:00
|
|
|
* @param {JQuery.Element} thumbnail
|
2018-03-05 20:42:00 +00:00
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function routeThumbnail( thumbnail ) {
|
|
|
|
router.navigate( '#/media/' + encodeURIComponent( thumbnail.getFileName() ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add routes to images and handle clicks
|
|
|
|
* @method
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initMediaViewer() {
|
|
|
|
thumbs.forEach( function ( thumb ) {
|
|
|
|
thumb.$el.off().data( 'thumb', thumb ).on( 'click', onClickImage );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 17:59:56 +00:00
|
|
|
* Hijack the Special:Languages link and replace it with a trigger to a languageOverlay
|
2017-07-12 15:12:40 +00:00
|
|
|
* that displays the same data
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initButton() {
|
|
|
|
// This catches language selectors in page actions and in secondary actions (e.g. Main Page)
|
2019-01-09 13:57:26 +00:00
|
|
|
// eslint-disable-next-line jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
var $primaryBtn = $( '.language-selector' );
|
|
|
|
|
|
|
|
if ( $primaryBtn.length ) {
|
|
|
|
// We only bind the click event to the first language switcher in page
|
|
|
|
$primaryBtn.on( 'click', function ( ev ) {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
if ( $primaryBtn.attr( 'href' ) || $primaryBtn.find( 'a' ).length ) {
|
|
|
|
router.navigate( '/languages' );
|
|
|
|
} else {
|
|
|
|
toast.show( mw.msg( 'mobile-frontend-languages-not-available' ) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 10:47:05 +00:00
|
|
|
/**
|
|
|
|
* Make an instance of an ImageOverlay. This function assumes that the module
|
|
|
|
* providing the ImageOverlay has been asynchronously loaded.
|
|
|
|
* @method
|
|
|
|
* @ignore
|
|
|
|
* @param {string} title Url of image
|
|
|
|
* @return {ImageOverlay}
|
|
|
|
*/
|
|
|
|
function makeImageOverlay( title ) {
|
|
|
|
var ImageOverlay = M.require( 'mobile.mediaViewer/ImageOverlay' ),
|
|
|
|
imageOverlay = new ImageOverlay( {
|
|
|
|
api: api,
|
|
|
|
thumbnails: thumbs,
|
2018-12-04 22:13:38 +00:00
|
|
|
title: decodeURIComponent( title ),
|
|
|
|
eventBus: eventBus
|
2018-07-26 10:47:05 +00:00
|
|
|
} );
|
|
|
|
imageOverlay.on( ImageOverlay.EVENT_EXIT, function () {
|
|
|
|
// Actually dismiss the overlay whenever the cross is closed.
|
|
|
|
window.location.hash = '';
|
|
|
|
// Clear the hash.
|
|
|
|
router.navigate( '' );
|
|
|
|
} );
|
|
|
|
imageOverlay.on( ImageOverlay.EVENT_SLIDE, function ( nextThumbnail ) {
|
|
|
|
routeThumbnail( nextThumbnail );
|
|
|
|
} );
|
|
|
|
return imageOverlay;
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Load image overlay
|
|
|
|
* @method
|
|
|
|
* @ignore
|
|
|
|
* @uses ImageOverlay
|
|
|
|
* @param {string} title Url of image
|
2018-07-26 10:47:05 +00:00
|
|
|
* @return {JQuery.Deferred|ImageOverlay}
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
function loadImageOverlay( title ) {
|
2017-07-19 23:08:24 +00:00
|
|
|
if ( mw.loader.getState( 'mmv.bootstrap' ) === 'ready' ) {
|
|
|
|
// This means MultimediaViewer has been installed and is loaded.
|
|
|
|
// Avoid loading it (T169622)
|
|
|
|
return $.Deferred().reject();
|
2018-08-31 22:48:34 +00:00
|
|
|
}
|
|
|
|
if ( mw.loader.getState( 'mobile.mediaViewer' ) === 'ready' ) {
|
2018-07-26 10:47:05 +00:00
|
|
|
// If module already loaded, do this synchronously to avoid the event loop causing
|
|
|
|
// a visible flash (see T197110)
|
|
|
|
return makeImageOverlay( title );
|
2017-07-19 23:08:24 +00:00
|
|
|
}
|
2018-08-31 22:48:34 +00:00
|
|
|
return loader.loadModule( 'mobile.mediaViewer' ).then( function () {
|
|
|
|
return makeImageOverlay( title );
|
|
|
|
} );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Routes
|
|
|
|
overlayManager.add( /^\/media\/(.+)$/, loadImageOverlay );
|
|
|
|
overlayManager.add( /^\/languages$/, function () {
|
2019-02-14 16:39:37 +00:00
|
|
|
return mobile.languageOverlay( new PageGateway( api ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
$( function () {
|
|
|
|
initButton();
|
|
|
|
initMediaViewer();
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialisation function for last modified module.
|
|
|
|
*
|
|
|
|
* Enhances an element representing a time
|
|
|
|
* to show a human friendly date in seconds, minutes, hours, days
|
|
|
|
* months or years
|
|
|
|
* @ignore
|
|
|
|
* @param {JQuery.Object} [$lastModifiedLink]
|
|
|
|
*/
|
|
|
|
function initHistoryLink( $lastModifiedLink ) {
|
|
|
|
var delta, historyUrl, msg, $bar,
|
|
|
|
ts, username, gender;
|
|
|
|
|
|
|
|
historyUrl = $lastModifiedLink.attr( 'href' );
|
|
|
|
ts = $lastModifiedLink.data( 'timestamp' );
|
|
|
|
username = $lastModifiedLink.data( 'user-name' ) || false;
|
|
|
|
gender = $lastModifiedLink.data( 'user-gender' );
|
|
|
|
|
|
|
|
if ( ts ) {
|
|
|
|
delta = time.getTimeAgoDelta( parseInt( ts, 10 ) );
|
|
|
|
if ( time.isRecent( delta ) ) {
|
|
|
|
$bar = $lastModifiedLink.closest( '.last-modified-bar' );
|
|
|
|
$bar.addClass( 'active' );
|
|
|
|
// in beta update icons to be inverted
|
|
|
|
$bar.find( '.mw-ui-icon' ).each( function () {
|
|
|
|
$( this ).attr( 'class', $( this ).attr( 'class' ).replace( '-gray', '-invert' ) );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
msg = time.getLastModifiedMessage( ts, username, gender, historyUrl );
|
|
|
|
$lastModifiedLink.replaceWith( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialisation function for last modified times
|
|
|
|
*
|
|
|
|
* Enhances .modified-enhancement element
|
|
|
|
* to show a human friendly date in seconds, minutes, hours, days
|
|
|
|
* months or years
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initModifiedInfo() {
|
2019-01-09 13:57:26 +00:00
|
|
|
// eslint-disable-next-line jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
$( '.modified-enhancement' ).each( function () {
|
|
|
|
initHistoryLink( $( this ) );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialisation function for user creation module.
|
|
|
|
*
|
|
|
|
* Enhances an element representing a time
|
|
|
|
+ to show a human friendly date in seconds, minutes, hours, days
|
|
|
|
* months or years
|
|
|
|
* @ignore
|
|
|
|
* @param {JQuery.Object} [$tagline]
|
|
|
|
*/
|
|
|
|
function initRegistrationDate( $tagline ) {
|
|
|
|
var msg, ts;
|
|
|
|
|
|
|
|
ts = $tagline.data( 'userpage-registration-date' );
|
|
|
|
|
|
|
|
if ( ts ) {
|
|
|
|
msg = time.getRegistrationMessage( ts, $tagline.data( 'userpage-gender' ) );
|
|
|
|
$tagline.text( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialisation function for registration date on user page
|
|
|
|
*
|
|
|
|
* Enhances .tagline-userpage element
|
|
|
|
* to show human friendly date in seconds, minutes, hours, days
|
|
|
|
* months or years
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initRegistrationInfo() {
|
2019-01-09 13:57:26 +00:00
|
|
|
// eslint-disable-next-line jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
$( '#tagline-userpage' ).each( function () {
|
|
|
|
initRegistrationDate( $( this ) );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2018-01-12 17:45:39 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function appendDownloadButton() {
|
2018-11-08 00:06:54 +00:00
|
|
|
var $downloadAction = downloadPageAction( skin,
|
|
|
|
config.get( 'wgMinervaDownloadNamespaces', [] ), window );
|
2017-10-18 21:03:51 +00:00
|
|
|
|
2018-11-08 00:06:54 +00:00
|
|
|
if ( $downloadAction ) {
|
2017-10-18 21:03:51 +00:00
|
|
|
// Because the page actions are floated to the right, their order in the
|
|
|
|
// DOM is reversed in the display. The watchstar is last in the DOM and
|
|
|
|
// left-most in the display. Since we want the download button to be to
|
|
|
|
// the left of the watchstar, we put it after it in the DOM.
|
2018-11-08 00:06:54 +00:00
|
|
|
$downloadAction.insertAfter( '#ca-watch' );
|
2018-01-09 15:40:36 +00:00
|
|
|
track( 'minerva.downloadAsPDF', {
|
|
|
|
action: 'buttonVisible'
|
|
|
|
} );
|
2017-10-18 21:03:51 +00:00
|
|
|
}
|
2018-01-12 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 22:52:35 +00:00
|
|
|
/**
|
|
|
|
* Initialize red links call-to-action
|
|
|
|
*
|
|
|
|
* Upon clicking a red link, show an interstitial CTA explaining that the page doesn't exist
|
|
|
|
* with a button to create it, rather than directly navigate to the edit form.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initRedlinksCta() {
|
|
|
|
page.getRedLinks().on( 'click', function ( ev ) {
|
|
|
|
var drawerOptions = {
|
|
|
|
progressiveButton: new Button( {
|
|
|
|
progressive: true,
|
|
|
|
label: mw.msg( 'mobile-frontend-editor-redlink-create' ),
|
|
|
|
href: $( this ).attr( 'href' )
|
|
|
|
} ).options,
|
|
|
|
closeAnchor: new Anchor( {
|
|
|
|
progressive: true,
|
|
|
|
label: mw.msg( 'mobile-frontend-editor-redlink-leave' ),
|
|
|
|
additionalClassNames: 'hide'
|
|
|
|
} ).options,
|
2019-02-05 20:54:10 +00:00
|
|
|
events: {
|
2018-12-20 19:31:58 +00:00
|
|
|
'click .hide': 'hide' // Call CtaDrawer.hide() on closeAnchor click.
|
2019-02-05 20:54:10 +00:00
|
|
|
},
|
2018-09-20 22:52:35 +00:00
|
|
|
content: mw.msg( 'mobile-frontend-editor-redlink-explain' ),
|
|
|
|
actionAnchor: false
|
|
|
|
},
|
|
|
|
drawer = new CtaDrawer( drawerOptions );
|
|
|
|
|
|
|
|
// use preventDefault() and not return false to close other open
|
|
|
|
// drawers or anything else.
|
|
|
|
ev.preventDefault();
|
|
|
|
drawer.show();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:32:49 +00:00
|
|
|
/**
|
|
|
|
* 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 initEditLink() {
|
|
|
|
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( {
|
|
|
|
name: 'edit',
|
|
|
|
glyphPrefix: 'minerva'
|
|
|
|
} ),
|
|
|
|
enabledEditIcon = new Icon( {
|
|
|
|
name: 'edit-enabled',
|
|
|
|
glyphPrefix: 'minerva'
|
|
|
|
} ),
|
|
|
|
enabledClass = enabledEditIcon.getGlyphClassName(),
|
2018-11-08 21:38:18 +00:00
|
|
|
disabledClass = disabledEditIcon.getGlyphClassName();
|
2018-09-21 00:32:49 +00:00
|
|
|
|
2018-11-08 21:38:18 +00:00
|
|
|
if ( mw.config.get( 'wgMinervaReadOnly' ) ) {
|
2019-01-09 13:57:26 +00:00
|
|
|
// eslint-disable-next-line jquery/no-global-selector
|
2018-11-08 21:38:18 +00:00
|
|
|
$( '#ca-edit' )
|
|
|
|
.removeClass( enabledClass )
|
|
|
|
.addClass( disabledClass );
|
|
|
|
}
|
2018-09-21 00:32:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 17:45:39 +00:00
|
|
|
$( function () {
|
|
|
|
// Update anything else that needs enhancing (e.g. watchlist)
|
|
|
|
initModifiedInfo();
|
|
|
|
initRegistrationInfo();
|
2019-01-09 13:57:26 +00:00
|
|
|
// eslint-disable-next-line jquery/no-global-selector
|
2018-01-12 17:45:39 +00:00
|
|
|
initHistoryLink( $( '.last-modifier-tagline a' ) );
|
|
|
|
appendDownloadButton();
|
2018-09-20 22:52:35 +00:00
|
|
|
initRedlinksCta();
|
2018-09-21 00:32:49 +00:00
|
|
|
initEditLink();
|
2018-07-30 14:45:44 +00:00
|
|
|
// Setup the issues banner on the page
|
|
|
|
// Pages which dont exist (id 0) cannot have issues
|
|
|
|
if ( !page.isMissing ) {
|
2018-08-01 03:30:02 +00:00
|
|
|
issues.init( overlayManager, page );
|
2018-07-30 14:45:44 +00:00
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
} );
|
2017-09-07 16:55:28 +00:00
|
|
|
|
|
|
|
M.define( 'skins.minerva.scripts/overlayManager', overlayManager );
|
2018-11-16 15:16:25 +00:00
|
|
|
}( mw.mobileFrontend, mw.track, mw.config ) );
|