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

Skip to content

Commit 53046a3

Browse files
ohadernicolas-grekas
authored andcommitted
[VarDumper] Reduce stylesheet assignments via JavaScript in HtmlDumper
1 parent 1250a93 commit 53046a3

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,17 @@ protected function getDumpHeader()
149149
<script>
150150
Sfdump = window.Sfdump || (function (doc) {
151151
152-
var refStyle = doc.createElement('style'),
153-
rxEsc = /([.*+?^${}()|\[\]\/\\])/g,
152+
if (doc.body instanceof HTMLElement) {
153+
doc.body.classList.add('sf-js-enabled');
154+
}
155+
156+
var rxEsc = /([.*+?^${}()|\[\]\/\\])/g,
154157
idRx = /\bsf-dump-\d+-ref[012]\w+\b/,
155158
keyHint = 0 <= navigator.platform.toUpperCase().indexOf('MAC') ? 'Cmd' : 'Ctrl',
156159
addEventListener = function (e, n, cb) {
157160
e.addEventListener(n, cb, false);
158161
};
159162
160-
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; }';
161-
doc.head.appendChild(refStyle);
162-
refStyle = doc.createElement('style');
163-
doc.head.appendChild(refStyle);
164-
165163
if (!doc.addEventListener) {
166164
addEventListener = function (element, eventName, callback) {
167165
element.attachEvent('on' + eventName, function (e) {
@@ -341,19 +339,9 @@ function xpathString(str) {
341339
function xpathHasClass(className) {
342340
return "contains(concat(' ', normalize-space(@class), ' '), ' " + className +" ')";
343341
}
344-
addEventListener(root, 'mouseover', function (e) {
345-
if ('' != refStyle.innerHTML) {
346-
refStyle.innerHTML = '';
347-
}
348-
});
349342
a('mouseover', function (a, e, c) {
350343
if (c) {
351344
e.target.style.cursor = "pointer";
352-
} else if (a = idRx.exec(a.className)) {
353-
try {
354-
refStyle.innerHTML = 'pre.sf-dump .'+a[0]+'{background-color: #B729D9; color: #FFF !important; border-radius: 2px}';
355-
} catch (e) {
356-
}
357345
}
358346
});
359347
a('click', function (a, e, c) {
@@ -422,6 +410,7 @@ function xpathHasClass(className) {
422410
}
423411
} else if (/\bsf-dump-ref\b/.test(elt.className) && (a = elt.getAttribute('href'))) {
424412
a = a.slice(1);
413+
elt.className += ' sf-dump-hover';
425414
elt.className += ' '+a;
426415
427416
if (/[\[{]$/.test(elt.previousSibling.nodeValue)) {
@@ -638,6 +627,16 @@ function showCurrent(state)
638627
639628
})(document);
640629
</script><style>
630+
.sf-js-enabled pre.sf-dump .sf-dump-compact,
631+
.sf-js-enabled .sf-dump-str-collapse .sf-dump-str-collapse,
632+
.sf-js-enabled .sf-dump-str-expand .sf-dump-str-expand {
633+
display: none;
634+
}
635+
.sf-dump-hover:hover {
636+
background-color: #B729D9;
637+
color: #FFF !important;
638+
border-radius: 2px;
639+
}
641640
pre.sf-dump {
642641
display: block;
643642
white-space: pre;

0 commit comments

Comments
 (0)