Skip to content

Commit

Permalink
Merge pull request #759 from natanfelles/views_hints
Browse files Browse the repository at this point in the history
Add debug views hints
  • Loading branch information
lonnieezell authored Oct 9, 2017
2 parents d04d984 + fe3e8e4 commit 05a7a9e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion application/Controllers/Checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function upload()
<input type="file" name="avatar">
<input type="submit" value="Upload">
</form>
</body>
Expand Down
24 changes: 24 additions & 0 deletions system/Debug/Toolbar/Views/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
color: rgba(0, 0, 0, 0.3);
}

#debug-bar .ci-action,
#debug-bar .ci-label {
border-radius: 0.25em;
text-shadow: none;
Expand All @@ -154,17 +155,21 @@
margin-left: 0.4em;
}

#debug-bar .ci-action:hover,
#debug-bar .ci-label:hover {
background-color: #eaeaea;
cursor: pointer;
}

#debug-bar .ci-action a,
#debug-bar .ci-label a {
display: block;
width: 100%;
color: inherit;
text-decoration: none;
}

#debug-bar .ci-action.active,
#debug-bar .ci-label.active {
background-color: #ccc;
border-color: #bbb;
Expand Down Expand Up @@ -280,3 +285,22 @@
text-align: right;
font-style: italic;
}

.debug-view.show-view {
border: 1px solid #dd4814;
margin: 4px;
}

.debug-view-path {
background-color: #fdc894;
color: #000;
padding: 2px;
font-family: monospace;
font-size: 11px;
min-height: 16px;
text-align: left;
}

.show-view .debug-view-path {
display: block !important;
}
49 changes: 49 additions & 0 deletions system/Debug/Toolbar/Views/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var ciDebugBar = {
ciDebugBar.createListeners();
ciDebugBar.setToolbarState();
ciDebugBar.setToolbarPosition();
ciDebugBar.setViewsHints();
},

//--------------------------------------------------------------------
Expand Down Expand Up @@ -146,6 +147,54 @@ var ciDebugBar = {
ciDebugBar.toolbar.style.display = open == 'open' ? 'inline-block' : 'none';
},

//--------------------------------------------------------------------

setViewsHints: function()
{
var views = document.getElementsByClassName('debug-view');
var btn = document.getElementById('toogle-debug-views');

if (ciDebugBar.readCookie('debug-view'))
{
for (var i = 0; i < views.length; i++)
{
ciDebugBar.addClass(views[i], 'show-view');
ciDebugBar.addClass(btn, 'active');
}
}
else
{
for (var i = 0; i < views.length; i++)
{
ciDebugBar.removeClass(views[i], 'show-view');
}
}

btn.onclick = function() {
// Had AJAX? Reset view blocks
views = document.getElementsByClassName('debug-view');

if (ciDebugBar.readCookie('debug-view'))
{
for (var i = 0; i < views.length; i++)
{
ciDebugBar.removeClass(views[i], 'show-view');
}
ciDebugBar.createCookie('debug-view', '', -1);
ciDebugBar.removeClass(btn, 'active');
}
else
{
for (var i = 0; i < views.length; i++)
{
ciDebugBar.addClass(views[i], 'show-view');
}
ciDebugBar.createCookie('debug-view', 'show', 365);
ciDebugBar.addClass(btn, 'active');
}
};
},

//--------------------------------------------------------------------

setToolbarPosition: function ()
Expand Down
1 change: 1 addition & 0 deletions system/Debug/Toolbar/Views/toolbar.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<?php endif; ?>
<?php endforeach; ?>
<span class="ci-label"><a href="javascript: void(0)" data-tab="ci-vars">Vars</a></span>
<span class="ci-action" id="toogle-debug-views"><a href="javascript: void(0)">Views</a></span>
<span id="toolbar-position"><a href="javascript: void(0)">&#8597;</a></span>
</div>

Expand Down
8 changes: 8 additions & 0 deletions system/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ public function render(string $view, array $options = null, $saveData = null): s
$output = ob_get_contents();
@ob_end_clean();

$after = (new \Config\Filters())->globals['after'];

if (in_array('toolbar', $after) || array_key_exists('toolbar', $after))
{
$output = '<div class="debug-view"><div class="debug-view-path" style="display: none;">' . $file . '</div>'
. $output . '</div>';
}

$this->logPerformance($start, microtime(true), $view);

// Should we cache?
Expand Down

0 comments on commit 05a7a9e

Please sign in to comment.