Jump to content

User:Gary/default summary.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
	DEFAULT SUMMARY
	Description: Creates a default edit summary, with several specific to certain pages, such as archive and talk pages.
*/

if (typeof(unsafeWindow) != 'undefined')
{
	var console = unsafeWindow.console;
	mw = unsafeWindow.mw;
}

$(defaultEditSummary);
function defaultEditSummary()
{
	if (!$('#wpSummary').length || ($('#wpSummary').attr('value') != '' && $('#wpSummary').attr('value').indexOf('/*') == -1) || !$('#wpTextbox1').length) return false;

	var myValue;
	var defaultValue = 'cleanup';
	
	if ($('#wpTextbox1').attr('value').length == 0) myValue = 'creating';
	else if (mw.config.get('wgCanonicalNamespace') == 'User_talk' && mw.config.get('wgPageName').indexOf('Archive') != -1) myValue = 'archiving';
	// Note: The 'Wikipedia' namespace is called 'Project'.
	else if (mw.config.get('wgCanonicalNamespace') == 'Project' || mw.config.get('wgCanonicalNamespace') == 'Talk' || mw.config.get('wgCanonicalNamespace').indexOf('_talk') != -1) myValue = 'commenting';
	else myValue = defaultValue;

	if ($('#wpSummary').attr('value').indexOf('/*') != -1 && ($('#wpSummary').attr('value').indexOf('*/') + 3) == $('#wpSummary').attr('value').length)
	{
		var addedValue = '';
		if (myValue != defaultValue) addedValue = myValue;
		$('#wpSummary').attr('value', document.getElementById('wpSummary').value + addedValue);
	}
	else if ($('#wpSummary').attr('value').indexOf('/*') == -1) $('#wpSummary').attr('value', myValue);
	
	$('#wpSummary').focus(function()
	{
		var summary = $(this);
		var index = summary.attr('value').indexOf(myValue);
		
		if (index == -1) return false;
		summary[0].selectionStart = index;
		summary[0].selectionEnd = index + myValue.length;
	});
}