User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
fix |
Cleanup Tag: Blanked |
||
| (64 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
//<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> |
|||