Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[VarDumper] Reduce stylesheet assignments via JavaScript in HtmlDumper #49977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/Symfony/Component/VarDumper/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