PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.3
6.3 6.2.3 6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 All 157 releases
mainwp / assets / js / mainwp-code-copy.js

mainwp-code-copy.js in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.3, at assets/js/mainwp-code-copy.js

42 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Copy buttons for AI feature code samples.
3 *
4 * @package MainWP\Dashboard
5 */
6
7 jQuery(function ($) {
8 const buttons = $('.mainwp-code-copy-button');
9
10 if (!buttons.length || typeof ClipboardJS === 'undefined') {
11 return;
12 }
13
14 buttons.each(function () {
15 const button = $(this);
16 const originalHtml = button.html();
17 const originalAriaLabel = button.attr('aria-label');
18 let resetTimer;
19
20 const showStatus = (icon, label) => {
21 globalThis.clearTimeout(resetTimer);
22 button.empty().append($('<i>').addClass(icon), document.createTextNode(label));
23 button.attr('aria-label', label);
24 resetTimer = globalThis.setTimeout(() => {
25 button.html(originalHtml);
26 button.attr('aria-label', originalAriaLabel);
27 }, 2000);
28 };
29
30 const clipboard = new ClipboardJS(this);
31
32 clipboard.on('success', (event) => {
33 event.clearSelection();
34 showStatus('check icon', button.data('copy-success'));
35 });
36
37 clipboard.on('error', () => {
38 showStatus('exclamation triangle icon', button.data('copy-error'));
39 });
40 });
41 });
42