Created
September 23, 2013 17:50
-
-
Save HoundstoothSTL/6674339 to your computer and use it in GitHub Desktop.
Load Tumblr Posts from Tumblr.js module
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
//************************ 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(); | |
}); |
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
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