|
88 | 88 | <textarea id="clipboard"><?= $this->htmlEncode($throwable) ?></textarea> |
89 | 89 | <span id="copied">Copied!</span> |
90 | 90 |
|
91 | | - <a href="#" id="copy-stacktrace" title="Copy the stacktrace for use in a bug report or pastebin"> |
| 91 | + <a href="#" |
| 92 | + class="copy-clipboard" |
| 93 | + data-clipboard="<?= $this->htmlEncode($throwable) ?>" |
| 94 | + title="Copy the stacktrace for use in a bug report or pastebin" |
| 95 | + > |
92 | 96 | <svg width="26" height="30" fill="none" xmlns="http://www.w3.org/2000/svg"> |
93 | 97 | <path d="M17.9998.333344H3.33317C1.8665.333344.666504 1.53334.666504 3.00001V20.3333c0 .7334.599996 1.3334 1.333336 1.3334.73333 0 1.33333-.6 1.33333-1.3334V4.33334c0-.73333.6-1.33333 1.33333-1.33333h13.3333c.7334 0 1.3334-.6 1.3334-1.33333 0-.733337-.6-1.333336-1.3334-1.333336zm5.3334 5.333336H8.6665c-1.46666 0-2.66666 1.2-2.66666 2.66666V27c0 1.4667 1.2 2.6667 2.66666 2.6667h14.6667c1.4666 0 2.6666-1.2 2.6666-2.6667V8.33334c0-1.46666-1.2-2.66666-2.6666-2.66666zM21.9998 27H9.99984c-.73333 0-1.33334-.6-1.33334-1.3333V9.66668c0-.73334.60001-1.33334 1.33334-1.33334H21.9998c.7334 0 1.3334.6 1.3334 1.33334V25.6667c0 .7333-.6 1.3333-1.3334 1.3333z" fill="#787878"/> |
94 | 98 | </svg> |
|
107 | 111 | </div> |
108 | 112 | <?php if ($request && ($requestInfo = $this->renderRequest($request)) !== ''): ?> |
109 | 113 | <div class="request"> |
110 | | - <?= $requestInfo ?> |
| 114 | + <h2>Request info</h2> |
| 115 | + <div class="body"> |
| 116 | + <pre class="codeBlock language-text"><?= $this->htmlEncode(rtrim($requestInfo, "\n")) ?></pre> |
| 117 | + </div> |
111 | 118 | </div> |
112 | 119 | <?php endif ?> |
113 | 120 | <?php if ($request && ($curlInfo = $this->renderCurl($request)) !== 'curl'): ?> |
114 | 121 | <div class="request"> |
115 | | - <?= $curlInfo ?> |
| 122 | + <textarea id="clipboard"><?= $curlInfo ?></textarea> |
| 123 | + <span id="copied" style="top: 10px">Copied!</span> |
| 124 | + <h2>cURL</h2> |
| 125 | + <a href="#" |
| 126 | + class="copy-clipboard" |
| 127 | + data-clipboard="<?= $curlInfo ?>" |
| 128 | + title="Copy the cURL" |
| 129 | + style="right: 10px; top: 5px" |
| 130 | + > |
| 131 | + <svg width="26" height="30" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 132 | + <path d="M17.9998.333344H3.33317C1.8665.333344.666504 1.53334.666504 3.00001V20.3333c0 .7334.599996 1.3334 1.333336 1.3334.73333 0 1.33333-.6 1.33333-1.3334V4.33334c0-.73333.6-1.33333 1.33333-1.33333h13.3333c.7334 0 1.3334-.6 1.3334-1.33333 0-.733337-.6-1.333336-1.3334-1.333336zm5.3334 5.333336H8.6665c-1.46666 0-2.66666 1.2-2.66666 2.66666V27c0 1.4667 1.2 2.6667 2.66666 2.6667h14.6667c1.4666 0 2.6666-1.2 2.6666-2.6667V8.33334c0-1.46666-1.2-2.66666-2.6666-2.66666zM21.9998 27H9.99984c-.73333 0-1.33334-.6-1.33334-1.3333V9.66668c0-.73334.60001-1.33334 1.33334-1.33334H21.9998c.7334 0 1.3334.6 1.3334 1.33334V25.6667c0 .7333-.6 1.3333-1.3334 1.3333z" fill="#787878"/> |
| 133 | + </svg> |
| 134 | + </a> |
| 135 | + <div class="body"> |
| 136 | + <div class="codeBlock language-sh"><?= $this->htmlEncode($curlInfo) ?></div> |
| 137 | + </div> |
116 | 138 | </div> |
117 | 139 | <?php endif ?> |
118 | 140 | <div class="footer"> |
|
291 | 313 | } |
292 | 314 |
|
293 | 315 | // handle copy stacktrace action on clipboard button |
294 | | - document.getElementById('copy-stacktrace').onclick = function(e) { |
| 316 | + const copyIntoClipboard = function(e) { |
295 | 317 | e.preventDefault(); |
296 | | - var textarea = document.getElementById('clipboard'); |
| 318 | + const parentContainer = e.currentTarget.parentElement; |
| 319 | + const textarea = parentContainer.querySelector('#clipboard'); |
297 | 320 | textarea.focus(); |
298 | 321 | textarea.select(); |
299 | 322 |
|
300 | | - var succeeded; |
| 323 | + let succeeded; |
301 | 324 | try { |
302 | 325 | succeeded = document.execCommand('copy'); |
303 | 326 | } catch (err) { |
304 | 327 | succeeded = false; |
305 | 328 | } |
306 | 329 | if (succeeded) { |
307 | | - var hint = document.getElementById('copied'); |
| 330 | + const hint = parentContainer.querySelector('#copied'); |
| 331 | + if (!hint) { |
| 332 | + return |
| 333 | + } |
308 | 334 | hint.style.display = 'block'; |
309 | | - setTimeout(function () { |
310 | | - hint.style.display = 'none'; |
311 | | - }, 2000); |
| 335 | + setTimeout(() => hint.style.display = 'none', 2000); |
312 | 336 | } else { |
313 | 337 | // fallback: show textarea if browser does not support copying directly |
314 | 338 | textarea.style.top = 0; |
315 | 339 | } |
316 | 340 | } |
| 341 | + const elements = document.querySelectorAll('.copy-clipboard') |
| 342 | + for (let element of elements) { |
| 343 | + element.onclick = copyIntoClipboard; |
| 344 | + } |
| 345 | + |
317 | 346 |
|
318 | 347 | // handle theme change |
319 | 348 | document.getElementById('dark-mode').onclick = function(e) { |
|
0 commit comments