Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created May 28, 2010 23:15
Show Gist options
  • Save ryanflorence/417877 to your computer and use it in GitHub Desktop.
Save ryanflorence/417877 to your computer and use it in GitHub Desktop.
Request.Fiddles = new Class({
Extends: Request.JSONP,
options: {
update: document.body,
limit: 5,
item: 'li',
itemHtml:
'<a href="{url}{version}" target="_blank">{title}</a> ' +
'<span>rev{version}</span>' +
'<p>{description}</p>',
callbackKey: 'jsoncallback',
data: {
limit: 10
}
},
initialize: function(user, options){
this.parent(options);
this.options.url = 'http://jsfiddle.net/api/user/' + user + '/demo/list.json';
//this.options.url = 'http://jsfiddle.zalewa.info/api/user/' + user + '/demo/list.json';
this.update = document.id(this.options.update);
this.addEvent('complete', this.listFiddles.bind(this));
},
listFiddles: function(response){
if (response.status === 'ok'){
response.list.each(function(fiddle){
var html = this.options.itemHtml.substitute(fiddle);
new Element(this.options.item,{ html: html}).inject(this.update);
}, this);
}
return this;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment