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 %} -