Skip to content

Instantly share code, notes, and snippets.

@nautat
Forked from johan/index.html
Created June 14, 2012 14:34
Show Gist options
  • Save nautat/2930724 to your computer and use it in GitHub Desktop.
Save nautat/2930724 to your computer and use it in GitHub Desktop.
Bl.ocks.org index by user
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Index of all bl.ocks.org pages owned by a github user</title>
<script type="text/javascript" src="http://d3js.org/d3.v2.js"></script>
<base target="_top">
<style>
body { padding: 0.5em; margin: 0; }
h1 { padding: 0; margin: 0; }
#list { padding: 0; margin: 1em 0 0; }
a[href] { color: steelblue; background: none; text-decoration: none; }
a[href]:hover { text-decoration: underline; }
a[href]:visited { color: #63419A; }
.created_at:after { content: " "; }
.info:before { content: ": "; }
.what,
body.help .list { display: none; }
body.help .what { display: block; }
</style>
</head>
<body>
<div class="list">
<h1>All bl.ocks by <a target="_blank" id="user">#...</a>:</h1>
<ul id="list"></ul>
</div>
<div class="what">
<h1>This page lists bl.ocks.org pages per github user</h1>
<p>
To see all gists that can be seen at
<a href="http://bl.ocks.org/">bl.ocks.org</a> by some github user
(i e: those of their gists which have an <code>index.html</code> file)
just put their name at the end of this URL, prefixed with a "#".
Examples:
</p>
<ul>
<li>#<a href="http://bl.ocks.org/2930724#mbostock">mbostock</a></li>
<li>#<a href="http://bl.ocks.org/2930724#johan">johan</a></li>
</ul>
</div>
<script src='jsonp.js'></script>
<script src='index.js'></script>
</body>
</html>
var owner = '' // fetched from url hash
, gists = [] // all gists
, blocks = [] // gists with an index.html file
;
top.onhashchange = init;
init();
function init() {
owner = (top.location.hash || '#').slice(1) ||
(top.document.querySelector('a.owner') && top.document.querySelector('a.owner').textContent);
var hash = '#'+ owner;
if ((document.body.className = owner ? '' : 'help'))
return;
if (top.location.hash != hash)
top.location.hash = hash;
d3.select('#user')
.attr('href', 'https://gist.github.com/'+ owner)
.text(owner);
JSONP('https://api.github.com/users/'+ owner + '/gists?per_page=5000', show);
}
function is_block(gist) {
return -1 !== d3.keys(gist.files).indexOf('index.html');
}
function show(json) {
gists = json.data;
var vis = d3.select('ul#list').selectAll('li')
.data(blocks = gists.filter(is_block))
, lis = vis.enter().append('li')
, out = vis.exit().remove();
lis.append('span')
.attr('class', 'created_at')
.text(function(d) { return d.created_at; });
lis.append('a')
.attr('target', function(d) { return 'bl_ock_'+ d.id; })
.attr('href', function(d) { return 'http://bl.ocks.org/'+ d.id; })
.attr('class', 'block')
.classed('private', function(d) { return !d.public; })
.text(function(d) { return d.id; });
lis.append('span')
.classed('info', function(d) { return !!d.description; })
.text(function(d) { return d.description || ''; });
if (!blocks.length) document.body.className = 'help';
d3.select(self.frameElement).style('height', document.body.offsetHeight +'px');
}
// calls `cb` with the data from `url`, which either ends with a "=" (for the callback),
// or handles the standard "&callback=" query parameter, as well-organized JSON APIs do.
function JSONP(url, cb) {
var nth = JSONP.nth = (JSONP.nth || 0) + 1
, name = 'cb' + nth.toString(36)
, tail = /=$/.test(url) ? '' : (/\?/.test(url) ? '&' : '?') + 'callback='
, head = document.getElementsByTagName('head')[0]
, load = document.createElement('script');
JSONP[name] = function(json) {
delete JSONP[name];
head.removeChild(load);
cb(json);
};
load.src = url + tail + 'JSONP.'+ name;
head.appendChild(load);
}
@johan
Copy link

johan commented Jun 14, 2012

Thanks for this; good work! :-D I appreciated it a lot, even though Mike finally merged Jason's pull request to make http://bl.ocks.org/mbostock work too.

@nautat
Copy link
Author

nautat commented Jun 14, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment