Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
$(function() {
'use strict';
var $textarea = $('textarea.oo-ui-inputWidget-input, #wpSummary');
if (!$textarea.length || document.getElementById('stdSummaries')) return;
var presets = (window.dev && window.dev.editSummaries) || {},
select = presets.select || 'Template:Stdsummaries';
$textarea.attr('tabindex', '3'); //set tabindex for summaries text area
$('#wpMinoredit').attr('tabindex', '4'); //set tabindex for minor edit checkbox
$('#wpSave').attr('tabindex', '5'); //set tabindex for publish button
var $summary = $('#wpSummaryEnhanced');
if (!$summary.length) $summary = $textarea;
if ('css' in presets) {
mw.util.addCSS(presets.css);
} else {
}
var $combo = $('<select id="stdSummaries" tabindex="2"></select>')
.insertAfter($textarea)
.change(function() {
//var val = $summary.val();
//$summary.val(val + (val.length ? '; ' : '') + $(this).val());
$summary.val($(this).val());
});
function flatten (options, indent) {
var flattened = [];
indent = indent || '';
for (var i = 0; i < options.length; i++) {
if ($.isArray(options[i])) {
flattened = flattened.concat(flatten(options[i], '-- '));
} else {
flattened.push(indent + options[i]);
}
}
return flattened;
}
function render (lines) {
var options = '', selected = ' selected',
ignore = { ':': 1, '*': 1, '<': 1 };
for (var i = 0; i < lines.length; i++, selected = '') {
if (!lines[i].length || ignore[lines[i][0]]) {
continue; // lines beginning with these characters: : * < are ignored
}
if (lines[i].substring(0, 3) === '-- ') {
var contents = mw.html.escape( lines[i].substring(3) );
options += '<option value="' + contents + '"' +
selected + '> ' + contents + '</option>';
} else {
options += '<option value="" disabled' +
selected + '>' + mw.html.escape( lines[i] ) + '</option>';
}
}
$combo.append(options);
}
if (typeof select === 'string') {
$.get(mw.util.getUrl(select, {action: 'raw'}))
.done(function (data) {
render(data.split(/\r\n|\n|\r/));
});
} else if (Array.isArray(select)) {
render(flatten(select));
}
});