Only load copy-and-paste helper on pages that use it

This change helps improve load times for key non-documentation pages
such as https://kubernetes.io/
This commit is contained in:
Tim Bannister
2020-09-29 18:27:45 +01:00
parent e2233f570a
commit 735410f17b
5 changed files with 44 additions and 72 deletions
-34
View File
@@ -9,40 +9,6 @@
var body;
//helper functions
function copyCode(elem){
if (document.getElementById(elem)) {
// create hidden text element, if it doesn't already exist
var targetId = "_hiddenCopyText_";
// must use a temporary form element for the selection and copy
target = document.getElementById(targetId);
if (!target) {
var target = document.createElement("textarea");
target.style.position = "absolute";
target.style.left = "-9999px";
target.style.top = "0";
target.id = targetId;
document.body.appendChild(target);
}
target.value = document.getElementById(elem).innerText;
// select the content
target.select();
// copy the selection
var succeed;
try {
succeed = document.execCommand("copy");
} catch(e) {
swal("Oh, no...","Sorry, your browser doesn't support document.execCommand('copy'), so we can't copy this code to your clipboard.");
succeed = false;
}
if (succeed) swal("Copied to clipboard: ",elem);
return succeed;
} else {
swal("Oops!",elem + " not found when trying to copy code");
return false;
}
}
function booleanAttributeValue(element, attribute, defaultValue){
// returns true if an attribute is present with no value
// e.g. booleanAttributeValue(element, 'data-modal', false);