User:Jcgoble3/SectionInput.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Jcgoble3/SectionInput. |
// 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());
}
});
}
});