Skip to content
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

Delay panel rendering #160

Merged
merged 1 commit into from May 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Tracy/Debugger.php
Expand Up @@ -550,7 +550,7 @@ public static function barDump($var, $title = NULL, array $options = NULL)
if (!self::$productionMode) {
static $panel;
if (!$panel) {
self::getBar()->addPanel($panel = new DefaultBarPanel('dumps'));
self::getBar()->addPanel($panel = new DefaultBarPanel('dumps'), 'Tracy:dumps');
}
$panel->data[] = ['title' => $title, 'dump' => Dumper::toHtml($var, (array) $options + [
Dumper::DEPTH => self::$maxDepth,
Expand Down
17 changes: 13 additions & 4 deletions src/Tracy/assets/Bar/bar.js
Expand Up @@ -22,6 +22,10 @@
Panel.prototype.init = function() {
var _this = this, elem = this.elem;

elem.innerHTML = elem.dataset.tracyContent;
delete elem.dataset.tracyContent;
evalScripts(elem);

draggable(elem, {
handle: elem.querySelector('h1'),
stop: function() {
Expand Down Expand Up @@ -70,7 +74,6 @@
if (!this.is('tracy-ajax')) {
Tracy.Toggle.persist(elem);
}
this.restorePosition();
};

Panel.prototype.is = function(mode) {
Expand Down Expand Up @@ -189,8 +192,10 @@
if (!pos) {
this.elem.classList.add(Panel.PEEK);
} else if (pos.window) {
this.init();
this.toWindow();
} else if (this.elem.querySelector('*')) {
} else if (this.elem.dataset.tracyContent) {
this.init();
this.toFloat();
setPosition(this.elem, pos);
}
Expand Down Expand Up @@ -246,6 +251,10 @@
var panel = Debug.panels[this.rel], link = this;
panel.focus(function() {
if (panel.is(Panel.PEEK)) {
if (panel.elem.dataset.tracyContent) {
panel.init();
}

var pos = getPosition(panel.elem);
setPosition(panel.elem, {
right: pos.right - getOffset(link).left + pos.width - getPosition(link).width - 4 + getOffset(panel.elem).left,
Expand Down Expand Up @@ -301,7 +310,7 @@

forEach(document.querySelectorAll('.tracy-panel'), function(panel) {
Debug.panels[panel.id] = new Panel(panel.id);
Debug.panels[panel.id].init();
Debug.panels[panel.id].restorePosition();
});

Debug.captureWindow();
Expand All @@ -328,7 +337,7 @@
forEach(document.querySelectorAll('.tracy-panel'), function(panel) {
if (!Debug.panels[panel.id]) {
Debug.panels[panel.id] = new Panel(panel.id);
Debug.panels[panel.id].init();
Debug.panels[panel.id].restorePosition();
}
});

Expand Down
19 changes: 10 additions & 9 deletions src/Tracy/assets/Bar/panels.phtml
Expand Up @@ -12,18 +12,19 @@
namespace Tracy;

use Tracy;
use Tracy\Helpers;

$icons = <<<'HTML'
<div class="tracy-icons">
<a href="#" title="open in window">&curren;</a>
<a href="#" rel="close" title="close window">&times;</a>
</div>
HTML;

foreach ($rows as $row) {
foreach ($row->panels as $panel) {
?>
<div class="tracy-panel <?= $row->type === 'ajax' ? 'tracy-ajax' : '' ?>" id="tracy-debug-panel-<?= $panel->id ?>">
<?php if ($panel->panel): echo $panel->panel ?>
<div class="tracy-icons">
<a href="#" title="open in window">&curren;</a>
<a href="#" rel="close" title="close window">&times;</a>
</div>
<?php endif ?>
</div><?php
$content = $panel->panel ? ($panel->panel . "\n" . $icons) : '';
$class = 'tracy-panel ' . ($row->type === 'ajax' ? 'tracy-ajax' : ''); ?>
<div class="<?= $class ?>" id="tracy-debug-panel-<?= $panel->id ?>" data-tracy-content="<?= Helpers::escapeHtml($content) ?>"></div><?php
}
}
17 changes: 13 additions & 4 deletions tests/Tracy/Debugger.barDump().expect
@@ -1,7 +1,11 @@
%A%<h1>Dumps</h1>
<style class="tracy-debug">
%A%
</style>

<h1>Dumps</h1>

<div class="tracy-inner tracy-DumpPanel">

<pre class="tracy-dump" title="barDump($arr)
in file %a% on line %d%" data-tracy-href="editor:%a%"><span class="tracy-toggle"><span class="tracy-dump-array">array</span> (8)</span>
<div><span class="tracy-dump-indent"> </span><span class="tracy-dump-key">0</span> => <span class="tracy-dump-number">10</span>
Expand All @@ -18,8 +22,13 @@ in file %a% on line %d%" data-tracy-href="editor:%a%"><span class="tracy-toggle"
<span class="tracy-dump-indent"> | </span><span class="tracy-dump-key">key2</span> => <span class="tracy-dump-bool">TRUE</span>
</div></div></pre>
<h2>String</h2>

<pre class="tracy-dump" title="barDump(&#039;&lt;a href=&quot;#&quot;&gt;test&lt;/a&gt;&#039;, &#039;String&#039;)
in file %a% on line %d%" data-tracy-href="editor:%a%"><span class="tracy-dump-string">"&lt;a href=&quot;#&quot;&gt;test&lt;/a&gt;"</span> (20)
</pre>
</div>%A%
</div>

<div class="tracy-icons">
<a href="#" title="open in window">&curren;</a>
<a href="#" rel="close" title="close window">&times;</a>
</div>
8 changes: 5 additions & 3 deletions tests/Tracy/Debugger.barDump().phpt
Expand Up @@ -5,8 +5,9 @@
* @outputMatch OK!
*/

use Tracy\Debugger;
use Tester\Assert;
use Tester\DomQuery;
use Tracy\Debugger;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -26,8 +27,9 @@ Debugger::enable();

register_shutdown_function(function () {
ob_end_clean();
$content = reset($_SESSION['_tracy']['bar'])['content'];
Assert::matchFile(__DIR__ . '/Debugger.barDump().expect', $content);
$rawContent = reset($_SESSION['_tracy']['bar'])['content'];
$panelContent = (string) DomQuery::fromHtml($rawContent)->find('#tracy-debug-panel-Tracy-dumps')[0]['data-tracy-content'];
Assert::matchFile(__DIR__ . '/Debugger.barDump().expect', $panelContent);
echo 'OK!'; // prevents PHP bug #62725
});

Expand Down
8 changes: 5 additions & 3 deletions tests/Tracy/Debugger.barDump().showLocation.phpt
Expand Up @@ -5,8 +5,9 @@
* @outputMatch OK!
*/

use Tracy\Debugger;
use Tester\Assert;
use Tester\DomQuery;
use Tracy\Debugger;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -27,7 +28,8 @@ Debugger::enable();

register_shutdown_function(function () {
ob_end_clean();
$content = reset($_SESSION['_tracy']['bar'])['content'];
$rawContent = reset($_SESSION['_tracy']['bar'])['content'];
$panelContent = (string) DomQuery::fromHtml($rawContent)->find('#tracy-debug-panel-Tracy-dumps')[0]['data-tracy-content'];
Assert::match(<<<EOD
%A%<h1>Dumps</h1>

Expand All @@ -39,7 +41,7 @@ in file %a% on line %d%" data-tracy-href="editor:%a%"><span class="tracy-dump-st
</div>
%A%
EOD
, $content);
, $panelContent);
echo 'OK!'; // prevents PHP bug #62725
});

Expand Down
8 changes: 5 additions & 3 deletions tests/Tracy/Debugger.warnings.html.phpt
Expand Up @@ -5,8 +5,9 @@
* @outputMatch OK!
*/

use Tracy\Debugger;
use Tester\Assert;
use Tester\DomQuery;
use Tracy\Debugger;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -29,7 +30,8 @@ register_shutdown_function(function () {
Assert::match('
Warning: Unsupported declare \'foo\' in %a% on line %d%%A%', $output);

$content = reset($_SESSION['_tracy']['bar'])['content'];
$rawContent = reset($_SESSION['_tracy']['bar'])['content'];
$panelContent = (string) DomQuery::fromHtml($rawContent)->find('#tracy-debug-panel-Tracy-errors')[0]['data-tracy-content'];
Assert::match('%A%<table>
<tr>
<td class="tracy-right">1%a%</td>
Expand All @@ -48,7 +50,7 @@ Warning: Unsupported declare \'foo\' in %a% on line %d%%A%', $output);
<td><pre>PHP Warning: %a% in %a%:%d%</a></pre></td>
</tr>
</table>
</div>%A%', $content);
</div>%A%', $panelContent);
echo 'OK!'; // prevents PHP bug #62725
});

Expand Down