From 71051be16290619340e1ed528cacb3be9a8f0c2c Mon Sep 17 00:00:00 2001 From: Kei Date: Thu, 29 Feb 2024 12:31:01 +0700 Subject: [PATCH] fix clipboard (#938) --- resources/js/frontend.js | 25 +++++++++++++++++++----- resources/views/frontend/short.blade.php | 4 ++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/resources/js/frontend.js b/resources/js/frontend.js index e18d23e51..73678d1c2 100644 --- a/resources/js/frontend.js +++ b/resources/js/frontend.js @@ -6,10 +6,25 @@ import './bootstrap'; * * https://github.com/zenorocha/clipboard.js */ -var ClipboardJS = require('clipboard'); +const clipboardJs = require('clipboard'); -new ClipboardJS('.btn-clipboard').on('success', function() { - $('.btn-clipboard') - .attr('data-original-title','Copied!').tooltip("_fixTitle").tooltip("show") - .attr("title", "Copy to clipboard").tooltip("_fixTitle"); +const target = document.getElementById('clipboard_shortlink'); +const clipboard = new clipboardJs(target); + +// Success action handler +clipboard.on('success', function (e) { + const currentLabel = target.innerHTML; + + // Exit label update when already in progress + if (target.innerHTML === 'Copied!') { + return; + } + + // Update button label + target.innerHTML = 'Copied!'; + + // Revert button label after 3 seconds + setTimeout(function () { + target.innerHTML = currentLabel; + }, 3000) }); diff --git a/resources/views/frontend/short.blade.php b/resources/views/frontend/short.blade.php index 0707a3776..803d8efe4 100644 --- a/resources/views/frontend/short.blade.php +++ b/resources/views/frontend/short.blade.php @@ -32,11 +32,11 @@ @endif
- @auth