From 69d23fded40c80b8f537414826a1e052b7838883 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sat, 28 Jan 2023 23:56:52 -0600 Subject: [PATCH] Add copy clipboard to base --- resources/common.js | 27 +++++++++++++++++++++++++++ templates/base.html | 1 + templates/common-content.html | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/resources/common.js b/resources/common.js index 18c71cf..68c6087 100644 --- a/resources/common.js +++ b/resources/common.js @@ -359,6 +359,33 @@ function onWindowReady() { $('#form-lang').submit(); }) $('#logout').on('click', () => $('#logout-form').submit()); + + var copyButton; + $('pre code').each(function () { + console.log($(this)); + $(this).parent().before($('
', {'class': 'copy-clipboard'}) + .append(copyButton = $('', { + 'class': 'btn-clipboard', + 'data-clipboard-text': $(this).text(), + 'title': 'Click to copy' + }).text('Copy'))); + + $(copyButton.get(0)).mouseleave(function () { + $(this).attr('class', 'btn-clipboard'); + $(this).removeAttr('aria-label'); + }); + + var curClipboard = new Clipboard(copyButton.get(0)); + + curClipboard.on('success', function (e) { + e.clearSelection(); + showTooltip(e.trigger, 'Copied!'); + }); + + curClipboard.on('error', function (e) { + showTooltip(e.trigger, fallbackMessage(e.action)); + }); + }); } $(function() { diff --git a/templates/base.html b/templates/base.html index f3e23bc..e095b48 100644 --- a/templates/base.html +++ b/templates/base.html @@ -89,6 +89,7 @@ + {% include "extra_js.html" %} diff --git a/templates/common-content.html b/templates/common-content.html index ff57965..0ffb0ae 100644 --- a/templates/common-content.html +++ b/templates/common-content.html @@ -6,7 +6,6 @@ {% block js_media %} {% compress js %} -