MinervaNeue/resources/skins.minerva.scripts/page-issues/page/pageIssueFormatter.js
jdlrobson 72df451bd3 Embrace packageFiles
Help with readability by using module.exports and require rather than the MobileFrontend
provided mw.mobileFrontend module manager (and avoid adopting webpack at this time)

Replace usages of mw.mobileFrontend.require with local require and module.exports
(compatible with RL or Node implementation)

Changes:
* Notifications modules are merged into skins.minerva.scripts and initialised
via a client side check.
* new file overlayManager for exporting an overlayManager singleton
rather than being hidden inside resources/skins.minerva.scripts/init.js
* All M.define/M.requires swapped out for require where possible
The `define` method is now forbidden in the repo.

Bug: T212944
Change-Id: I44790dd3fc6fe42bb502d79c39c4081c223bf2b1
2019-07-16 18:04:10 +00:00

52 lines
1.7 KiB
JavaScript

( function () {
var
newPageIssueLink = require( './PageIssueLink.js' ),
newPageIssueLearnMoreLink = require( './PageIssueLearnMoreLink.js' );
/**
* Modifies the `issue` DOM to create a banner designed for single / multiple issue templates,
* and handles event-binding for that issues overlay.
*
* @param {IssueSummary} issue
* @param {string} msg
* @param {string} overlayUrl
* @param {Object} overlayManager
* @param {boolean} [multiple]
*/
function insertPageIssueBanner( issue, msg, overlayUrl, overlayManager, multiple ) {
var $learnMoreEl = newPageIssueLearnMoreLink( msg ),
$issueContainer = multiple ?
issue.$el.parents( '.mbox-text-span, .mbox-text-div' ) :
issue.$el.find( '.mbox-text' ),
$clickContainer = multiple ? issue.$el.parents( '.mbox-text' ) : issue.$el;
$issueContainer.prepend( issue.iconString );
$issueContainer.prepend( $learnMoreEl );
$clickContainer.on( 'click', function () {
overlayManager.router.navigate( overlayUrl );
return false;
} );
}
/**
* Modifies the page DOM to insert a page-issue notice below the title of the page,
* containing a link with a message like "this page has issues".
* Used on talk & category namespaces, or when page-issue banners have been disabled.s
*
* @param {string} labelText
* @param {string} section
*/
function insertPageIssueNotice( labelText, section ) {
var $link = newPageIssueLink( labelText );
$link.attr( 'href', '#/issues/' + section );
// eslint-disable-next-line no-jquery/no-global-selector
$link.insertAfter( $( 'h1#section_0' ) );
}
module.exports = {
insertPageIssueBanner: insertPageIssueBanner,
insertPageIssueNotice: insertPageIssueNotice
};
}() );