User:ErrantX/defaultsummaries.js: Difference between revisions

Content deleted Content added
f
m Maintenance: Replacing addOnloadHook with native jQuery (mw:ResourceLoader/Migration_guide_(users)#addOnloadHook - phab:T130879)
 
(31 intermediate revisions by 2 users not shown)
Line 1:
// The original value of the edit summary field is stored here
// ============================================================
var editsummOriginalSummary = new String();
// Standard edit summaries
// ============================================================
 
// A global ref to the dropdown with canned edit summaries
function editSummaries() {
var editsummDropdown = null;
var $box = $('#wpSummary');
 
var $label = $box.next();
function editsummInitialize()
alert("here");
{
if (!$label.size()) {
// Save the original value of the edit summary field
return;
editsummOriginalSummary = document.getElementById("wpSummary");
}
if(editsummOriginalSummary == null)
{
return;
}
 
var insertBeforeThis = document.getElementById("wpSummary").nextSibling;
if(insertBeforeThis.className != "editCheckboxes")
{
return;
}
 
editsummOriginalSummary = editsummOriginalSummary.value
// For convenience, add a dropdown box with some canned edit
// summaries to the form.
 
var dropdown = document.createElement("select");
dropdown.style.width = "38%";
dropdown.style.margin = "0px 4px 0px 0px";
dropdown.onchange = new Function("editsummOnCannedSummarySelected()");
 
var minorDropdown = document.createElement("select");
minorDropdown.style.width = "38%";
minorDropdown.onchange = new Function("editsummOnCannedSummarySelected()");
 
editsummAddCatToDropdown(minorDropdown,"Common minor edit summaries - click to use");
editsummAddCatToDropdown(dropdown,"Common edit summaries - click to use");
editsummAddOptionToDropdown(minorDropdown,"Spelling/grammar correction");
$combo = $('<select />').attr('id', 'stdSummaries').change(function() {
editsummAddOptionToDropdown(minorDropdown,"Fixing style/layout errors");
var val = $(this).val();
editsummAddOptionToDropdown(minorDropdown,"[[Help:Reverting|Reverting]] [[Wikipedia:Vandalism|Vandalism]] or test edit");
if (val != '') {
editsummAddOptionToDropdown(minorDropdown,"[[Help:Reverting|Reverting]] unexplained content removal");
$('#wpSummaryEnhanced,#wpSummary').val(val);
editsummAddOptionToDropdown(minorDropdown,"Copyedit (minor)");
}
});
if (mw.config.get('wgNamespaceNumber') == 0)
{
$label.prepend('<br />').prepend($combo).prepend('Summaries: ');
editsummAddOptionToDropdown(dropdown,"Expanding article");
editsummAddOptionToDropdown(dropdown,"Adding/improving reference(s)");
$.ajax({
editsummAddOptionToDropdown(dropdown,"Adding/removing category/ies");
'dataType': 'text',
editsummAddOptionToDropdown(dropdown,"Adding/removing external link(s)");
'data': {
editsummAddOptionToDropdown(dropdown,"Adding/removing wikilink(s)");
'title': 'User:ErrantX/template',
editsummAddOptionToDropdown(dropdown,"Removing unsourced content");
'action': 'raw',
editsummAddOptionToDropdown(dropdown,"Clean up");
'ctype': 'text/plain'
editsummAddOptionToDropdown(dropdown,"Copyedit (major)");
},
} else
'url': wgScript,
{
'success': function(data) {
editsummAddOptionToDropdown(dropdown,"Reply");
var lines = data.split("\n");
editsummAddOptionToDropdown(dropdown,"Comment");
for (var i in lines) {
if ((mw.config.get('wgNamespaceNumber') % 2 != 0) & (mw.config.get('wgNamespaceNumber') != 3))
var val = (lines[i].indexOf('-- ') == 0) ? lines[i].substring(3) : '';
{
var $opt = $('<option />').val(val).text(lines[i]);
editsummAddOptionToDropdown(dropdown,"[[Wikipedia:WikiProject|WikiProject]] tagging");
$combo.append($opt);
editsummAddOptionToDropdown(dropdown,"[[Wikipedia:WikiProject|WikiProject]] assessment");
}
}
});
 
var theParent = insertBeforeThis.parentNode;
theParent.insertBefore(dropdown,insertBeforeThis);
theParent.insertBefore(minorDropdown,insertBeforeThis);
theParent.insertBefore(document.createElement("br"),dropdown);
 
// Store a global ref to it
editsummDropdown = dropdown;
}
 
function editsummAddOptionToDropdown(dropdown,optionText)
{
var option = document.createElement("option");
var optionTextNode = document.createTextNode(optionText);
option.appendChild(optionTextNode);
dropdown.appendChild(option);
}
 
function editsummAddCatToDropdown(dropdown,catText)
{
var option = document.createElement("option");
option.disabled = "disabled"
var optionTextNode = document.createTextNode(catText);
option.appendChild(optionTextNode);
dropdown.appendChild(option);
}
 
// There's a cross-browser issue when accessing the selected text:
// *In Firefox you can use: selectObj.value
// *In IE, you have to use: selectObj.options[selectObj.selectedIndex].text
// *The latter method also works in Firefox
function editsummOnCannedSummarySelected()
{
var idx = editsummDropdown.selectedIndex;
var canned = editsummDropdown.options[idx].text;
 
var newSummary = editsummOriginalSummary;
if (newSummary.length!=0) newSummary += " - ";
newSummary += canned;
document.forms.editform.wpSummary.value = newSummary;
}
 
$(function (){
addOnloadHook(editSummaries);
editsummInitialize ();
});