Skip to content

Instantly share code, notes, and snippets.

@reaktivo
Created December 26, 2009 05:51
Show Gist options
  • Save reaktivo/263848 to your computer and use it in GitHub Desktop.
Save reaktivo/263848 to your computer and use it in GitHub Desktop.
var GistRequest = {
fxScroll: new Fx.Scroll(document.body, {offset: {y: -20}}),
proxy: 'proxy.php',
init: function() {
this.lookForGists();
},
lookForGists: function() {
var gists = $$('a').filter(this.filterGists);
gists.each(this.addGistAction.bind(this));
},
addGistAction: function(item, i, arr) {
item.addEvent('click', this.gistClick.bindWithEvent(this, item));
if(item.get('rel') == 'auto') this.gistClick(null, item, true);
},
filterGists: function(item, i, arr) {
return item.get('href').test(/^https?:\/\/gist/);
},
gistClick: function(e, item) {
if(e) e.stop();
var wrapper = item.retrieve('wrapper');
if(wrapper) {
this.fxScroll.toElement(item);
wrapper.slide('toggle');
}else{
wrapper = new Element('div');
item.store('wrapper', wrapper);
wrapper.inject(item.getParent(), 'after');
wrapper.slide('hide');
var request = new Request.HTML({
url: this.proxy,
update: wrapper,
onComplete: this.gistClick.bind(this, [null, item])
});
request.get({url: item.get('href') + '.pibb'});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment