User:ErrantX/defaultsummaries.js

This is an old revision of this page, as edited by ErrantX (talk | contribs) at 12:36, 14 May 2011 (add). 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;
    }

    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()");

    editsummAddCatToDropdown(dropdown,"Choose a Default Edit Summary");
    editsummAddCatToDropdown(dropdown,"Article");
    editsummAddOptionToDropdown(dropdown,"expand");
    editsummAddOptionToDropdown(dropdown,"+ref");
    editsummAddOptionToDropdown(dropdown,"add categories");
    editsummAddOptionToDropdown(dropdown,"tag");
    editsummAddOptionToDropdown(dropdown,"wikify");
    editsummAddOptionToDropdown(dropdown,"clean up");
    editsummAddOptionToDropdown(dropdown,"rv");
    ditsummAddCatToDropdown(dropdown,"Vandalism");
    editsummAddOptionToDropdown(dropdown,"rvv");
    editsummAddOptionToDropdown(dropdown,"rv unexplained deletion");
    ditsummAddCatToDropdown(dropdown,"Talk Pages");
    editsummAddOptionToDropdown(dropdown,"r");

    var insertBeforeThis = document.getElementById("wpSummary").nextSibling;
    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 ();
  
});