Difference between revisions of "MediaWiki:Common.js"
Greg.Fuller (talk | contribs) |
Greg.Fuller (talk | contribs) |
||
Line 6: | Line 6: | ||
}) | }) | ||
+ | //https://stackoverflow.com/questions/33855641/copy-output-of-a-javascript-variable-to-the-clipboard | ||
function jfa_copy_to_clipboard (text) { | function jfa_copy_to_clipboard (text) { | ||
var dummy = document.createElement("textarea"); | var dummy = document.createElement("textarea"); | ||
Line 18: | Line 19: | ||
var jfa_short_url = jQuery("span.jfa-page-shorturl a").attr("href"); | var jfa_short_url = jQuery("span.jfa-page-shorturl a").attr("href"); | ||
console.log(jfa_short_url); | console.log(jfa_short_url); | ||
− | + | jQuery(".jfa-share-option-url a").attr("href",jfa_short_url); | |
jQuery(".jfa-share-option-url a").click(function(event) { | jQuery(".jfa-share-option-url a").click(function(event) { | ||
Line 24: | Line 25: | ||
//alert( "Handler for .click() called." ); | //alert( "Handler for .click() called." ); | ||
jfa_copy_to_clipboard(jfa_short_url); | jfa_copy_to_clipboard(jfa_short_url); | ||
+ | alert("The short url for this page has been copied to your clipboard and is ready to paste!"); | ||
}); | }); | ||
}) | }) |
Revision as of 11:25, 9 February 2019
/* Any JavaScript here will be loaded for all users on every page load. */
//Insert 'Justice for Animals .org' in the DOM, for the header jQuery(document).ready(function () {
document.body.insertAdjacentHTML( 'afterbegin', '
');
})
//https://stackoverflow.com/questions/33855641/copy-output-of-a-javascript-variable-to-the-clipboard function jfa_copy_to_clipboard (text) {
var dummy = document.createElement("textarea"); document.body.appendChild(dummy); dummy.value = text; dummy.select(); document.execCommand("copy"); document.body.removeChild(dummy);
}
jQuery(document).ready(function () { var jfa_short_url = jQuery("span.jfa-page-shorturl a").attr("href"); console.log(jfa_short_url); jQuery(".jfa-share-option-url a").attr("href",jfa_short_url);
jQuery(".jfa-share-option-url a").click(function(event) { event.preventDefault(); //alert( "Handler for .click() called." ); jfa_copy_to_clipboard(jfa_short_url); alert("The short url for this page has been copied to your clipboard and is ready to paste!"); });
})