Aug 25th, 2010 by Brent | No Comments »
Creating a Zooltool feed widget in less than 20 lines of javascript…
So you use Zootool to catalog your design inspiration but it would be cool to place them on your site, right?
Well you’re in luck. Zootool has nice little JSON api which allows you to query your account and pull your feed in JSON (you can do a ton of other things too) and in less than 20 lines of code I can show you how to do it.
This code requires jQuery, mainly because I like how jQuery makes it easy to create elements and iterate through JSON but if you know javascript, you can totally do this without it… and you need to sign up for a developer account on zootool.com.
Once you have a dev account and your apikey, you are ready to go.
Here is the code:
<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<!-- This is where your feed images will go -->
<div class="zooToolList"></div>
<!-- Create JSON request and attach to the top of the document -->
<script>
var script = document.createElement('script');
script.src = 'http://zootool.com/api/users/items/?apikey=yourApiKey& amp;username=yourUserNam&limit=10&callback=zooRsp';
script.type = 'text/javascript';
var head = document.getElementsByTagName('head').item(0);
head.appendChild(script);
<!-- Callback function -->
function zooRsp (data) {
$.each(data, function(item) {
$("<a/>").attr({
href : this.permalink,
target : '_blank'
}).append(
$("<img/>").attr({
src : this.thumbnail,
'class' : 'zooThumb'
})
).appendTo(".zooToolList");
});
}
</script>
just replace yourApiKey with your api key and yourUserName with your username.
Here is a stand alone version that you can copy and paste the code out of…
How it works:
Basically this code appends your API request to the top of your HTML file, which fires the query, and the returned object is a JSON object with all of your data with a callback function attached to it called zooRsp. The zooRsp function takes the JSON object and just loops through it and creates the elements based on the data and plunks them in the zooToolList div…
all you have to do is style up the resulting links and images to your liking and you are done…









