MediaWiki:Gadget-DefaultSummaries.js

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl+F5 or Ctrl+R (Command+R on a Mac)
  • Google Chrome: press Ctrl+Shift+R (Command+Shift+R on a Mac)
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl+F5
  • Konqueror: click Reload or press F5
  • Opera: clear the cache in Tools → Preferences
(function ($) { // Wrap with anonymous function
    // The original value of the edit summary field is stored here
    var editsummOriginalSummary = "";
 
    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 = true;
        option.selected = true;
        var optionTextNode = document.createTextNode(catText);
        option.appendChild(optionTextNode);
        dropdown.appendChild(option);
    }
 
    function editsummOnCannedSummarySelected() {
        // Save the original value of the edit summary field
        editsummOriginalSummary = document.getElementById("wpSummary");
        if (editsummOriginalSummary) {
            editsummOriginalSummary = editsummOriginalSummary.value;
        } else {
            editsummOriginalSummary = "";
        }
 
        var idx = this.selectedIndex;
        var canned = this.options[idx].text;
 
        var newSummary = editsummOriginalSummary;
 
        // Append old edit summary with space, if exists
        if (newSummary.length !== 0) {
            newSummary += " ";
        }
        newSummary += canned;
        document.getElementById("wpSummary").value = newSummary;
    }
 
    $(function () {
        var insertBeforeThis = document.getElementById("wpSummary");
 
        // Loop through siblings, looking for editCheckboxes class
        while (insertBeforeThis) {
            if (insertBeforeThis.className === "editCheckboxes") {
                break;
            }
 
            insertBeforeThis = insertBeforeThis.nextSibling;
        }
 
        // If we failed to find the editCheckboxes class, or insertBeforeThis is null
        if (!insertBeforeThis || 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 = "0 4px 0 0";
        dropdown.onchange = editsummOnCannedSummarySelected;
 
        var minorDropdown = document.createElement("select");
        minorDropdown.style.width = "38%";
        minorDropdown.onchange = editsummOnCannedSummarySelected;
 
        editsummAddCatToDropdown(minorDropdown, "Common minor edit summaries – click to use");
        editsummAddCatToDropdown(dropdown, "Common edit summaries – click to use");
 
        editsummAddOptionToDropdown(minorDropdown, "Spelling/grammar correction");
        editsummAddOptionToDropdown(minorDropdown, "Fixing style/layout errors");
        editsummAddOptionToDropdown(minorDropdown, "Fixing minor link errors");
 
        if (mw.config.get('wgNamespaceNumber') != 1 && mw.config.get('wgNamespaceNumber') != 3 && mw.config.get('wgNamespaceNumber') != 5 && mw.config.get('wgNamespaceNumber') != 7 && mw.config.get('wgNamespaceNumber') != 9 && mw.config.get('wgNamespaceNumber') != 11 && mw.config.get('wgNamespaceNumber') != 13 && mw.config.get('wgNamespaceNumber') != 15) {
            editsummAddOptionToDropdown(dropdown, "Expanding article");
            editsummAddOptionToDropdown(dropdown, "Adding/improving reference(s)");
            editsummAddOptionToDropdown(dropdown, "Adding/removing category/ies");
            editsummAddOptionToDropdown(dropdown, "Removing unnecessary content");
            editsummAddOptionToDropdown(dropdown, "Clean up");
            editsummAddOptionToDropdown(dropdown, "Created page");
            editsummAddOptionToDropdown(dropdown, "Created category");
            editsummAddOptionToDropdown(dropdown, "Created template");
        } else {
            editsummAddOptionToDropdown(dropdown, "Reply");
            editsummAddOptionToDropdown(dropdown, "Comment");
            editsummAddOptionToDropdown(dropdown, "Suggestion");
        }
 
        var theParent = insertBeforeThis.parentNode;
        theParent.insertBefore(dropdown, insertBeforeThis);
        theParent.insertBefore(minorDropdown, insertBeforeThis);
        theParent.insertBefore(document.createElement("br"), dropdown);
    });
}(jQuery)) // End wrap