Skip to content

Commit 389a71c

Browse files
committed
remove inline style debugbar,welcome_message for CSP
1 parent a42449e commit 389a71c

File tree

6 files changed

+123
-54
lines changed

6 files changed

+123
-54
lines changed

app/Views/welcome_message.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,28 @@
150150
.further h2:first-of-type {
151151
padding-top: 0;
152152
}
153+
.f1 {
154+
fill: none;
155+
stroke: #000;
156+
stroke-linejoin: round;
157+
stroke-width: 32px;
158+
}
159+
160+
.f2 {
161+
fill: none;
162+
stroke: #000;
163+
stroke-linecap: round;
164+
stroke-linejoin: round;
165+
stroke-width: 32px;
166+
}
167+
168+
.f3 {
169+
fill: none;
170+
stroke: #000;
171+
stroke-linecap: round;
172+
stroke-miterlimit: 10;
173+
stroke-width: 32px;
174+
}
153175
footer {
154176
background-color: rgba(221, 72, 20, .8);
155177
text-align: center;
@@ -206,7 +228,7 @@
206228
</a>
207229
</li>
208230
<li class="menu-toggle">
209-
<button onclick="toggleMenu();">&#9776;</button>
231+
<button id="menuToggle">&#9776;</button>
210232
</li>
211233
<li class="menu-item hidden"><a href="#">Home</a></li>
212234
<li class="menu-item hidden"><a href="https://codeigniter4.github.io/userguide/" target="_blank">Docs</a>
@@ -253,7 +275,7 @@
253275
<h1>Go further</h1>
254276

255277
<h2>
256-
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><rect x='32' y='96' width='64' height='368' rx='16' ry='16' style='fill:none;stroke:#000;stroke-linejoin:round;stroke-width:32px'/><line x1='112' y1='224' x2='240' y2='224' style='fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/><line x1='112' y1='400' x2='240' y2='400' style='fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/><rect x='112' y='160' width='128' height='304' rx='16' ry='16' style='fill:none;stroke:#000;stroke-linejoin:round;stroke-width:32px'/><rect x='256' y='48' width='96' height='416' rx='16' ry='16' style='fill:none;stroke:#000;stroke-linejoin:round;stroke-width:32px'/><path d='M422.46,96.11l-40.4,4.25c-11.12,1.17-19.18,11.57-17.93,23.1l34.92,321.59c1.26,11.53,11.37,20,22.49,18.84l40.4-4.25c11.12-1.17,19.18-11.57,17.93-23.1L445,115C443.69,103.42,433.58,94.94,422.46,96.11Z' style='fill:none;stroke:#000;stroke-linejoin:round;stroke-width:32px'/></svg>
278+
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><rect x='32' y='96' width='64' height='368' rx='16' ry='16' class="f1" /><line x1='112' y1='224' x2='240' y2='224' class="f2" /><line x1='112' y1='400' x2='240' y2='400' class="f2" /><rect x='112' y='160' width='128' height='304' rx='16' ry='16' class="f1" /><rect x='256' y='48' width='96' height='416' rx='16' ry='16' class="f1" /><path d='M422.46,96.11l-40.4,4.25c-11.12,1.17-19.18,11.57-17.93,23.1l34.92,321.59c1.26,11.53,11.37,20,22.49,18.84l40.4-4.25c11.12-1.17,19.18-11.57,17.93-23.1L445,115C443.69,103.42,433.58,94.94,422.46,96.11Z' class="f1"/></svg>
257279
Learn
258280
</h2>
259281

@@ -263,7 +285,7 @@
263285
target="_blank">User Guide</a> !</p>
264286

265287
<h2>
266-
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><path d='M431,320.6c-1-3.6,1.2-8.6,3.3-12.2a33.68,33.68,0,0,1,2.1-3.1A162,162,0,0,0,464,215c.3-92.2-77.5-167-173.7-167C206.4,48,136.4,105.1,120,180.9a160.7,160.7,0,0,0-3.7,34.2c0,92.3,74.8,169.1,171,169.1,15.3,0,35.9-4.6,47.2-7.7s22.5-7.2,25.4-8.3a26.44,26.44,0,0,1,9.3-1.7,26,26,0,0,1,10.1,2L436,388.6a13.52,13.52,0,0,0,3.9,1,8,8,0,0,0,8-8,12.85,12.85,0,0,0-.5-2.7Z' style='fill:none;stroke:#000;stroke-linecap:round;stroke-miterlimit:10;stroke-width:32px'/><path d='M66.46,232a146.23,146.23,0,0,0,6.39,152.67c2.31,3.49,3.61,6.19,3.21,8s-11.93,61.87-11.93,61.87a8,8,0,0,0,2.71,7.68A8.17,8.17,0,0,0,72,464a7.26,7.26,0,0,0,2.91-.6l56.21-22a15.7,15.7,0,0,1,12,.2c18.94,7.38,39.88,12,60.83,12A159.21,159.21,0,0,0,284,432.11' style='fill:none;stroke:#000;stroke-linecap:round;stroke-miterlimit:10;stroke-width:32px'/></svg>
288+
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><path d='M431,320.6c-1-3.6,1.2-8.6,3.3-12.2a33.68,33.68,0,0,1,2.1-3.1A162,162,0,0,0,464,215c.3-92.2-77.5-167-173.7-167C206.4,48,136.4,105.1,120,180.9a160.7,160.7,0,0,0-3.7,34.2c0,92.3,74.8,169.1,171,169.1,15.3,0,35.9-4.6,47.2-7.7s22.5-7.2,25.4-8.3a26.44,26.44,0,0,1,9.3-1.7,26,26,0,0,1,10.1,2L436,388.6a13.52,13.52,0,0,0,3.9,1,8,8,0,0,0,8-8,12.85,12.85,0,0,0-.5-2.7Z' class="f3" /><path d='M66.46,232a146.23,146.23,0,0,0,6.39,152.67c2.31,3.49,3.61,6.19,3.21,8s-11.93,61.87-11.93,61.87a8,8,0,0,0,2.71,7.68A8.17,8.17,0,0,0,72,464a7.26,7.26,0,0,0,2.91-.6l56.21-22a15.7,15.7,0,0,1,12,.2c18.94,7.38,39.88,12,60.83,12A159.21,159.21,0,0,0,284,432.11' class="f3" /></svg>
267289
Discuss
268290
</h2>
269291

@@ -274,7 +296,7 @@
274296
target="_blank">chat on Slack</a> !</p>
275297

276298
<h2>
277-
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><line x1='176' y1='48' x2='336' y2='48' style='fill:none;stroke:#000;stroke-linecap:round;stroke-miterlimit:10;stroke-width:32px'/><line x1='118' y1='304' x2='394' y2='304' style='fill:none;stroke:#000;stroke-linecap:round;stroke-miterlimit:10;stroke-width:32px'/><path d='M208,48v93.48a64.09,64.09,0,0,1-9.88,34.18L73.21,373.49C48.4,412.78,76.63,464,123.08,464H388.92c46.45,0,74.68-51.22,49.87-90.51L313.87,175.66A64.09,64.09,0,0,1,304,141.48V48' style='fill:none;stroke:#000;stroke-linecap:round;stroke-miterlimit:10;stroke-width:32px'/></svg>
299+
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><line x1='176' y1='48' x2='336' y2='48' class="f3" /><line x1='118' y1='304' x2='394' y2='304' class="f3" /><path d='M208,48v93.48a64.09,64.09,0,0,1-9.88,34.18L73.21,373.49C48.4,412.78,76.63,464,123.08,464H388.92c46.45,0,74.68-51.22,49.87-90.51L313.87,175.66A64.09,64.09,0,0,1,304,141.48V48' class="f3" /></svg>
278300
Contribute
279301
</h2>
280302

@@ -309,7 +331,8 @@
309331

310332
<!-- SCRIPTS -->
311333

312-
<script>
334+
<script {csp-script-nonce}>
335+
document.getElementById("menuToggle").addEventListener('click',toggleMenu);
313336
function toggleMenu() {
314337
var menuItems = document.getElementsByClassName('menu-item');
315338
for (var i = 0; i < menuItems.length; i++) {

system/Debug/Toolbar.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ protected function renderTimelineRecursive(array $rows, float $startTime, int $s
197197
$open = $row['name'] === 'Controller';
198198

199199
if ($hasChildren || $isQuery) {
200-
$output .= '<tr class="timeline-parent' . ($open ? ' timeline-parent-open' : '') . '" id="timeline-' . $styleCount . '_parent" onclick="ciDebugBar.toggleChildRows(\'timeline-' . $styleCount . '\');">';
200+
$output .= '<tr class="timeline-parent' . ($open ? ' timeline-parent-open' : '') . '" id="timeline-' . $styleCount . '_parent" data-toggle="childrows" data-child="timeline-' . $styleCount . '">';
201201
} else {
202202
$output .= '<tr>';
203203
}
204204

205-
$output .= '<td class="' . ($isChild ? 'debug-bar-width30' : '') . '" style="--level: ' . $level . ';">' . ($hasChildren || $isQuery ? '<nav></nav>' : '') . $row['name'] . '</td>';
205+
$output .= '<td class="' . ($isChild ? 'debug-bar-width30' : '') . ' level-' . $level . '" >' . ($hasChildren || $isQuery ? '<nav></nav>' : '') . $row['name'] . '</td>';
206206
$output .= '<td class="' . ($isChild ? 'debug-bar-width10' : '') . '">' . $row['component'] . '</td>';
207207
$output .= '<td class="' . ($isChild ? 'debug-bar-width10 ' : '') . 'debug-bar-alignRight">' . number_format($row['duration'] * 1000, 2) . ' ms</td>';
208208
$output .= "<td class='debug-bar-noverflow' colspan='{$segmentCount}'>";
@@ -220,15 +220,15 @@ protected function renderTimelineRecursive(array $rows, float $startTime, int $s
220220

221221
// Add children if any
222222
if ($hasChildren || $isQuery) {
223-
$output .= '<tr class="child-row" id="timeline-' . ($styleCount - 1) . '_children" style="' . ($open ? '' : 'display: none;') . '">';
223+
$output .= '<tr class="child-row ' . ($open ? '' : ' debug-bar-ndisplay') . '" id="timeline-' . ($styleCount - 1) . '_children" >';
224224
$output .= '<td colspan="' . ($segmentCount + 3) . '" class="child-container">';
225225
$output .= '<table class="timeline">';
226226
$output .= '<tbody>';
227227

228228
if ($isQuery) {
229229
// Output query string if query
230230
$output .= '<tr>';
231-
$output .= '<td class="query-container" style="--level: ' . ($level + 1) . ';">' . $row['query'] . '</td>';
231+
$output .= '<td class="query-container level-' . ($level + 1) . '" >' . $row['query'] . '</td>';
232232
$output .= '</tr>';
233233
} else {
234234
// Recursively render children

system/Debug/Toolbar/Views/_database.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<tr class="{class}" title="{hover}" data-toggle="{qid}-trace">
1111
<td class="narrow">{duration}</td>
1212
<td>{! sql !}</td>
13-
<td style="text-align: right"><strong>{trace-file}</strong></td>
13+
<td class="debug-bar-alignRight"><strong>{trace-file}</strong></td>
1414
</tr>
15-
<tr class="muted" id="{qid}-trace" style="display:none">
15+
<tr class="muted debug-bar-ndisplay" id="{qid}-trace">
1616
<td></td>
1717
<td colspan="2">
1818
{trace}

system/Debug/Toolbar/Views/toolbar.js

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var ciDebugBar = {
4949
var tab = ciDebugBar.readCookie("debug-bar-tab");
5050
if (document.getElementById(tab)) {
5151
var el = document.getElementById(tab);
52-
el.style.display = "block";
52+
ciDebugBar.switchClass(el,"debug-bar-ndisplay","debug-bar-dblock");
5353
ciDebugBar.addClass(el, "active");
5454
tab = document.querySelector("[data-tab=" + tab + "]");
5555
if (tab) {
@@ -70,7 +70,24 @@ var ciDebugBar = {
7070
// Hook up generic toggle via data attributes `data-toggle="foo"`
7171
var links = this.toolbar.querySelectorAll("[data-toggle]");
7272
for (var i = 0; i < links.length; i++) {
73-
links[i].addEventListener("click", ciDebugBar.toggleRows, true);
73+
let toggleData = links[i].getAttribute("data-toggle");
74+
if(toggleData=="datatable"){
75+
76+
let datatable = links[i].getAttribute("data-table");
77+
links[i].addEventListener("click", function(){
78+
ciDebugBar.toggleDataTable(datatable)
79+
}, true);
80+
81+
}else if(toggleData=="childrows"){
82+
83+
let child = links[i].getAttribute("data-child");
84+
links[i].addEventListener("click", function(){
85+
ciDebugBar.toggleChildRows(child)
86+
}, true);
87+
88+
}else{
89+
links[i].addEventListener("click", ciDebugBar.toggleRows, true);
90+
}
7491
}
7592
},
7693

@@ -79,21 +96,21 @@ var ciDebugBar = {
7996
var tab = document.getElementById(this.getAttribute("data-tab"));
8097

8198
// If the label have not a tab stops here
82-
if (!tab) {
99+
if (! tab) {
83100
return;
84101
}
85102

86103
// Remove debug-bar-tab cookie
87104
ciDebugBar.createCookie("debug-bar-tab", "", -1);
88105

89106
// Check our current state.
90-
var state = tab.style.display;
107+
var state = tab.classList.contains("debug-bar-dblock");
91108

92109
// Hide all tabs
93110
var tabs = document.querySelectorAll("#debug-bar .tab");
94111

95112
for (var i = 0; i < tabs.length; i++) {
96-
tabs[i].style.display = "none";
113+
ciDebugBar.switchClass(tabs[i],"debug-bar-dblock","debug-bar-ndisplay");
97114
}
98115

99116
// Mark all labels as inactive
@@ -104,8 +121,8 @@ var ciDebugBar = {
104121
}
105122

106123
// Show/hide the selected tab
107-
if (state != "block") {
108-
tab.style.display = "block";
124+
if (! state) {
125+
ciDebugBar.switchClass(tab,"debug-bar-ndisplay","debug-bar-dblock");
109126
ciDebugBar.addClass(this.parentNode, "active");
110127
// Create debug-bar-tab cookie to persistent state
111128
ciDebugBar.createCookie(
@@ -138,6 +155,11 @@ var ciDebugBar = {
138155
}
139156
},
140157

158+
switchClass : function(el,classFrom,classTo){
159+
ciDebugBar.removeClass(el,classFrom);
160+
ciDebugBar.addClass(el,classTo);
161+
},
162+
141163
/**
142164
* Toggle display of another object based on
143165
* the data-toggle value of this object
@@ -150,8 +172,12 @@ var ciDebugBar = {
150172
let target = document.getElementById(
151173
row.getAttribute("data-toggle")
152174
);
153-
target.style.display =
154-
target.style.display === "none" ? "table-row" : "none";
175+
176+
if(target.classList.contains("debug-bar-ndisplay")) {
177+
ciDebugBar.switchClass(target,"debug-bar-ndisplay","debug-bar-dtableRow");
178+
}else{
179+
ciDebugBar.switchClass(target,"debug-bar-dtableRow","debug-bar-ndisplay");
180+
}
155181
}
156182
},
157183

@@ -166,7 +192,11 @@ var ciDebugBar = {
166192
}
167193

168194
if (obj) {
169-
obj.style.display = obj.style.display === "none" ? "block" : "none";
195+
if(obj.classList.contains("debug-bar-ndisplay")){
196+
ciDebugBar.switchClass(obj,"debug-bar-ndisplay","debug-bar-dblock");
197+
}else{
198+
ciDebugBar.switchClass(obj,"debug-bar-dblock","debug-bar-ndisplay");
199+
}
170200
}
171201
},
172202

@@ -182,7 +212,13 @@ var ciDebugBar = {
182212
}
183213

184214
if (par && obj) {
185-
obj.style.display = obj.style.display === "none" ? "" : "none";
215+
216+
if(obj.classList.contains("debug-bar-ndisplay")){
217+
ciDebugBar.removeClass(obj,"debug-bar-ndisplay");
218+
}else{
219+
ciDebugBar.addClass(obj,"debug-bar-ndisplay");
220+
}
221+
186222
par.classList.toggle("timeline-parent-open");
187223
}
188224
},
@@ -193,11 +229,15 @@ var ciDebugBar = {
193229
* Toggle tool bar from full to icon and icon to full
194230
*/
195231
toggleToolbar: function () {
196-
var open = ciDebugBar.toolbar.style.display != "none";
197-
198-
ciDebugBar.icon.style.display = open == true ? "inline-block" : "none";
199-
ciDebugBar.toolbar.style.display =
200-
open == false ? "inline-block" : "none";
232+
var open = ! ciDebugBar.toolbar.classList.contains("debug-bar-ndisplay");
233+
234+
if(open){
235+
ciDebugBar.switchClass(ciDebugBar.icon,"debug-bar-ndisplay","debug-bar-dinlineBlock");
236+
ciDebugBar.switchClass(ciDebugBar.toolbar,"debug-bar-dinlineBlock","debug-bar-ndisplay");
237+
}else{
238+
ciDebugBar.switchClass(ciDebugBar.icon,"debug-bar-dinlineBlock","debug-bar-ndisplay");
239+
ciDebugBar.switchClass(ciDebugBar.toolbar,"debug-bar-ndisplay","debug-bar-dinlineBlock");
240+
}
201241

202242
// Remember it for other page loads on this site
203243
ciDebugBar.createCookie("debug-bar-state", "", -1);
@@ -215,10 +255,13 @@ var ciDebugBar = {
215255
setToolbarState: function () {
216256
var open = ciDebugBar.readCookie("debug-bar-state");
217257

218-
ciDebugBar.icon.style.display =
219-
open != "open" ? "inline-block" : "none";
220-
ciDebugBar.toolbar.style.display =
221-
open == "open" ? "inline-block" : "none";
258+
if(open !="open"){
259+
ciDebugBar.switchClass(ciDebugBar.icon,"debug-bar-ndisplay","debug-bar-dinlineBlock");
260+
ciDebugBar.switchClass(ciDebugBar.toolbar,"debug-bar-dinlineBlock","debug-bar-ndisplay");
261+
}else{
262+
ciDebugBar.switchClass(ciDebugBar.icon,"debug-bar-dinlineBlock","debug-bar-ndisplay");
263+
ciDebugBar.switchClass(ciDebugBar.toolbar,"debug-bar-ndisplay","debug-bar-dinlineBlock");
264+
}
222265
},
223266

224267
toggleViewsHints: function () {
@@ -494,7 +537,7 @@ var ciDebugBar = {
494537
var btn = document.querySelector("[data-tab=ci-views]");
495538

496539
// If the Views Collector is inactive stops here
497-
if (!btn) {
540+
if (! btn) {
498541
return;
499542
}
500543

@@ -527,7 +570,7 @@ var ciDebugBar = {
527570

528571
ciDebugBar.createCookie("debug-bar-position", "", -1);
529572

530-
if (!position || position === "bottom") {
573+
if (! position || position === "bottom") {
531574
ciDebugBar.createCookie("debug-bar-position", "top", 365);
532575
ciDebugBar.addClass(ciDebugBar.icon, "fixed-top");
533576
ciDebugBar.addClass(ciDebugBar.toolbar, "fixed-top");
@@ -569,7 +612,7 @@ var ciDebugBar = {
569612
var theme = ciDebugBar.readCookie("debug-bar-theme");
570613

571614
if (
572-
!theme &&
615+
! theme &&
573616
window.matchMedia("(prefers-color-scheme: dark)").matches
574617
) {
575618
// If there is no cookie, and "prefers-color-scheme" is set to "dark"
@@ -617,7 +660,7 @@ var ciDebugBar = {
617660
var eventSource;
618661

619662
// If the Hot Reload Collector is inactive stops here
620-
if (!btn) {
663+
if (! btn) {
621664
return;
622665
}
623666

@@ -716,7 +759,7 @@ var ciDebugBar = {
716759
for (var i = 0; i < rowGet.length; i++) {
717760
row = rowGet[i];
718761
if (!/\/\(.+?\)/.test(rowGet[i].innerText)) {
719-
row.style = "cursor: pointer;";
762+
ciDebugBar.addClass(row,"debug-bar-pointer");
720763
row.setAttribute(
721764
"title",
722765
location.origin + "/" + ciDebugBar.trimSlash(row.innerText)
@@ -741,7 +784,7 @@ var ciDebugBar = {
741784
patt,
742785
'<input type="text" placeholder="$1">'
743786
) +
744-
'<input type="submit" value="Go" style="margin-left: 4px;">' +
787+
'<input type="submit" value="Go" class="debug-bar-mleft4">' +
745788
"</form>";
746789
}
747790
}

0 commit comments

Comments
 (0)