// list of buttons
SDsummaryList = [
// Button text # WP shortcut # summary text
"SDSHORT # SDSHORT # Shorten short description",
"SDNONE # SDNONE # Set Short description to none",
"Uppercase # SDFORMAT # Uppercase first letter of short description",
"Plaintext # SDFORMAT # Plain text short description",
"SDDATES # SDDATES # Format short description dates",
"SDDUPLICATE # SDDUPLICATE # Simplify short description",
"SDAVOID # SDAVOID # Simplify short description",
"SDNOTDEF # SDNOTDEF # Short description is not a definition"
];
console.log('SDsummary loaded')
mw.loader.using(
,
function() {
if( mw.config.get('wgIsArticle') && mw.config.get('wgNamespaceNumber') === 0 ) {
SDsummaryInit(10);
}
},
function() {
alert('SDsummary needs the SDhelper gadget');
}
);
// add CSS
mw.util.addCSS("button.SDsummaryButton { margin-top: 5px; margin-right: 5px; background-color: gold; ");
// use the list to create buttons
function SDsummaryInit(safety) {
console.log('SDsummary init', safety);
var $sdh = $('#sdh');
if($sdh.length < 1 && safety > 0) { // allow only a limited number of checks
// SDhelper is not set up yet
setTimeout(SDsummaryInit, 100, safety-1);
return;
}
var SDsummaryBox = $('#contentSub'); // where to put the buttons
SDsummaryList.forEach(function(s){
var w = s.split('#');
var b = $('<button class="SDsummaryButton" data-text="' + w.trim() + '" data-wp="' + w.trim() + '">' + w.trim() + '</button>');
SDsummaryBox.append(b);
b.click(SDsummaryPaste);
});
}
// button click code to set and display the summary
function SDsummaryPaste(){
var txt = $(this).data('text');
var wp = $(this).data('wp');
$('#sdh-summarybox>input').val(txt + ' — ]');
$('#sdh-summarybox').removeClass('oo-ui-element-hidden');
if(wp === "SDNONE") {
$('#sdh-descriptionbox>input').val("none").change();
}
}