User:23W/defaultsummaries.js

/** * Imported as of 10 May 2014 from MediaWiki:Gadget-defaultsummaries.js (in turn imported as of 9 June 2011 from User:ErrantX/defaultsummaries.js) * Edited version from MediaWiki:Gadget-defaultsummaries.js * Implements default edit summary dropdown boxes */ (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 = false; 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); }

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.className = "wpSummarySelect"; // dropdown.onchange = editsummOnCannedSummarySelected; // editsummAddCatToDropdown(dropdown, "Common edit summaries – click to use"); editsummAddOptionToDropdown(dropdown, ""); editsummAddOptionToDropdown(dropdown, "..."); editsummAddOptionToDropdown(dropdown, "Oops"); editsummAddOptionToDropdown(dropdown, ""); editsummAddOptionToDropdown(dropdown, "Copy editing"); editsummAddOptionToDropdown(dropdown, "Correcting info"); editsummAddOptionToDropdown(dropdown, "Correcting param"); editsummAddOptionToDropdown(dropdown, "Expanding"); editsummAddOptionToDropdown(dropdown, "Formatting"); editsummAddOptionToDropdown(dropdown, "Reordering"); editsummAddOptionToDropdown(dropdown, "Rephrasing"); editsummAddOptionToDropdown(dropdown, ""); editsummAddOptionToDropdown(dropdown, "Assessing"); editsummAddOptionToDropdown(dropdown, "Clarifying"); editsummAddOptionToDropdown(dropdown, "Commenting"); editsummAddOptionToDropdown(dropdown, "Replying"); editsummAddOptionToDropdown(dropdown, "See talk page"); editsummAddOptionToDropdown(dropdown, ""); editsummAddOptionToDropdown(dropdown, "Fixing"); editsummAddOptionToDropdown(dropdown, "Removing repetition"); editsummAddOptionToDropdown(dropdown, ""); editsummAddOptionToDropdown(dropdown, "Adding reference"); editsummAddOptionToDropdown(dropdown, ""); editsummAddOptionToDropdown(dropdown, "Adding category"); editsummAddOptionToDropdown(dropdown, "Deleting category"); editsummAddOptionToDropdown(dropdown, "Adding external link"); editsummAddOptionToDropdown(dropdown, "Deleting external link"); editsummAddOptionToDropdown(dropdown, "Adding internal link"); editsummAddOptionToDropdown(dropdown, "Deleting internal link"); editsummAddOptionToDropdown(dropdown, ""); editsummAddOptionToDropdown(dropdown, "Deleting section"); editsummAddOptionToDropdown(dropdown, ""); editsummAddOptionToDropdown(dropdown, "Creating new article"); editsummAddOptionToDropdown(dropdown, "Creating redirect page"); editsummAddOptionToDropdown(dropdown, "Creating stub article"); $insertBeforeThis.before(dropdown); }	mw.hook('ve.saveDialog.stateChanged') .add(function		{			//.ve-init-mw-viewPageTarget-saveDialog-checkboxes			var $insertBeforeThis = ve.init.mw.targets[0].saveDialog.$body.find('.ve-ui-mwSaveDialog-options');			$summaryBox = ve.init.mw.targets[0].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, "");	}); }(jQuery)); // End wrap with anonymous function