|
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"> |
|
254 | 276 | } |
255 | 277 |
|
256 | 278 | // handle copy stacktrace action on clipboard button |
257 | | - document.getElementById('copy-stacktrace').onclick = function(e) { |
| 279 | + const copyIntoClipboard = function(e) { |
258 | 280 | e.preventDefault(); |
259 | | - var textarea = document.getElementById('clipboard'); |
| 281 | + const parentContainer = e.currentTarget.parentElement; |
| 282 | + const textarea = parentContainer.querySelector('#clipboard'); |
260 | 283 | textarea.focus(); |
261 | 284 | textarea.select(); |
262 | 285 |
|
263 | | - var succeeded; |
| 286 | + let succeeded; |
264 | 287 | try { |
265 | 288 | succeeded = document.execCommand('copy'); |
266 | 289 | } catch (err) { |
267 | 290 | succeeded = false; |
268 | 291 | } |
269 | 292 | if (succeeded) { |
270 | | - var hint = document.getElementById('copied'); |
| 293 | + const hint = parentContainer.querySelector('#copied'); |
| 294 | + if (!hint) { |
| 295 | + return |
| 296 | + } |
271 | 297 | hint.style.display = 'block'; |
272 | | - setTimeout(function () { |
273 | | - hint.style.display = 'none'; |
274 | | - }, 2000); |
| 298 | + setTimeout(() => hint.style.display = 'none', 2000); |
275 | 299 | } else { |
276 | 300 | // fallback: show textarea if browser does not support copying directly |
277 | 301 | textarea.style.top = 0; |
278 | 302 | } |
279 | 303 | } |
| 304 | + const elements = document.querySelectorAll('.copy-clipboard') |
| 305 | + for (let element of elements) { |
| 306 | + element.onclick = copyIntoClipboard; |
| 307 | + } |
| 308 | + |
280 | 309 |
|
281 | 310 | // handle theme change |
282 | 311 | document.getElementById('dark-mode').onclick = function(e) { |
|
0 commit comments