@@ -24,7 +24,7 @@ class HtmlDumper extends CliDumper
24
24
public static $ defaultOutput = 'php://output ' ;
25
25
26
26
protected $ dumpHeader ;
27
- protected $ dumpPrefix = '<pre class=sf-dump id=%s data-indent-pad="%s"> ' ;
27
+ protected $ dumpPrefix = '<pre class=sf-dump id=%s data-indent-pad="%s" data-collapsed-by-default-nodes-higher-than="%s" > ' ;
28
28
protected $ dumpSuffix = '</pre><script>Sfdump("%s")</script> ' ;
29
29
protected $ dumpId = 'sf-dump ' ;
30
30
protected $ colors = true ;
@@ -45,6 +45,10 @@ class HtmlDumper extends CliDumper
45
45
'index ' => 'color:#1299DA ' ,
46
46
);
47
47
48
+ protected $ jsProperties = array (
49
+ 'collapsedByDefaultNodesHigherThan ' => 1
50
+ );
51
+
48
52
/**
49
53
* {@inheritdoc}
50
54
*/
@@ -75,6 +79,16 @@ public function setStyles(array $styles)
75
79
$ this ->styles = $ styles + $ this ->styles ;
76
80
}
77
81
82
+ /**
83
+ * Configures js properties.
84
+ *
85
+ * @param array $jsProperties A map of jsProperties names to customize the behavior.
86
+ */
87
+ public function setJsProperties (array $ jsProperties )
88
+ {
89
+ $ this ->jsProperties = $ jsProperties ;
90
+ }
91
+
78
92
/**
79
93
* Sets an HTML header that will be dumped once in the output stream.
80
94
*
@@ -119,6 +133,7 @@ protected function getDumpHeader()
119
133
120
134
$ line = <<<'EOHTML'
121
135
<script>
136
+
122
137
Sfdump = window.Sfdump || (function (doc) {
123
138
124
139
var refStyle = doc.createElement('style'),
@@ -175,6 +190,7 @@ function toggle(a, recursive) {
175
190
176
191
return function (root) {
177
192
root = doc.getElementById(root);
193
+ var collapsedByDefaultNodesHigherThan = root.getAttribute('data-collapsed-by-default-nodes-higher-than');
178
194
179
195
function a(e, f) {
180
196
addEventListener(root, e, function (e) {
@@ -252,6 +268,19 @@ function isCtrlKey(e) {
252
268
len = t.length;
253
269
i = t = 0;
254
270
271
+ function getLevelNodeFromRoot(node, level) {
272
+ level = level || 0;
273
+ level++;
274
+
275
+ node = node.parentNode;
276
+
277
+ if ('sf-dump' == node.className) {
278
+ return level;
279
+ }
280
+
281
+ return getLevelNodeFromRoot(node, level);
282
+ }
283
+
255
284
while (i < len) {
256
285
elt = root[i];
257
286
if ("SAMP" == elt.tagName) {
@@ -267,9 +296,11 @@ function isCtrlKey(e) {
267
296
a.title = (a.title ? a.title+'\n[' : '[')+keyHint+'+click] Expand all children';
268
297
a.innerHTML += '<span>▼</span>';
269
298
a.className += ' sf-dump-toggle';
270
- if ('sf-dump' != elt.parentNode.className) {
299
+
300
+ if (getLevelNodeFromRoot(elt) > collapsedByDefaultNodesHigherThan) {
271
301
toggle(a);
272
302
}
303
+
273
304
} else if ("sf-dump-ref" == elt.className && (a = elt.getAttribute('href'))) {
274
305
a = a.substr(1);
275
306
elt.className += ' '+a;
@@ -431,7 +462,12 @@ protected function style($style, $value, $attr = array())
431
462
protected function dumpLine ($ depth , $ endOfValue = false )
432
463
{
433
464
if (-1 === $ this ->lastDepth ) {
434
- $ this ->line = sprintf ($ this ->dumpPrefix , $ this ->dumpId , $ this ->indentPad ).$ this ->line ;
465
+ $ this ->line = sprintf (
466
+ $ this ->dumpPrefix ,
467
+ $ this ->dumpId ,
468
+ $ this ->indentPad ,
469
+ $ this ->jsProperties ['collapsedByDefaultNodesHigherThan ' ]
470
+ ) . $ this ->line ;
435
471
}
436
472
if (!$ this ->headerIsDumped ) {
437
473
$ this ->line = $ this ->getDumpHeader ().$ this ->line ;
0 commit comments