Created
December 3, 2014 07:40
-
-
Save 0xv/640759ab91c1740db1f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
TUMBLR FEATURED POSTS SCRIPT | |
Automatically gets all posts tagged with "featured" and lists them | |
REQUIRES JQUERY! | |
-------------------------------------- | |
Created by james <at> bandit.co.nz | |
http://blog.bandit.co.nz | |
Some code borrowed from Jacob DeHart's AJAX Search: | |
http://blog.bandit.co.nz/post/80415548/tumblr-ajax-inline-search | |
*/ | |
Featured = { | |
'apiNum' : 50, // how many posts to read | |
'listId' : '_featured', // the id of the ul to write to | |
'tagName' : '_featured', // the name of the tag we're searching for | |
'linkAppend' : '', // html to append to the end of each linked post | |
'postDB' : [], | |
'listPos' : 0, | |
'doList' : function (where) { | |
var li; var ul = $('#'+where); | |
var titles = {"link":"link-text", "photo":"photo-caption", "quote":"quote-text", "regular":"regular-title", "video":"video-caption"} | |
// cycle through post database | |
pcount = Featured.postDB.length; | |
for(i=Featured.listPos;i<pcount;i++) { | |
p = Featured.postDB[i]; | |
if(p[titles[p.type]] != '') titlestr = p[titles[p.type]].replace(/<\/?[^>]+>/gi, ''); | |
else titlestr = p['url']; | |
li = document.createElement('li'); | |
$(li).append($(p['regular-body']).find('img')[0]) | |
.append('<a class="'+p.type+'" href="'+p["url-with-slug"]+'">'+titlestr+Featured.linkAppend+'</a>'); | |
Featured.listPos = pcount; | |
} | |
}, | |
'getData' : function() { | |
$.get('/api/read/json?num='+Featured.apiNum+'&tagged='+Featured.tagName, | |
function(data) { | |
eval(data); | |
for(i=0;i<tumblr_api_read.posts.length;i++) { | |
Featured.postDB.push(tumblr_api_read.posts[i]); | |
Featured.doList(Featured.listId); | |
} | |
} | |
); | |
} | |
}; | |
$(document).ready(function(){ | |
Featured.getData(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment