Jump to content

User:GhostInTheMachine/SDsummary.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by GhostInTheMachine (talk | contribs) at 17:59, 31 July 2022 (globals...). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
//  list of buttons
window.SDsummaryList = [

"SDSHORT    # Shorten Short description per [[WP:SDSHORT]]",
"SDNONE     # Short description=none per [[WP:SDNONE]]"

];

mw.loader.using(
  [ 'ext.gadget.Shortdesc-helper' ],
  SDsummaryInit,
  function(){
    alert('SDsummary needs the SDhelper gadget');
  }
);

//  add CSS
mw.util.addCSS("button.SDsummaryButton { margin-top: 5px; margin-right: 5px; } ");

//  where to put the buttons
var SDsummaryBox = $('#contentSub');

//  use the list to create buttons
function SDsummaryInit() {
  window.SDsummaryList.forEach(function(s){
    var w = s.split('#');
    var b = $('<button class="SDsummaryButton" data-text="' + w[1].trim() + '">' + w[0].trim() + '</button>');
    SDsummaryBox.append(b);
    b.click(SDsummaryPaste);
  });
}

//  button click code to set the summary
function SDsummaryPaste(){
  $('#sdh-summarybox>input').val($(this).data('text'));
}