/*
---
script: Request.Fiddles.js
description: displays user's fiddles using jsFiddle API, http://jsfiddle.tumblr.com/api-doc
license: MIT style license
authors:
Ryan Florence (http://ryanflorence.com)
Piotr Zalewa (http://webdev.zalewa.info)
requires:
core:1.2.4:
- Request.JSONP
provides: [Request.Fiddles]
...
*/
Request.Fiddles = new Class({
Extends: Request.JSONP,
options: {
update: document.body,
item: 'li',
itemHtml:
'<a href="{url}{version}" target="_blank">{title}</a> ' +
'<p>{description}</p>',
callbackKey: 'jsoncallback',
website: 'http://jsfiddle.net',
data: {
// if not specified the ones specified in API doc will be used
}
},
// I had to modify the callback-function for retrieving all my fiddles
initialize: function(user, options){
this.parent(options);
this.options.url = this.options.website + '/api/user/' + user + '/demo/list.json?callback=start=0&limit=5000';
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;
}
});
// Example ------------------------------
window.addEvent('domready', function() {
var request = new Request.Fiddles('Flocke',{
update: 'fiddle-list'
}).send();
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.