MediaWiki:Standard Edit Summaries.js

$(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 = $(' ') .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 += ' ' + contents + ' '; } else { options += '' + mw.html.escape( lines[i] ) + ' '; }       }        $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)); } });