Skip to content

Commit c74aa81

Browse files
committed
[WebProfilerBundle] Fix Copy as Curl
1 parent a314b65 commit c74aa81

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
constructor() {
1414
this.#createTabs();
1515
this.#createToggles();
16+
this.#createCopyToClipboard();
1617
this.#convertDateTimesToUserTimezone();
1718
}
1819
@@ -161,18 +162,39 @@
161162
});
162163
});
163164
164-
/* Prevents from disallowing clicks on "copy to clipboard" elements inside toggles */
165-
const copyToClipboardElements = toggle.querySelectorAll('span[data-clipboard-text]');
166-
copyToClipboardElements.forEach((copyToClipboardElement) => {
167-
copyToClipboardElement.addEventListener('click', (e) => {
168-
e.stopPropagation();
169-
});
170-
});
171-
172165
toggle.setAttribute('data-processed', 'true');
173166
});
174167
}
175168
169+
#createCopyToClipboard() {
170+
if (!navigator.clipboard) {
171+
return;
172+
}
173+
174+
const copyToClipboardElements = document.querySelectorAll('[data-clipboard-text]');
175+
176+
copyToClipboardElements.forEach((copyToClipboardElement) => {
177+
copyToClipboardElement.classList.remove('hidden');
178+
179+
copyToClipboardElement.addEventListener('click', (e) => {
180+
/* Prevents from disallowing clicks on "copy to clipboard" elements inside toggles */
181+
e.stopPropagation();
182+
183+
navigator.clipboard.writeText(copyToClipboardElement.getAttribute('data-clipboard-text'));
184+
185+
let oldContent = copyToClipboardElement.textContent;
186+
187+
copyToClipboardElement.textContent = `✅ Copied!`;
188+
copyToClipboardElement.classList.add('status-success');
189+
190+
setTimeout(() => {
191+
copyToClipboardElement.textContent = oldContent;
192+
copyToClipboardElement.classList.remove('status-success');
193+
}, 7000);
194+
});
195+
});
196+
}
197+
176198
#convertDateTimesToUserTimezone() {
177199
const userTimezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone;
178200

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,6 @@
5050
};
5151
}
5252
53-
if (navigator.clipboard) {
54-
document.addEventListener('readystatechange', () => {
55-
if (document.readyState !== 'complete') {
56-
return;
57-
}
58-
59-
document.querySelectorAll('[data-clipboard-text]').forEach(function (element) {
60-
removeClass(element, 'hidden');
61-
element.addEventListener('click', function () {
62-
navigator.clipboard.writeText(element.getAttribute('data-clipboard-text'));
63-
64-
if (element.classList.contains("label")) {
65-
let oldContent = element.textContent;
66-
67-
element.textContent = "✅ Copied!";
68-
element.classList.add("status-success");
69-
70-
setTimeout(() => {
71-
element.textContent = oldContent;
72-
element.classList.remove("status-success");
73-
}, 7000);
74-
}
75-
});
76-
});
77-
});
78-
}
79-
8053
var request = function(url, onSuccess, onError, payload, options, tries) {
8154
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
8255
options = options || {};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy