mediawiki-skins-MinervaNeue/resources/skins.minerva.talk/init.js
jdlrobson 2cc9516cde Minerva is its own skin
This is programmatic output from python3 scripts/migrate.py

This will result in a Minerva skin dependent on MobileFrontend.

Post merge we will rename message keys to have minerva- prefix

Bug: T166748
Change-Id: Iff1f7e63e796cc5d4a6d2ab0370e0c33248d2fce
2017-07-12 08:12:40 -07:00

98 lines
2.9 KiB
JavaScript

( function ( M, $ ) {
var loader = M.require( 'mobile.startup/rlModuleLoader' ),
LoadingOverlay = M.require( 'mobile.startup/LoadingOverlay' ),
user = M.require( 'mobile.startup/user' ),
Button = M.require( 'mobile.startup/Button' ),
$talk = $( '.talk' ),
// use the plain return value here - T128273
title = $talk.attr( 'data-title' ),
page = M.getCurrentPage(),
overlayManager = M.require( 'skins.minerva.scripts/overlayManager' ),
skin = M.require( 'skins.minerva.scripts/skin' ),
pageTitle, talkTitle;
// if there's no title for any reason, don't do anything
if ( !title ) {
return;
}
// T127190
title = decodeURIComponent( title );
// sanity check: the talk namespace needs to have the next higher integer
// of the page namespace (the api should add topics only to the talk page of the current
// page)
// (https://www.mediawiki.org/wiki/Manual:Using_custom_namespaces#Creating_a_custom_namespace)
// The method to get associated namespaces will change later (maybe), see T487
pageTitle = mw.Title.newFromText( mw.config.get( 'wgPageName' ) );
talkTitle = mw.Title.newFromText( title );
if (
!pageTitle ||
!talkTitle ||
( pageTitle.getMainText() !== talkTitle.getMainText() ) ||
( pageTitle.getNamespaceId() + 1 !== talkTitle.getNamespaceId() )
) {
return;
}
overlayManager.add( /^\/talk\/?(.*)$/, function ( id ) {
var result = $.Deferred(),
talkOptions = {
api: new mw.Api(),
title: title,
licenseMsg: skin.getLicenseMsg()
};
loader.loadModule( 'mobile.talk.overlays' ).done( function () {
var Overlay;
if ( id === 'new' ) {
Overlay = M.require( 'mobile.talk.overlays/TalkSectionAddOverlay' );
} else if ( id ) {
talkOptions.id = id;
Overlay = M.require( 'mobile.talk.overlays/TalkSectionOverlay' );
} else {
Overlay = M.require( 'mobile.talk.overlays/TalkOverlay' );
}
result.resolve( new Overlay( talkOptions ) );
} );
return result;
} );
/**
* Create route '#/talk'
* @ignore
*/
function init() {
$talk.on( 'click', function () {
window.location.hash = '#/talk';
return false;
} );
}
init();
// add an "add discussion" button to talk pages (only for logged in users)
if (
!user.isAnon() &&
( page.inNamespace( 'talk' ) || page.inNamespace( 'user_talk' ) )
) {
new Button( {
label: mw.msg( 'minerva-talk-add-topic' ),
href: '#/talk/new',
progressive: true
} ).prependTo( '#content #bodyContent' );
// reload the page after the new discussion was added
M.on( 'talk-added-wo-overlay', function () {
var loadingOverlay = new LoadingOverlay();
window.location.hash = '';
// setTimeout to make sure, that loadingOverlay's overlayenabled class on html doesnt get removed by
// OverlayManager (who closes TalkSectionAddOverlay
window.setTimeout( function () {
loadingOverlay.show();
window.location.reload();
}, 10 );
} );
}
}( mw.mobileFrontend, jQuery ) );