Content deleted Content added
massive update |
f |
||
Line 1:
// Nominations Viewer
//
// Description: Compact nominations for [[WP:FAC]], [[WP:FAR]], [[WP:FLC]],
// [[WP:FLRC]], [[WP:FPC]], and [[WP:PR]].
// Documentation: [[Wikipedia:Nominations Viewer]]
//
// ===
//
// Begin settings
// ---
//
// Default:
//
// NominationsViewer =
// {
// 'enabledPages': ['Wikipedia:Featured article candidates', ...],
// 'nominationData': ['images', 'age', 'nominators', 'participants', 'votes'],
// }
const NominationsViewer = window.NominationsViewer
? window.NominationsViewer
: {};
if (NominationsViewer.enabledPages === null) {
NominationsViewer.enabledPages = {
// 'User:Gary/Sandbox': 'nominations'
Line 38 ⟶ 37:
}
if (NominationsViewer.nominationData === null) {
NominationsViewer.nominationData = [
'images',
Line 47 ⟶ 46:
];
}
/**
* End settings
*/
class NominationsViewerClass {
/**
* Add empty nomination data holders for a nomination.
*
* @param {string} pageName Name of the nomination page.
* @param {jQuery} $parentNode Parent node containing the entire nomination.
* @param {Array} ids The ID names to create.
* @returns {jQuery} The new node we added.
*/
static addNominationData(pageName, $parentNode, ids) {
Line 71 ⟶ 73:
}
static
const data = { allH3Length: $headings.length };
Line 123 ⟶ 125:
// Age
'NominationsViewerClass.firstRevisionCallback',
`action=query&prop=revisions&rvdir=newer&rvlimit=1&titles=${pageName}`,
Line 129 ⟶ 131:
}
static addNewNomData(pageName, data, id, abbrTitle, isFirstData) {
if (!data) {
return
}
Line 150 ⟶ 146:
$newChild.append($abbr);
}
/**
* Create the data that appears next to the nomination's listing.
*
* @param {string} pageName Page name of the nomination page.
* @returns {jQuery} The new node we added.
*/
static createData(pageName) {
Line 208 ⟶ 206:
/**
* Replace a nomination with a new and improved one.
*
* @param {
* @param {jQuery} options.$h3 The h3 heading of the nomination.
* @param {number} options.index The index of the nomination among the others.
* @returns {undefined}
*/
static createNomination({ $h3, index }) {
Line 217 ⟶ 218:
// Skip it.
if (!$editLink.length) {
return
}
Line 251 ⟶ 252:
// Ask the API to add data to our placeholders
}
Line 318 ⟶ 319:
// Check if enabled on this page
Object.keys(NominationsViewer.enabledPages).forEach((page) => {
if (pageName === page.replace(/\s/g, '_')) {
currentPageIsEnabled = true;
} else if (pageName.
currentPageIsASubpage = true;
}
Line 328 ⟶ 327:
if (
currentPageIsEnabled === null ||
window.mw.config.get('wgAction') !== 'view' ||
window.location.href.indexOf('&oldid=') !== -1 ||
!(currentPageIsASubpage === null)
) {
return false;
Line 341 ⟶ 340:
const $parentNode = $('.mw-content-ltr');
const $h3s = $parentNode.find('h3');
this.
//
$h3s.each((index, element) =>
this.createNomination({
Line 370 ⟶ 369:
}
/
static collapseTable(event) {
event.preventDefault();
Line 433 ⟶ 430:
let action = actionParam;
if (action === null) {
action = 'expand';
}
Line 449 ⟶ 446:
let action = actionParam;
if (action === null) {
action = '';
}
Line 468 ⟶ 465:
if (action === 'collapse') {
return toggleHideNom($node, $nomButton);
}
return toggleShowNom($node, $nomButton);
}
// These have to be separate from the above because they have a lower
// priority.
if ($node.is(':visible')) {
return toggleHideNom($node, $nomButton);
}
return toggleShowNom($node, $nomButton);
}
Line 487 ⟶ 490:
}
/
static allRevisionsCallback(obj) {
const vars = this.formatJSON(obj);
Line 502 ⟶ 503:
vars.revisions.forEach((revision) => {
if (!revision.user) {
return;
Line 525:
if (a[1] < b[1]) {
return 1;
}
return -1;
}
return 0;
});
Line 533 ⟶ 536:
const usersArray2 = usersArray.map((user) => `${user[0]}: ${user[1]}`);
return this.
vars.pageName,
`${moreThan + userCount} ${this.pluralize('participant', userCount)}`,
Line 577 ⟶ 580:
});
this.
vars.pageName,
`${matches.length} ${this.pluralize('image', matches.length)}`,
Line 598 ⟶ 601:
);
// eslint-disable-next-line max-depth
if ($.isEmptyObject(listOfNominators)) {
listOfNominators = this.findNominators(content, /:<small>''.*/);
Line 623 ⟶ 627:
/* eslint-disable indent */
this.
vars.pageName,
allNominators.length > 0
Line 734 ⟶ 738:
const toolTip = supports + opposes;
return this.
}
Line 747 ⟶ 746:
/**
* The callback after getting the first revision of a page.
*
* @param {Object} obj The response object from the Wikipedia API.
* @returns {undefined} Generated nomination data.
*/
static firstRevisionCallback(obj) {
Line 753 ⟶ 754:
if (!vars) {
return
}
Line 814 ⟶ 815:
}
vars.pageName,
timeAgo,
Line 821 ⟶ 822:
);
}
}
// Callback helpers
static capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
Line 908 ⟶ 905:
const pageType = NominationsViewer.enabledPages[pageName];
if (type !== null) {
if (type === pageType) {
return true;
Line 937 ⟶ 934:
}
// Already ran?
if (window.NominationsViewerClass) {
return;
}
window.NominationsViewerClass = NominationsViewerClass;
NominationsViewerClass.init();
});
|