Skip to content

Instantly share code, notes, and snippets.

@HoundstoothSTL
Created September 23, 2013 17:50
Show Gist options
  • Save HoundstoothSTL/6674339 to your computer and use it in GitHub Desktop.
Save HoundstoothSTL/6674339 to your computer and use it in GitHub Desktop.

Revisions

  1. HoundstoothSTL created this gist Sep 23, 2013.
    47 changes: 47 additions & 0 deletions Tumblr.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    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 );
    }
    });
    }
    };
    35 changes: 35 additions & 0 deletions loader.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    //************************ 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();
    });