PrettyPrint Dinamique
pushin the boundaries of pretty print
by dbjdbj
HTML
<button id="btn_paint">Pretty Print</button>
<hr />
<textarea id="display" wrap='off' tabindex="6" class="wide" >
/* comment */
function arr ( a ) {
return (
a = [],
a[0] = a.length
) ;
} ;
function sparse ( a, L ) {
return a[0] ? a[L] = a : ([])[L] = 0 ;
}
sparse ( arr(), 0xFFFF ) ;
</textarea>
CSS
body {height:600px;margin:0; background-color:#C0C0C0;}
#display {width:90%;height:90%; border:2px solid; margin:0; }
JavaScript
try {
//-----------------------------------------------------------------------
var $display = $("#display");
console = {
info : function () { var s,j = 0; while( s = arguments[j++]) $display.append("\n// "+s ); }
} ;
var blanket_maker = function ( call_on_show ) {
var /* element_to_be */_blanketed = $display ,
pritty_pre = "<pre class='prettyprint linenums' style='background-color:white;'></pre>" ,
$blanket = $("<div id='blanket' ></div>"),
$code ;
$blanket.click(function (event) { $blanket.hide("slow");
});
$blanket.css({
'background-color':'#C0C0C0',
'display':'none',
'overflow':'auto',
'border' : '1px solid',
'padding' :'2px',
'position':'absolute',
'top':'0px',
'left':'0px',
'width':'100%',
'height':'100%',
'z-index':'99'
}).html(pritty_pre).appendTo( document.body ) ;
blanket_maker = function (call_on_show) {
$code = $blanket.find(".prettyprint");
$code.removeClass("prettyprinted");
/* ABOVE IS CRUCIAL FOR DYNAMIC WAY OF WORKING !!! */
console.info( "prettyPrint:" + typeof prettyPrint ,
"$code.hasClass('prettyprint'):" + $code.hasClass('prettyprint'),
"$code.hasClass('prettyprinted'):" + $code.hasClass('prettyprinted')
) ;
$blanket.css({
top: _blanketed.position().top,
left: _blanketed.position().left,
width: 1 + _blanketed.width(),
height: _blanketed.height()
});
if ("function" === typeof call_on_show)...