MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */ // copy to clipboard $(function { // wait for content load (DOMContentLoaded) $('.copy-clipboard').each(function  { var $this = $(this); var $button = $('&#xf0ea; '); $this.append($button); $button.click(function {    var $content = $this.find('.copy-content');    $content.children.remove;    selectElementText($content[0]);    try {      if (!document.execCommand('copy'))       throw 42;      mw.notify('Successfully copied to Clipboard.');    } catch (err) {      mw.notify('Copy to Clipboard failed. Please do it yourself.', {type:'error'});   }   }); });

$('.copy-wrapper img').click(function (e) {   e.preventDefault;    var text = $(this).closest('.copy-wrapper').find('.copy-content').html;    var copyEl = document.createElement('textarea');    copyEl.value = text;    document.body.appendChild(copyEl);    copyEl.select;    try {      if (!document.execCommand('copy'))       throw 42;      mw.notify('Successfully copied to Clipboard.');    } catch (err) {      mw.notify('Copy to Clipboard failed. Please do it yourself.', {type:'error'});   }    document.body.removeChild(copyEl);   });

});

function selectElementText(element) { var range, selection; if (document.body.createTextRange) { range = document.body.createTextRange; range.moveToElementText(element); range.select; } else if (window.getSelection) { selection = window.getSelection; range = document.createRange; range.selectNodeContents(element); selection.removeAllRanges; selection.addRange(range); } }