Skip to content

Commit 73f0a82

Browse files
committed
initialize standalone with ensureToolbarContainer
1 parent 740d2be commit 73f0a82

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

system/Debug/Toolbar/Views/toolbar.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ var ciDebugBar = {
88
icon: null,
99

1010
init: function () {
11-
// Standalone debugbar pages do not have #toolbarContainer, use body as fallback.
12-
this.toolbarContainer = document.getElementById("toolbarContainer") || document.body;
11+
this.toolbarContainer = document.getElementById("toolbarContainer");
1312
this.toolbar = document.getElementById("debug-bar");
1413
this.icon = document.getElementById("debug-icon");
1514

system/Debug/Toolbar/Views/toolbarstandalone.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,54 @@ if (! document.getElementById('debugbar_loader')) {
99
return;
1010
}
1111

12-
localStorage.setItem('debugbar-time', time);
13-
localStorage.setItem('debugbar-time-new', time);
1412
window.location.href = ciSiteURL + '?debugbar_time=' + time;
1513
};
1614
}
1715

1816
(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+
1938
function initStandaloneToolbar() {
2039
if (typeof ciDebugBar !== 'object') {
2140
return;
2241
}
2342

24-
if (! document.getElementById('debug-bar') || ! document.getElementById('debug-icon')) {
43+
const icon = document.getElementById('debug-icon');
44+
const toolbar = document.getElementById('debug-bar');
45+
46+
if (! toolbar || ! icon) {
2547
return;
2648
}
2749

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);
2860
ciDebugBar.init();
2961
}
3062

0 commit comments

Comments
 (0)