2019-04-04 21:20:39 +00:00
|
|
|
( function ( M ) {
|
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,
|
2019-03-04 22:19:33 +00:00
|
|
|
TitleUtil = M.require( 'skins.minerva.scripts/TitleUtil' ),
|
2018-08-16 19:00:38 +00:00
|
|
|
issues = M.require( 'skins.minerva.scripts/pageIssues' ),
|
2019-04-04 21:20:39 +00:00
|
|
|
Toolbar = M.require( 'skins.minerva.scripts/Toolbar' ),
|
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,
|
|
|
|
Button = mobile.Button,
|
|
|
|
Anchor = mobile.Anchor,
|
2018-11-08 15:12:53 +00:00
|
|
|
overlayManager = OverlayManager.getSingleton(),
|
2019-07-11 00:56:04 +00:00
|
|
|
currentPage = mobile.currentPage(),
|
|
|
|
currentPageHTMLParser = mobile.currentPageHTMLParser(),
|
|
|
|
$redLinks = currentPageHTMLParser.getRedLinks(),
|
2018-07-26 10:47:05 +00:00
|
|
|
api = new mw.Api(),
|
2019-03-04 22:19:33 +00:00
|
|
|
eventBus = mobile.eventBusSingleton,
|
|
|
|
namespaceIDs = mw.config.get( 'wgNamespaceIds' );
|
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
|
2019-04-19 17:36:50 +00:00
|
|
|
* @param {JQuery.Object} [$container] Optional container to search within
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2019-04-19 17:36:50 +00:00
|
|
|
function initMediaViewer( $container ) {
|
2019-07-11 00:56:04 +00:00
|
|
|
currentPageHTMLParser.getThumbnails( $container ).forEach( function ( thumb ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
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-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-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
|
|
|
/**
|
2019-03-25 20:08:54 +00:00
|
|
|
* Returns a rejected promise if MultimediaViewer is available. Otherwise
|
|
|
|
* returns the mediaViewerOverlay
|
2018-07-26 10:47:05 +00:00
|
|
|
* @method
|
|
|
|
* @ignore
|
2019-03-25 20:08:54 +00:00
|
|
|
* @param {string} title the title of the image
|
|
|
|
* @return {JQuery.Deferred|Overlay}
|
2018-07-26 10:47:05 +00:00
|
|
|
*/
|
2019-03-25 20:08:54 +00:00
|
|
|
function makeMediaViewerOverlayIfNeeded( 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
|
|
|
}
|
2019-03-25 20:08:54 +00:00
|
|
|
|
|
|
|
return mobile.mediaViewer.overlay( {
|
|
|
|
api: api,
|
2019-07-11 00:56:04 +00:00
|
|
|
thumbnails: currentPageHTMLParser.getThumbnails(),
|
2019-03-25 20:08:54 +00:00
|
|
|
title: decodeURIComponent( title ),
|
|
|
|
eventBus: eventBus
|
2018-08-31 22:48:34 +00:00
|
|
|
} );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Routes
|
2019-03-25 20:08:54 +00:00
|
|
|
overlayManager.add( /^\/media\/(.+)$/, makeMediaViewerOverlayIfNeeded );
|
2017-07-12 15:12:40 +00:00
|
|
|
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();
|
|
|
|
} );
|
|
|
|
|
2019-04-19 17:36:50 +00:00
|
|
|
mw.hook( 'wikipage.content' ).add( initMediaViewer );
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* 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' );
|
2019-03-21 14:50:23 +00:00
|
|
|
$bar.find( '.mw-ui-icon-minerva-clock' ).addClass( 'mw-ui-icon-minerva-clock-invert' );
|
|
|
|
$bar.find( '.mw-ui-icon-mf-arrow-gray' ).addClass( 'mw-ui-icon-mf-arrow-invert' );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
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-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-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-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2017-07-12 15:12:40 +00:00
|
|
|
$( '#tagline-userpage' ).each( function () {
|
|
|
|
initRegistrationDate( $( this ) );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-03-04 22:19:33 +00:00
|
|
|
/**
|
|
|
|
* Tests a URL to determine if it links to a local User namespace page or not.
|
|
|
|
*
|
|
|
|
* Assuming the current page visited is hosted on metawiki, the following examples would return
|
|
|
|
* true:
|
|
|
|
*
|
|
|
|
* https://meta.wikimedia.org/wiki/User:Foo
|
|
|
|
* /wiki/User:Foo
|
|
|
|
* /wiki/User:Nonexistent_user_page
|
|
|
|
*
|
|
|
|
* The following examples return false:
|
|
|
|
*
|
|
|
|
* https://en.wikipedia.org/wiki/User:Foo
|
|
|
|
* /wiki/Foo
|
|
|
|
* /wiki/User_talk:Foo
|
|
|
|
*
|
|
|
|
* @param {string} url
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
function isUserUri( url ) {
|
|
|
|
var
|
|
|
|
title = TitleUtil.newFromUri( url ),
|
|
|
|
namespace = title ? title.getNamespaceId() : undefined;
|
|
|
|
return namespace === namespaceIDs.user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strip the edit action from red links to nonexistent User namespace pages.
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function initUserRedLinks() {
|
2019-06-12 20:29:49 +00:00
|
|
|
$redLinks.filter( function ( _, element ) {
|
2019-03-04 22:19:33 +00:00
|
|
|
// Filter out non-User namespace pages.
|
|
|
|
return isUserUri( element.href );
|
|
|
|
} ).each( function ( _, element ) {
|
|
|
|
var uri = new mw.Uri( element.href );
|
|
|
|
if ( uri.query.action !== 'edit' ) {
|
|
|
|
// Nothing to strip.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strip the action.
|
|
|
|
delete uri.query.action;
|
|
|
|
|
|
|
|
// Update the element with the new link.
|
|
|
|
element.href = uri.toString();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
2019-03-04 22:19:33 +00:00
|
|
|
* Special case T201339: following a red link to a user or user talk page should not prompt for
|
|
|
|
* its creation. The reasoning is that user pages should be created by their owners and it's far
|
|
|
|
* more common that non-owners follow a user's red linked user page to consider their
|
|
|
|
* contributions, account age, or other activity.
|
|
|
|
*
|
|
|
|
* For example, a user adds a section to a Talk page and signs their contribution (which creates
|
|
|
|
* a link to their user page whether exists or not). If the user page does not exist, that link
|
|
|
|
* will be red. In both cases, another user follows this link, not to edit create a page for
|
|
|
|
* that user but to obtain information on them.
|
|
|
|
*
|
2018-09-20 22:52:35 +00:00
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function initRedlinksCta() {
|
2019-06-12 20:29:49 +00:00
|
|
|
$redLinks.filter( function ( _, element ) {
|
2019-03-04 22:19:33 +00:00
|
|
|
// Filter out local User namespace pages.
|
|
|
|
return !isUserUri( element.href );
|
|
|
|
} ).on( 'click', function ( ev ) {
|
2018-09-20 22:52:35 +00:00
|
|
|
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();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-06-14 17:32:17 +00:00
|
|
|
/**
|
|
|
|
* When tabs are present and one is selected, scroll the selected tab into view.
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function initTabsScrollPosition() {
|
2019-06-20 21:20:33 +00:00
|
|
|
var $tabContainer, tabPosition, containerPosition, left, right,
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$selectedTab = $( '.minerva__tab.selected' );
|
|
|
|
if ( $selectedTab.length !== 1 ) {
|
2019-06-14 17:32:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-06-20 21:20:33 +00:00
|
|
|
|
|
|
|
$tabContainer = $selectedTab.closest( '.minerva__tab-container' );
|
|
|
|
tabPosition = $selectedTab.position();
|
|
|
|
containerPosition = $tabContainer.position();
|
|
|
|
// Position of the left edge of $selectedTab relative to the left edge of $tabContainer
|
|
|
|
left = tabPosition.left - containerPosition.left;
|
|
|
|
// Position of the right edge of $selectedTab relative to the left edge of $tabContainer
|
|
|
|
right = left + $selectedTab.outerWidth();
|
|
|
|
|
|
|
|
// If $selectedTab is (partly) scrolled out of view, scroll it into view
|
|
|
|
// This only considers and manipulates the horizontal scroll position within $tabContainer,
|
|
|
|
// not the vertical scroll position of the viewport
|
|
|
|
if ( left < 0 ) {
|
|
|
|
// Left edge of $selectedTab is to the left of the left edge of $tabContainer
|
|
|
|
// Scroll $tabContainer to the left, by subtracting the difference from its scrollLeft
|
|
|
|
// (we're subtracting here by adding a negative number)
|
|
|
|
$tabContainer.scrollLeft( $tabContainer.scrollLeft() + left );
|
|
|
|
} else if ( right > $tabContainer.innerWidth() ) {
|
|
|
|
// Right edge of $selectedTab is to the right of the right edge of $tabContainer
|
|
|
|
// Scroll $tabContainer to the right, by adding the difference to its scrollLeft
|
|
|
|
$tabContainer.scrollLeft(
|
|
|
|
$tabContainer.scrollLeft() + right - $tabContainer.innerWidth()
|
|
|
|
);
|
2019-06-14 17:32:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-12 17:45:39 +00:00
|
|
|
$( function () {
|
2019-04-04 21:20:39 +00:00
|
|
|
var toolbarElement = document.querySelector( Toolbar.selector );
|
2018-01-12 17:45:39 +00:00
|
|
|
// Update anything else that needs enhancing (e.g. watchlist)
|
|
|
|
initModifiedInfo();
|
|
|
|
initRegistrationInfo();
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2018-01-12 17:45:39 +00:00
|
|
|
initHistoryLink( $( '.last-modifier-tagline a' ) );
|
2019-04-04 21:20:39 +00:00
|
|
|
if ( toolbarElement ) {
|
|
|
|
Toolbar.bind( window, toolbarElement, eventBus );
|
|
|
|
Toolbar.render( window, toolbarElement );
|
|
|
|
}
|
2018-09-20 22:52:35 +00:00
|
|
|
initRedlinksCta();
|
2019-03-04 22:19:33 +00:00
|
|
|
initUserRedLinks();
|
2019-06-14 17:32:17 +00:00
|
|
|
initTabsScrollPosition();
|
2018-07-30 14:45:44 +00:00
|
|
|
// Setup the issues banner on the page
|
|
|
|
// Pages which dont exist (id 0) cannot have issues
|
2019-07-11 00:56:04 +00:00
|
|
|
if ( !currentPage.isMissing ) {
|
|
|
|
issues.init( overlayManager, currentPageHTMLParser );
|
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 );
|
2019-04-04 21:20:39 +00:00
|
|
|
}( mw.mobileFrontend ) );
|