From 735410f17b6bf8445c6f7d1978adeeadd8a4ded4 Mon Sep 17 00:00:00 2001 From: Tim Bannister Date: Tue, 29 Sep 2020 18:27:45 +0100 Subject: [PATCH] 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/ --- layouts/case-studies/single-baseof.html | 2 -- layouts/partials/footer-scripts.html | 35 -------------------- layouts/partials/head.html | 1 - layouts/partials/hooks/body-end.html | 44 +++++++++++++++++++++++++ static/js/script.js | 34 ------------------- 5 files changed, 44 insertions(+), 72 deletions(-) delete mode 100644 layouts/partials/footer-scripts.html create mode 100644 layouts/partials/hooks/body-end.html diff --git a/layouts/case-studies/single-baseof.html b/layouts/case-studies/single-baseof.html index 23b0894543..35d172626c 100644 --- a/layouts/case-studies/single-baseof.html +++ b/layouts/case-studies/single-baseof.html @@ -8,8 +8,6 @@ {{ partial "deprecation-warning.html" . }} {{ block "main" . }}{{ end }} {{ partialCached "footer.html" . }} - - {{ partialCached "scripts.html" . }} diff --git a/layouts/partials/footer-scripts.html b/layouts/partials/footer-scripts.html deleted file mode 100644 index 5a9f825169..0000000000 --- a/layouts/partials/footer-scripts.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 0383341d36..0fc1445b65 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -85,7 +85,6 @@ {{ end }} - {{ if .HasShortcode "mermaid" }} diff --git a/layouts/partials/hooks/body-end.html b/layouts/partials/hooks/body-end.html new file mode 100644 index 0000000000..36e65f7791 --- /dev/null +++ b/layouts/partials/hooks/body-end.html @@ -0,0 +1,44 @@ +{{ with .Site.Params.algolia_docsearch }} + +{{ end }} +{{/* copy-and-paste helper for codenew shortcode */}} +{{- if .HasShortcode "codenew" -}} + + +{{- end -}} diff --git a/static/js/script.js b/static/js/script.js index f1d33c2caf..929881fb34 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -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);