User:Euphoria/common.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
fix |
fix |
||
| Line 1: | Line 1: | ||
//<nowiki> |
|||
// [[User:Euphoria/common.js]] helper for VfD closures |
|||
mw.loader.using('mediawiki.util', function () { |
mw.loader.using(['mediawiki.util', 'oojs-ui'], function () { |
||
| ⚫ | |||
// Add "Close as delete" |
|||
mw.util.addPortletLink( |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
'Close this VfD as delete' |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
var vfdPrefix = 'User:Euphoria/TestVfD/'; // or 'Wikiquote:Votes_for_deletion/' |
|||
// Add "Close as keep" |
|||
mw.util.addPortletLink( |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
'Close this VfD as keep' |
|||
| ⚫ | |||
e.preventDefault(); |
|||
insertClosure('keep'); |
|||
| ⚫ | |||
| ⚫ | |||
// Add "Close as no consensus" |
|||
mw.util.addPortletLink( |
|||
function addButton(label, id, action) { |
|||
'p-cactions', |
|||
mw.util.addPortletLink('p-cactions', '#', label, id, 'Close this VfD as ' + action) |
|||
| ⚫ | |||
' |
.addEventListener('click', function (e) { |
||
e.preventDefault(); |
|||
openClosurePanel(action); |
|||
}); |
|||
} |
|||
e.preventDefault(); |
|||
insertClosure('no consensus'); |
|||
| ⚫ | |||
| ⚫ | |||
addButton('Close as no consensus', 'ca-close-nc', 'no consensus'); |
|||
| ⚫ | |||
var textbox = document.getElementById('wpTextbox1'); |
|||
if (!textbox) return alert('Edit box not found!'); |
|||
var panelId = 'vfd-closure-panel'; |
|||
$('#' + panelId).remove(); |
|||
var $panel = $('<div>').attr('id', panelId).css({ |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
backgroundColor: '#f9f9f9' |
|||
}); |
}); |
||
$panel.append($('<h4>').text('VfD Closure Preview')); |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
var $commentInput = $('<input>').attr({ |
|||
type: 'text', |
|||
placeholder: 'Optional comment' |
|||
}).css({ width: '100%', margin: '5px 0' }); |
|||
$panel.append($('<label>').text('Comment:')).append('<br>').append($commentInput).append('<br>'); |
|||
return; |
|||
} |
|||
var $preview = $('<div>').css({ |
|||
// Insert templates at top and bottom |
|||
border: '1px solid #aaa', |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
}).text('Preview will appear here'); |
|||
$panel.append($preview); |
|||
var $btnPreview = $('<button>').text('Preview').css({ marginRight: '5px' }); |
|||
// Prefill summary |
|||
var $btnInsert = $('<button>').text('Insert').css({ marginRight: '5px' }); |
|||
var $btnCancel = $('<button>').text('Cancel'); |
|||
$panel.append($btnPreview, $btnInsert, $btnCancel); |
|||
$(textbox).before($panel); |
|||
function generateWikitext() { |
|||
var comment = $commentInput.val(); |
|||
| ⚫ | |||
| ⚫ | |||
return topText + textbox.value + bottomText; |
|||
} |
} |
||
$btnPreview.on('click', function () { |
|||
$preview.text(generateWikitext()); |
|||
| ⚫ | |||
| ⚫ | |||
textbox.value = generateWikitext(); |
|||
var summaryBox = document.getElementById('wpSummary'); |
|||
if (summaryBox) summaryBox.value = 'Closed as ' + action; |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
} |
} |
||
}); |
}); |
||
//</nowiki> |
|||
Revision as of 07:47, 25 September 2025
//<nowiki>
mw.loader.using(['mediawiki.util', 'oojs-ui'], function () {
var vfdPrefix = 'User:Euphoria/TestVfD/'; // or 'Wikiquote:Votes_for_deletion/'
if (!mw.config.get('wgPageName').startsWith(vfdPrefix)) return;
function addButton(label, id, action) {
mw.util.addPortletLink('p-cactions', '#', label, id, 'Close this VfD as ' + action)
.addEventListener('click', function (e) {
e.preventDefault();
openClosurePanel(action);
});
}
addButton('Close as delete', 'ca-close-delete', 'delete');
addButton('Close as keep', 'ca-close-keep', 'keep');
addButton('Close as no consensus', 'ca-close-nc', 'no consensus');
function openClosurePanel(action) {
var textbox = document.getElementById('wpTextbox1');
if (!textbox) return alert('Edit box not found!');
var panelId = 'vfd-closure-panel';
$('#' + panelId).remove();
var $panel = $('<div>').attr('id', panelId).css({
border: '1px solid #ccc',
padding: '10px',
margin: '10px 0',
backgroundColor: '#f9f9f9'
});
$panel.append($('<h4>').text('VfD Closure Preview'));
var $commentInput = $('<input>').attr({
type: 'text',
placeholder: 'Optional comment'
}).css({ width: '100%', margin: '5px 0' });
$panel.append($('<label>').text('Comment:')).append('<br>').append($commentInput).append('<br>');
var $preview = $('<div>').css({
border: '1px solid #aaa',
padding: '5px',
margin: '5px 0',
backgroundColor: '#fff'
}).text('Preview will appear here');
$panel.append($preview);
var $btnPreview = $('<button>').text('Preview').css({ marginRight: '5px' });
var $btnInsert = $('<button>').text('Insert').css({ marginRight: '5px' });
var $btnCancel = $('<button>').text('Cancel');
$panel.append($btnPreview, $btnInsert, $btnCancel);
$(textbox).before($panel);
function generateWikitext() {
var comment = $commentInput.val();
var topText = '{{subst:vt|' + action + '. --~~~~' + (comment ? ' ' + comment : '') + '}}\n\n';
var bottomText = '\n\n{{subst:vb}}';
return topText + textbox.value + bottomText;
}
$btnPreview.on('click', function () {
$preview.text(generateWikitext());
});
$btnInsert.on('click', function () {
textbox.value = generateWikitext();
var summaryBox = document.getElementById('wpSummary');
if (summaryBox) summaryBox.value = 'Closed as ' + action;
$panel.remove();
});
$btnCancel.on('click', function () {
$panel.remove();
});
}
});
//</nowiki>