User:Absconditus/defaultsummaries.js

// 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.style.width = "38%"; dropdown.style.margin = "0px 4px 0px 0px"; dropdown.onchange = new Function("editsummOnCannedSummarySelected"); var mDropdown = document.createElement("select"); mDropdown.style.width = "38%"; mDropdown.onchange = new Function("editsummOnCannedSummarySelected"); editsummAddCatToDropdown(mDropdown,"Minor edit summaries"); editsummAddCatToDropdown(dropdown,"Major edit summaries"); eAdd(mDropdown,"Spelling/grammar correction"); eAdd(mDropdown,"Fixing style/layout errors"); eAdd(mDropdown,"Reverting Vandalism or test edit"); eAdd(mDropdown,"Reverting unexplained content removal"); eAdd(mDropdown,"Reverting my own edit(s)"); eAdd(dropdown,"-- test edit."); eAdd(mDropdown,"Copyedit (minor)"); eAdd(mDropdown,"Fix."); if (mw.config.get('wgNamespaceNumber') == 0) {     eAdd(dropdown,"Expanding article."); eAdd(dropdown,"Adding/improving reference(s)."); eAdd(dropdown,"Adding/removing category/ies."); eAdd(dropdown,"Adding/removing external link(s)."); eAdd(dropdown,"Adding/removing wikilink(s)."); eAdd(dropdown,"Removing unsourced content."); eAdd(dropdown,"Clean up."); } else {   eAdd(dropdown,"Reply"); eAdd(dropdown,"Comment"); if ((mw.config.get('wgNamespaceNumber') % 2 != 0) & (mw.config.get('wgNamespaceNumber') != 3)) {    eAdd(dropdown,"WikiProject tagging"); eAdd(dropdown,"WikiProject assessment"); } }   var theParent = insertBeforeThis.parentNode; theParent.insertBefore(dropdown,insertBeforeThis); theParent.insertBefore(mDropdown,insertBeforeThis); theParent.insertBefore(document.createElement("br"),dropdown); // Store a global ref to it   editsummDropdown = dropdown; } function eAdd(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 { editsummInitialize ; });