User:Euphoria/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
OOUI buttons
fix
Line 1: Line 1:
// <nowiki>
//<nowiki>
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'oojs-ui-core', 'oojs-ui-widgets'], function () {
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'oojs-ui'], function () {
const pagePrefix = 'User:Euphoria/Test VfD';
const pagePrefix = 'User:Euphoria/Test VfD';


Line 22: Line 22:


const actions = [
const actions = [
{ name: 'delete', color: '#e74c3c', flag: 'destructive' },
{ name: 'delete', colorClass: 'oo-ui-destructiveElement' },
{ name: 'keep', color: '#27ae60', flag: 'progressive' },
{ name: 'keep', colorClass: 'oo-ui-progressiveElement' },
{ name: 'no consensus', color: '#f1c40f', flag: '' }
{ name: 'no consensus', colorClass: 'oo-ui-warningElement' }
];
];


actions.forEach(function (actionObj) {
actions.forEach(function (actionObj) {
// Create OOUI button
const btn = new OO.ui.ButtonWidget({
const btn = new OO.ui.ButtonWidget({
label: actionObj.name.charAt(0).toUpperCase(),
label: actionObj.name.charAt(0).toUpperCase(),
title: 'Close as ' + actionObj.name,
title: 'Close as ' + actionObj.name,
flags: actionObj.flag ? [actionObj.flag] : [],
classes: ['vfd-btn', actionObj.colorClass],
framed: false
flags: ['small'] // small button size
});
});


// Mouse hover brightness handled automatically by OOUI
btn.on('click', function (e) {
btn.on('click', function (e) {
e.preventDefault();
e.preventDefault();
Line 62: Line 60:
'\n{{subst:vb}}';
'\n{{subst:vb}}';


// Edit discussion page
api.postWithToken('csrf', {
api.postWithToken('csrf', {
action: 'edit',
action: 'edit',
Line 85: Line 82:


if (actionObj.name === 'delete') {
if (actionObj.name === 'delete') {
// Delete target page
api.postWithToken('csrf', {
api.postWithToken('csrf', {
action: 'delete',
action: 'delete',
Line 101: Line 97:


if (talkId !== "-1") {
if (talkId !== "-1") {
// Delete talk page if exists
api.postWithToken('csrf', {
api.postWithToken('csrf', {
action: 'delete',
action: 'delete',
Line 121: Line 116:
);
);
} else {
} else {
// Keep / No consensus: update page and talk page
api.get({
api.get({
action: 'query',
action: 'query',
Line 185: Line 179:
});
});


// Append OOUI button element to container
container.appendChild(btn.$element[0]);
container.appendChild(btn.$element[0]);
});
});
Line 193: Line 186:
});
});
});
});
// </nowiki>
//</nowiki>