Jump to content

User:Jcgoble3/SectionInput.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jcgoble3 (talk | contribs) at 08:23, 5 January 2016 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Copied from [[User:Svick/SectionInput.js]]
// In the process of updating to jQuery and modifying to work with wikEd

// This script creates new text box for the name of the edited section.
// This way, the browser's autocomplete for edit summary doesn't contain section name and becomes much more useful.
// Tested in Firefox.
$(function() {
	if (mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit') {
		var summary = $('#wpSummary');
		var sectionid = $('#editform input[name="wpSection"]');
		if (sectionid && sectionid.value == 'new') {
			return;
		}
		summary.css('width', '74%');
		var section = $('<input>');
		section.attr('id', 'section');
		section.attr('name', 'section');
		section.css('width', '23.7%');
		section.css('margin-right', '1%');
		section.attr('tabIndex', '1');
		summary.before($('<br />'));
		summary.before(section);
		var re = RegExp('/\\*\\s*(.*?)\\s*\\*/\\s*');
		var result = re.exec(summary.val());
		if (result) {
			section.val(result[1]);
		}
		summary.val(summary.val().replace(re, ''));
		summary.submit(function() {
			if (section.val())
				summary.val('/* ' + section.val() + ' */ ' + summary.val());
		});
	}
});