forked from matthewbuchanan/tumblr-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.tumblr-kit.min.js
1 lines (1 loc) · 1.73 KB
/
jquery.tumblr-kit.min.js
1
(function(e,t,n){e.fn.getTumblrPosts=function(t){e.views.helpers({getHostname:function(){return TUMBLR_HOSTNAME},getTintedAudioPlayer:function(e,t){var n=e.data.player;if(t!=null){var r=/color=FFFFFF/g;t=t.split("#")[1];return n.replace(r,"color="+t)}else{return n}},getPhotoURL:function(e,t){var n=e.data.alt_sizes,r="";for(var i=0;i<n.length;i++){if(n[i].width>=t)r=n[i].url;else break}return r===""?n[0].url:r},getPhotoOrientation:function(e){var t=e.data.original_size;if(t.width>t.height){return"landscape"}else if(t.width<t.height){return"portrait"}else{return"square"}},getVideoEmbed:function(e,t){var n=e.data.player,r="";for(var i=0;i<n.length;i++){if(n[i].width<=t)r=n[i].embed_code;else break}return r===""?n[0].embed_code:r}});var n=e.extend({hostname:TUMBLR_HOSTNAME,id:null,type:"",tag:"",limit:20,offset:0,format:"",template:"",before:null,done:null,always:null},t);var r=this;return this.each(function(){if(n.type!="")n.type="/"+n.type;var t="http://api.tumblr.com/v2/blog/"+n.hostname+"/posts"+n.type+"?api_key="+TUMBLR_API_KEY,i="";if(n.id){t+="&id="+parseInt(n.id)}else{if(n.tag)t+="&tag="+encodeURI(n.tag);if(n.limit)t+="&limit="+parseInt(n.limit);i=t;if(n.offset)t+="&offset="+parseInt(n.offset)}var s=e.ajax({url:t,dataType:"jsonp",jsonp:"jsonp",ifModified:true,beforeSend:function(){if(typeof n.before==="function")n.before.call(r)}}).done(function(t,s,o){if(typeof t!=="undefined"&&typeof t.response!=="undefined">t.response.total_posts>0){e.each(t.response.posts,function(){var t=n.template!=""?n.template:"#tmpl-"+this.type;r.append(e(t).render(this))})}if(typeof n.done==="function")n.done.call(r,t,s,o,i)}).always(function(e,t){r.find(".tumblr-api-loading").hide();if(typeof n.always==="function")n.always.call(r,e,t,i)})})}})(jQuery,window)