Skip to content

Instantly share code, notes, and snippets.

@HoundstoothSTL
Created September 23, 2013 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HoundstoothSTL/6674339 to your computer and use it in GitHub Desktop.
Save HoundstoothSTL/6674339 to your computer and use it in GitHub Desktop.
Load Tumblr Posts from Tumblr.js module
//************************ Load Tumblr Posts ****************************
/*
* @requires - ./Tumblr.js
* @url - https://gist.github.com/HoundstoothSTL/
*/
Tumblr.init({
dataType: 'json',
apiKey: 'dSObejFjA8z2gAs4Nv0V9bwwj8oP6TRIF124kaXWFfPVwG6iuY',
limit: '1',
endpoint: 'http://api.tumblr.com/v2/blog/pixelpressgame.tumblr.com/posts/text',
fragment: '?limit=' +this.limit+ '&api_key=' +this.apiKey,
dataUrl: '/blog.json'
});
var loadTemplates = function() {
var post = Tumblr.posts[0],
title = post.title,
body = post.body,
author = post.author,
date = post.date
url = post.url,
twitter = post.twitter;
// load up template elements here
$('[data-template="title"]').text(title);
$('[data-template="body"]').html(body);
$('[data-template="author"]').text(author);
$('[data-template="author"]').attr('href', twitter);
$('[data-template="date"]').text(date);
$('[data-template="url"]').attr('href', url);
};
window.addEventListener('load', function() {
loadTemplates();
});
var Tumblr = {
posts: {
// this will get filled by the ajax response upon success
},
config: {
dataType: 'jsonp',
apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
limit: '1',
endpoint: 'http://api.tumblr.com/v2/blog/pixelpressgame.tumblr.com/posts/text',
fragment: '?limit=' +this.limit+ '&api_key=' +this.apiKey,
dataUrl: this.endpoint + this.fragment
},
ajaxSuccess: function(responseData, textStatus, jqXHR) {
if( typeof this.posts === "object") {
this.posts = responseData;
}
},
ajaxError: function(responseData, textStatus, errorThrown) {
var response = {
data: responseData,
status: textStatus,
err: errorThrown
};
console.log(response);
},
init: function(options) {
if( typeof options === "object" ) {
this.config = options;
}
$.ajax({
type: 'GET',
dataType: this.config.dataType,
url: this.config.dataUrl,
success: function (responseData, textStatus, jqXHR) {
Tumblr.ajaxSuccess( responseData, textStatus, jqXHR );
},
error: function (responseData, textStatus, errorThrown) {
Tumblr.ajaxError( responseData, textStatus, errorThrown );
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment