Skip to content

Commit 64a3403

Browse files
minor #49977 [VarDumper] Reduce stylesheet assignments via JavaScript in HtmlDumper (ohader)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [VarDumper] Reduce stylesheet assignments via JavaScript in `HtmlDumper` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | *none* | License | MIT The dynamic `<style>` element in the JavaScript variable `refStyle` can be replaced by static CSS and element states. The new rule `.sf-dump-hover:hover` substitutes JavaScript event handling for `mouseover` events. This is a preparation to have the possibility to assign `nonce` HTML attributes to inline `<script>` and `<style>` nodes, e.g. shown as proof-of-concept at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78512/2/typo3/sysext/adminpanel/Classes/Utility/HtmlDumper.php Commits ------- 53046a3bac [VarDumper] Reduce stylesheet assignments via JavaScript in `HtmlDumper`
2 parents b53bbaa + 54894d9 commit 64a3403

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

Dumper/HtmlDumper.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,17 @@ protected function getDumpHeader()
163163
<script>
164164
Sfdump = window.Sfdump || (function (doc) {
165165
166-
var refStyle = doc.createElement('style'),
167-
rxEsc = /([.*+?^${}()|\[\]\/\\])/g,
166+
if (doc.body instanceof HTMLElement) {
167+
doc.body.classList.add('sf-js-enabled');
168+
}
169+
170+
var rxEsc = /([.*+?^${}()|\[\]\/\\])/g,
168171
idRx = /\bsf-dump-\d+-ref[012]\w+\b/,
169172
keyHint = 0 <= navigator.platform.toUpperCase().indexOf('MAC') ? 'Cmd' : 'Ctrl',
170173
addEventListener = function (e, n, cb) {
171174
e.addEventListener(n, cb, false);
172175
};
173176
174-
refStyle.innerHTML = 'pre.sf-dump .sf-dump-compact, .sf-dump-str-collapse .sf-dump-str-collapse, .sf-dump-str-expand .sf-dump-str-expand { display: none; }';
175-
doc.head.appendChild(refStyle);
176-
refStyle = doc.createElement('style');
177-
doc.head.appendChild(refStyle);
178-
179177
if (!doc.addEventListener) {
180178
addEventListener = function (element, eventName, callback) {
181179
element.attachEvent('on' + eventName, function (e) {
@@ -355,19 +353,9 @@ function xpathString(str) {
355353
function xpathHasClass(className) {
356354
return "contains(concat(' ', normalize-space(@class), ' '), ' " + className +" ')";
357355
}
358-
addEventListener(root, 'mouseover', function (e) {
359-
if ('' != refStyle.innerHTML) {
360-
refStyle.innerHTML = '';
361-
}
362-
});
363356
a('mouseover', function (a, e, c) {
364357
if (c) {
365358
e.target.style.cursor = "pointer";
366-
} else if (a = idRx.exec(a.className)) {
367-
try {
368-
refStyle.innerHTML = 'pre.sf-dump .'+a[0]+'{background-color: #B729D9; color: #FFF !important; border-radius: 2px}';
369-
} catch (e) {
370-
}
371359
}
372360
});
373361
a('click', function (a, e, c) {
@@ -436,6 +424,7 @@ function xpathHasClass(className) {
436424
}
437425
} else if (/\bsf-dump-ref\b/.test(elt.className) && (a = elt.getAttribute('href'))) {
438426
a = a.slice(1);
427+
elt.className += ' sf-dump-hover';
439428
elt.className += ' '+a;
440429
441430
if (/[\[{]$/.test(elt.previousSibling.nodeValue)) {
@@ -652,6 +641,16 @@ function showCurrent(state)
652641
653642
})(document);
654643
</script><style>
644+
.sf-js-enabled pre.sf-dump .sf-dump-compact,
645+
.sf-js-enabled .sf-dump-str-collapse .sf-dump-str-collapse,
646+
.sf-js-enabled .sf-dump-str-expand .sf-dump-str-expand {
647+
display: none;
648+
}
649+
.sf-dump-hover:hover {
650+
background-color: #B729D9;
651+
color: #FFF !important;
652+
border-radius: 2px;
653+
}
655654
pre.sf-dump {
656655
display: block;
657656
white-space: pre;

0 commit comments

Comments
 (0)