User:ErrantX/defaultsummaries.js

This is an old revision of this page, as edited by Rd232 (talk | contribs) at 00:41, 25 May 2011 (+). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// The original value of the edit summary field is stored here
var editsummOriginalSummary = new String();

// A global ref to the dropdown with canned edit summaries
var editsummDropdown = null;

function editsummInitialize()
{
    // Save the original value of the edit summary field
    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.onchange = new Function("editsummOnCannedSummarySelected()");

    editsummAddOptionToDropdown(dropdown,"Common edit summaries - click to use");

    editsummAddCatToDropdown(dropdown,"Minor edits");    
    editsummAddOptionToDropdown(dropdown,"Spelling/grammar correction");
    editsummAddOptionToDropdown(dropdown,"Fixing style/layout errors");
    editsummAddOptionToDropdown(dropdown,"[[Help:Reverting|Reverting]] [[Wikipedia:Vandalism|Vandalism]] or test edit");
    editsummAddOptionToDropdown(dropdown,"[[Help:Reverting|Reverting]] unexplained content removal");

    editsummAddCatToDropdown(dropdown,"Non-minor edits");    
    editsummAddOptionToDropdown(dropdown,"Expanding article");
    editsummAddOptionToDropdown(dropdown,"Adding/improving reference(s)");
    editsummAddOptionToDropdown(dropdown,"Adding/removing category/ies");
    editsummAddOptionToDropdown(dropdown,"Adding/removing external link(s)");
    editsummAddOptionToDropdown(dropdown,"Removing unsourced content");
    editsummAddOptionToDropdown(dropdown,"Clean up");
    
    editsummAddCatToDropdown(dropdown,"Talk Pages");
    editsummAddOptionToDropdown(dropdown,"Reply - r");
    editsummAddOptionToDropdown(dropdown,"Comment - c");

    var theParent = insertBeforeThis.parentNode;
    theParent.insertBefore(dropdown,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;
}

addOnloadHook(function (){
  editsummInitialize ();
  
});