8000 [WebProfilerBundle] Fix Copy as Curl · symfony/symfony@c97f0f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c97f0f9

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

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

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

+32-8
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,41 @@
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.disabled = true;
189+
copyToClipboardElement.classList.add('status-success');
190+
191+
setTimeout(() => {
192+
copyToClipboardElement.textContent = oldContent;
193+
copyToClipboardElement.disabled = false;
194+
copyToClipboardElement.classList.remove('status-success');
195+
}, 7000);
196+
});
197+
});
198+
}
199+
176200
#convertDateTimesToUserTimezone() {
177201
const userTimezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone;
178202

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

-27
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)
0