Jump to content

User:Jcgoble3/SectionInput.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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]]
// Updated to jQuery and modified to play nice with wikEd, and still work without it

// 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.length && sectionid.val() === 'new') {
			return;
		}
		summary.css('width', '74%');
		summary.css('display', 'inline');
		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');
		// fix to work in wikEd
		var wikEdSummary = $('.wikEdSummaryComboInput');
		var anchor = wikEdSummary.length ? wikEdSummary : summary;
		anchor.before($('<br />'));
		anchor.before(section);
		var re = /\/\*\s*(.*?)\s*\*\/\s*/;
		var match = re.exec(summary.val());
		if (match) {
			section.val(match[1]);
		}
		summary.val(summary.val().replace(re, ''));
		$('#editform').submit(function() {
			if (section.val()) {
				summary.val('/* ' + section.val() + ' */ ' + summary.val());
			}
		});
	}
});