CSS and Javascript changes must comply with the wiki design rules.
Note: After saving, 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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Clear the cache in Tools → Preferences
/* 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 = $('<button title="Copy to Clipboard"></button>');
$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 $content = $(this).closest('.copy-wrapper').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'});
}
});
});
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);
}
}