Created
December 5, 2012 08:37
-
-
Save al3xandr3/4213877 to your computer and use it in GitHub Desktop.
Pretty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add as browser bookmark: | |
// javascript:(function(){var d=document,s=d.createElement('scr'+'ipt'),b=d.body,l=d.location;s.setAttribute('src','https://raw.github.com/gist/4213877/pretty.js');b.appendChild(s)})(); | |
// Loads javascript | |
// note that callback function needs be before calling loadJS(or inline) | |
// loadJS("http://code.jquery.com/jquery-latest.js", function() { $('my_element').hide(); }); | |
var loadJS = function (url, callback) { | |
var head = document.getElementsByTagName("head")[0]; | |
var script = document.createElement("script"); | |
script.src = url; | |
// Attach handlers for all browsers | |
var done = false; | |
script.onload = script.onreadystatechange = function() { | |
if( !done && ( !this.readyState || | |
this.readyState == "loaded" || | |
this.readyState == "complete")) { | |
done = true; | |
// Continue your code | |
callback(); | |
// Handle memory leak in IE | |
script.onload = script.onreadystatechange = null; | |
head.removeChild( script ); | |
} | |
}; | |
head.appendChild(script); | |
} | |
// main function to run after js files are loaded | |
var run = function () { | |
// include pretiffy.css | |
$('head').append('<link rel="stylesheet" href="http://al3xandr3.github.com/css/prettify.css" type="text/css" />'); | |
// find all elements with pre (typically where code is) | |
$('pre').addClass("prettyprint"); | |
// make pretty !! | |
prettyPrint(); | |
} | |
// jquery and take it from there | |
loadJS('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', function () { | |
//when finished loading jquery load prettify.js, then run | |
loadJS('http://al3xandr3.github.com/js/libs/prettify.js', run); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment