Skip to content

Commit 2582088

Browse files
authored
fix: initialize standalone toolbar (#9950)
* fix: initialize standalone toolbar * initialize standalone with ensureToolbarContainer
1 parent e5111b1 commit 2582088

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

system/Debug/Toolbar/Views/toolbar.tpl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<script id="toolbar_js">
2929
var ciSiteURL = "<?= rtrim(site_url(), '/') ?>"
3030
<?= file_get_contents(__DIR__ . '/toolbar.js') ?>
31+
<?= file_get_contents(__DIR__ . '/toolbarstandalone.js') ?>
3132
</script>
3233
<div id="debug-icon" class="debug-bar-ndisplay">
3334
<a id="debug-icon-link">
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Bootstrap for standalone Debug Toolbar pages (?debugbar_time=...).
3+
*/
4+
5+
if (! document.getElementById('debugbar_loader')) {
6+
if (typeof loadDoc !== 'function') {
7+
window.loadDoc = function (time) {
8+
if (isNaN(time)) {
9+
return;
10+
}
11+
12+
window.location.href = ciSiteURL + '?debugbar_time=' + time;
13+
};
14+
}
15+
16+
(function () {
17+
function ensureToolbarContainer(icon, toolbar) {
18+
let toolbarContainer = document.getElementById('toolbarContainer');
19+
20+
if (toolbarContainer) {
21+
return;
22+
}
23+
24+
toolbarContainer = document.createElement('div');
25+
toolbarContainer.setAttribute('id', 'toolbarContainer');
26+
27+
if (icon) {
28+
toolbarContainer.appendChild(icon);
29+
}
30+
31+
if (toolbar) {
32+
toolbarContainer.appendChild(toolbar);
33+
}
34+
35+
document.body.appendChild(toolbarContainer);
36+
}
37+
38+
function initStandaloneToolbar() {
39+
if (typeof ciDebugBar !== 'object') {
40+
return;
41+
}
42+
43+
const icon = document.getElementById('debug-icon');
44+
const toolbar = document.getElementById('debug-bar');
45+
46+
if (! toolbar || ! icon) {
47+
return;
48+
}
49+
50+
const currentTime = new URLSearchParams(window.location.search).get('debugbar_time');
51+
52+
if (currentTime && ! isNaN(currentTime)) {
53+
if (! localStorage.getItem('debugbar-time')) {
54+
localStorage.setItem('debugbar-time', currentTime);
55+
}
56+
localStorage.setItem('debugbar-time-new', currentTime);
57+
}
58+
59+
ensureToolbarContainer(icon, toolbar);
60+
ciDebugBar.init();
61+
}
62+
63+
if (document.readyState === 'loading') {
64+
document.addEventListener('DOMContentLoaded', initStandaloneToolbar, false);
65+
} else {
66+
initStandaloneToolbar();
67+
}
68+
})();
69+
}

user_guide_src/source/changelogs/v4.7.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Bugs Fixed
4242
- **ContentSecurityPolicy:** Fixed a bug where ``generateNonces()`` produces corrupted JSON responses by replacing CSP nonce placeholders with unescaped double quotes. The method now automatically JSON-escapes nonce attributes when the response Content-Type is JSON.
4343
- **Model:** Fixed a bug where ``BaseModel::updateBatch()`` threw an exception when ``updateOnlyChanged`` was ``true`` and the index field value did not change.
4444
- **Session:** Fixed a bug in ``MemcachedHandler`` where the constructor incorrectly threw an exception when ``savePath`` was not empty.
45+
- **Toolbar:** Fixed a bug where the standalone toolbar page loaded from ``?debugbar_time=...`` was not interactive.
4546

4647
See the repo's
4748
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)