Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created November 19, 2010 01:34
Show Gist options
  • Save max-mapper/706000 to your computer and use it in GitHub Desktop.
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
<!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&rsquo;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