MediaWiki:Gadget-summary.js

/* */ /* Tool to simplify filling in edit summary. * Under the field "Summary" is displayed * a box with ideas to fill in into the summary field. * It is possible to extend this by adding code * to your script (User:Nick/vector.js): * * addSummaryButton("shown text", "filled in text", "text in the bubble after mouse pointing"); */ // buttons array wpSummaryButtons = new Array; // function that will fill in the summary function insertSummary(text) { wpSummary = document.getElementById('wpSummary'); // if text is already present, it will not be added if (wpSummary.value.indexOf(text) != -1) return; // if there are no buttons, do not continue if(wpSummaryButtons.length == 0) return; // if filled in, a semicolon will be added if (wpSummary.value.match(/[^,; \/•]$/)) wpSummary.value += ';'; if (wpSummary.value.match(/[^ ]$/)) wpSummary.value += ' '; // add text wpSummary.value += text; } // function that adds a button function addSummaryButton(name, text, title) { // create button buttonSummary = document.createElement('a'); buttonSummary.appendChild(document.createTextNode(name)); buttonSummary.href = "#"; buttonSummary.title = title; buttonSummary.onclick = function{insertSummary(text); return false;}; // add to button queue wpSummaryButtons[wpSummaryButtons.length] = buttonSummary; } // function adding list of summaries to the page function createSummaryButtons{ // if there is no Summary field, do not continue if(!document.getElementById('wpSummary')) return; var wpSummary = document.getElementById('wpSummary'); if (!wpSummary || (wpSummary.form.wpSection && wpSummary.form.wpSection.value == 'new')) return; // block of buttons wpSummaryBtn = document.createElement('div'); wpSummaryBtn.className = 'mw-editTools'; wpSummaryBtnP = document.createElement('p'); wpSummaryBtn.appendChild(wpSummaryBtnP); // add image wpSummaryBtnImage = new Image; wpSummaryBtnImage.src = 'http://www.wikiskripta.eu/images/thumb/c/c3/Vložit.png/15px-Vložit.png'; wpSummaryBtnImage.name = 'http://www.wikiskripta.eu/index.php/Soubor:Vložit.png'; wpSummaryBtnP.appendChild(wpSummaryBtnImage); // add text wpSummaryLegend = document.createElement('b'); wpSummaryLegend.appendChild(document.createTextNode(" Summary tips: ")); wpSummaryBtnP.appendChild(wpSummaryLegend); // add buttons for(i in wpSummaryButtons) { wpSummaryBtnP.appendChild(wpSummaryButtons[i]); wpSummaryBtnSpace = document.createElement('span'); if(i != (wpSummaryButtons.length - 1)) wpSummaryBtnSpace.appendChild(document.createTextNode(' • ')); wpSummaryBtnP.appendChild(wpSummaryBtnSpace); }  // insert into page wpSummary.parentNode.insertBefore(wpSummaryBtn, wpSummary.nextSibling); } // list of buttons addSummaryButton("editorial process", "editorial process", "Editorial process"); addSummaryButton("sources", "sources checked", "Sources checked in the editorial process"); addSummaryButton("category", "category", "Category"); addSummaryButton("typography", "typo", "Typographical changes"); addSummaryButton("grammar", "grammar", "Gramatical changes"); addSummaryButton("links", "links", "Added links"); addSummaryButton("image", "image", "Added or editted image"); addSummaryButton("license", "license", "License changes"); addSummaryButton("headings", "headings", "Headings"); addSummaryButton("portals", "portals", "Portals"); addSummaryButton("references/citations", "citation", "References or citations"); addSummaryButton("answer", "answer", "Answer in discussion"); addSummaryButton("redirect", "redirect", "Redirect"); // gadget start addOnloadHook(createSummaryButtons); /* */