Created
November 19, 2010 01:34
-
-
Save max-mapper/706000 to your computer and use it in GitHub Desktop.
experiment in trying to implement @mbostock's bl.ocks.org in pure html + js
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>gist bl.ocks</title> | |
<link rel="stylesheet" type="text/css" href="style.css" /> | |
<script src="http://jquery.com/src/jquery-latest.js"></script> | |
<script src="https://github.com/janl/mustache.js/raw/master/mustache.js"></script> | |
<script> | |
var gist = {}, id = 582915, source; | |
$(function(){ | |
function parseMetadata(data) { | |
gist.owner = ""; | |
if(data.owner) gist.owner = data.owner; | |
gist.description = ""; | |
if(data.description) gist.description = data.description; | |
gist.files = []; | |
if(data.files) gist.files = data.files; | |
gist.time = data.created_at; | |
gist.title = id; | |
if (data.description) { | |
gist.title = data.description + " - " + id; | |
} | |
gist.id = id; | |
gist.html = data.div; | |
} | |
$.ajax({ | |
url: "https://gist.github.com/" + id + ".json", | |
dataType: 'jsonp', | |
success: function(data){ | |
parseMetadata(data); | |
$('body').html(Mustache.to_html($('#bodyTemplate').html(), gist)); | |
source = $($(gist.html).find('.highlight')[1]).text(); | |
$('iframe').contents().find("body").html(source) | |
} | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<script id='bodyTemplate' type='text/mustache'> | |
<div class="body"> | |
<a href="/" class="about right">What’s all this then?</a> | |
<h1>block <a href="http://gist.github.com/{{id}}">#{{id}}</a></h1> | |
<h2> | |
<span class="description">{{title}}</span> | |
by <a href="http://github.com/{{owner}}" class="owner">{{owner}}</a> | |
</h2> | |
<iframe marginwidth="0" marginheight="0" scrolling="no" src="about:blank "></iframe> | |
<div class="readme"> | |
<pre>{{description}}</pre> | |
<p class="time">Created at {{time}}.</p> | |
</div> | |
<a href="/" class="about">about bl.ocks.org</a> | |
</div> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment