| 1 |
(function ($) { |
| 2 |
$(document).ready(function () { |
| 3 |
// Copy Quick Embed Shortcode |
| 4 |
$(document).on("click", ".stp_shortcode_copy_btn", function (e) { |
| 5 |
e.preventDefault(); |
| 6 |
const $btn = $(this); |
| 7 |
const text = $btn.data("shortcode") || $btn.data("clipboard-text"); |
| 8 |
const $textSpan = $btn.find(".copy-text"); |
| 9 |
const originalText = $textSpan.length ? $textSpan.text() : ""; |
| 10 |
|
| 11 |
if (!text) return; |
| 12 |
|
| 13 |
const performFeedback = () => { |
| 14 |
$btn.addClass("copied"); |
| 15 |
if ($textSpan.length) { |
| 16 |
$textSpan.text("Copied!"); |
| 17 |
setTimeout(() => { |
| 18 |
$btn.removeClass("copied"); |
| 19 |
$textSpan.text(originalText); |
| 20 |
}, 2000); |
| 21 |
} else { |
| 22 |
// Fallback if no span, maybe a tooltip or just a class |
| 23 |
setTimeout(() => { |
| 24 |
$btn.removeClass("copied"); |
| 25 |
}, 2000); |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
if (navigator.clipboard) { |
| 30 |
navigator.clipboard.writeText(text).then(performFeedback); |
| 31 |
} else { |
| 32 |
const tempInput = document.createElement("input"); |
| 33 |
tempInput.value = text; |
| 34 |
document.body.appendChild(tempInput); |
| 35 |
tempInput.select(); |
| 36 |
document.execCommand("copy"); |
| 37 |
document.body.removeChild(tempInput); |
| 38 |
performFeedback(); |
| 39 |
} |
| 40 |
}); |
| 41 |
}); |
| 42 |
})(jQuery); |