aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/clipboard.js21
-rw-r--r--layouts/partials/docs/footer.html5
2 files changed, 26 insertions, 0 deletions
diff --git a/assets/clipboard.js b/assets/clipboard.js
new file mode 100644
index 0000000..fdf84cf
--- /dev/null
+++ b/assets/clipboard.js
@@ -0,0 +1,21 @@
+(function () {
+ function select(element) {
+ const selection = window.getSelection();
+
+ const range = document.createRange();
+ range.selectNodeContents(element);
+
+ selection.removeAllRanges();
+ selection.addRange(range);
+ }
+
+ document.querySelectorAll("pre code").forEach(code => {
+ code.addEventListener("click", function (event) {
+ select(code.parentElement);
+
+ if (navigator.clipboard) {
+ navigator.clipboard.writeText(code.parentElement.textContent);
+ }
+ });
+ });
+})();
diff --git a/layouts/partials/docs/footer.html b/layouts/partials/docs/footer.html
index 7f1a08a..6e1a694 100644
--- a/layouts/partials/docs/footer.html
+++ b/layouts/partials/docs/footer.html
@@ -23,3 +23,8 @@
</div>
{{ end }}
</div>
+
+{{ $script := resources.Get "clipboard.js" | resources.Minify }}
+{{ with $script.Content }}
+ <script>{{ . | safeJS }}</script>
+{{ end }}