Skip to content

Instantly share code, notes, and snippets.

@dgmike
Created April 20, 2010 19:19
Show Gist options
  • Save dgmike/372926 to your computer and use it in GitHub Desktop.
Save dgmike/372926 to your computer and use it in GitHub Desktop.
Debugs an simple array/object on html
.debug {
background: #EEE;
border-bottom:1px solid #DDD;
margin: 0 1em;
cursor:pointer;
}
.debug .title {
background:#AAA;
color:#FFF;
font-weight:bold;
padding-left:.5em;
}
.debug pre {
margin: .5em;
font-size:1em;
}
.debug pre ol {
margin-left: 2.5em;
}
.debug pre ol li {
font-family:Monaco;
font-size:.85em;
background:#FFF;
cursor:auto;
}
.debug pre ol li.odd {
background:#F5F5FF;
}
;(function($){
$.fn.preIt = function() {
$(this).find('pre').each(function(){
var text = $(this).html().split('\n');
var new_text = ''
$.each(text, function(){
new_text = new_text + '<li>' + this + '</li>'
})
$(this).html('<ol class="lines">'+new_text+'</ol>')
$(this).find('.lines li:odd').addClass('odd')
}).hide()
$(this).find('.title').click(function(){
$(this).parent().find('pre').toggle()
})
}
})(jQuery);
jQuery(function(){
$('.debug').preIt();
})
<?php
if (isset($_GET['debbug'])) {
print "<div class='debug'><div class='title'>Easy title for my debug var</div><pre>"; print_r($my_var); print "</pre></div>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment