MediaWiki:Gadget-defaultsummaries.js
Utseende
OBS: Efter du har publicerat sidan kan du behöva tömma din webbläsares cache för att se ändringarna.
- Firefox / Safari: Håll ned Skift och klicka på Uppdatera sidan eller tryck Ctrl-F5 eller Ctrl-R (⌘-R på Mac)
- Google Chrome: Tryck Ctrl-Skift-R (⌘-Skift-R på Mac)
- Edge Håll ned Ctrl och klicka på Uppdatera eller tryck Ctrl-F5.
- Opera: Tryck Ctrl-F5.
/*
* Implements default edit summary dropdown boxes
* Imported and modified from English Wikipedia: https://en.wikipedia.org/wiki/MediaWiki:Gadget-defaultsummaries.js
*/
(function ($) { // Wrap with anonymous function
var $summaryBox = $('#wpSummary');
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
var editsummOriginalSummary = $summaryBox.val();
var idx = this.selectedIndex;
var canned = this.options[idx].text;
var newSummary = editsummOriginalSummary;
// Append old edit summary with space, if exists,
// and last character != space
if (newSummary.length !== 0 && newSummary.charAt(newSummary.length - 1) !== " ") {
newSummary += " ";
}
newSummary += canned;
$summaryBox.val( newSummary ).trigger( 'change' );
}
function insertSummaryOptions($insertBeforeThis, dropdownWidth) {
// For convenience, add a dropdown box with some canned edit
// summaries to the form.
var dropdown = document.createElement("select");
dropdown.style.width = dropdownWidth;
dropdown.style.margin = "0 4px 0 0";
dropdown.onchange = editsummOnCannedSummarySelected;
editsummAddCatToDropdown(dropdown, "Vanliga redigeringskommentarer");
editsummAddOptionToDropdown(dropdown, "Rättat felstavning");
editsummAddOptionToDropdown(dropdown, "Textputs");
editsummAddOptionToDropdown(dropdown, "Korrigerat disposition");
editsummAddOptionToDropdown(dropdown, "Korrigerat syntax");
editsummAddOptionToDropdown(dropdown, "Lagt till illustration");
editsummAddOptionToDropdown(dropdown, "Lagt till kategori");
editsummAddOptionToDropdown(dropdown, "Lagt till mall");
editsummAddOptionToDropdown(dropdown, "Lagt till/utökat infobox");
editsummAddOptionToDropdown(dropdown, "Lagt till/utökat Referenser/Källor");
editsummAddOptionToDropdown(dropdown, "Lagt till/utökat Vidare läsning");
editsummAddOptionToDropdown(dropdown, "Lagt till/utökat Externa länkar");
editsummAddOptionToDropdown(dropdown, "Lagt till/utökat Bibliografi");
$insertBeforeThis.before(dropdown);
}
mw.hook( 've.saveDialog.stateChanged' ).add(function(){
//.ve-init-mw-viewPageTarget-saveDialog-checkboxes
var target = ve.init.target;
var $insertBeforeThis = target.saveDialog.$body.find('.ve-ui-mwSaveDialog-options');
$summaryBox = target.saveDialog.$body.find('.ve-ui-mwSaveDialog-summary textarea');
if (!$insertBeforeThis.length) {
return;
}
insertSummaryOptions($insertBeforeThis, "98%");
});
$(function() {
var $insertBeforeThis = $('.editCheckboxes');
// If we failed to find the editCheckboxes class
if (!$insertBeforeThis.length) {
return;
}
insertSummaryOptions($insertBeforeThis, "38%");
});
}(jQuery)); // End wrap with anonymous function