User:Euphoria/common.js: Difference between revisions
From Test Wiki
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> |
|||