Skip to content

Commit

Permalink
[VarDumper] Reduce stylesheet assignments via JavaScript in HtmlDumper
Browse files Browse the repository at this point in the history
  • Loading branch information
ohader authored and nicolas-grekas committed May 16, 2023
1 parent cb21bc9 commit 54894d9
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions Dumper/HtmlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,17 @@ protected function getDumpHeader()
<script>
Sfdump = window.Sfdump || (function (doc) {
var refStyle = doc.createElement('style'),
rxEsc = /([.*+?^${}()|\[\]\/\\])/g,
if (doc.body instanceof HTMLElement) {
doc.body.classList.add('sf-js-enabled');
}
var rxEsc = /([.*+?^${}()|\[\]\/\\])/g,
idRx = /\bsf-dump-\d+-ref[012]\w+\b/,
keyHint = 0 <= navigator.platform.toUpperCase().indexOf('MAC') ? 'Cmd' : 'Ctrl',
addEventListener = function (e, n, cb) {
e.addEventListener(n, cb, false);
};
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; }';
doc.head.appendChild(refStyle);
refStyle = doc.createElement('style');
doc.head.appendChild(refStyle);
if (!doc.addEventListener) {
addEventListener = function (element, eventName, callback) {
element.attachEvent('on' + eventName, function (e) {
Expand Down Expand Up @@ -341,19 +339,9 @@ function xpathString(str) {
function xpathHasClass(className) {
return "contains(concat(' ', normalize-space(@class), ' '), ' " + className +" ')";
}
addEventListener(root, 'mouseover', function (e) {
if ('' != refStyle.innerHTML) {
refStyle.innerHTML = '';
}
});
a('mouseover', function (a, e, c) {
if (c) {
e.target.style.cursor = "pointer";
} else if (a = idRx.exec(a.className)) {
try {
refStyle.innerHTML = 'pre.sf-dump .'+a[0]+'{background-color: #B729D9; color: #FFF !important; border-radius: 2px}';
} catch (e) {
}
}
});
a('click', function (a, e, c) {
Expand Down Expand Up @@ -422,6 +410,7 @@ function xpathHasClass(className) {
}
} else if (/\bsf-dump-ref\b/.test(elt.className) && (a = elt.getAttribute('href'))) {
a = a.slice(1);
elt.className += ' sf-dump-hover';
elt.className += ' '+a;
if (/[\[{]$/.test(elt.previousSibling.nodeValue)) {
Expand Down Expand Up @@ -638,6 +627,16 @@ function showCurrent(state)
})(document);
</script><style>
.sf-js-enabled pre.sf-dump .sf-dump-compact,
.sf-js-enabled .sf-dump-str-collapse .sf-dump-str-collapse,
.sf-js-enabled .sf-dump-str-expand .sf-dump-str-expand {
display: none;
}
.sf-dump-hover:hover {
background-color: #B729D9;
color: #FFF !important;
border-radius: 2px;
}
pre.sf-dump {
display: block;
white-space: pre;
Expand Down

0 comments on commit 54894d9

Please sign in to comment.