Skip to content

Instantly share code, notes, and snippets.

@orionrush
Forked from jarmo/tumblr-recent-posts.js
Created March 23, 2014 22:30
Show Gist options
  • Select an option

  • Save orionrush/9730839 to your computer and use it in GitHub Desktop.

Select an option

Save orionrush/9730839 to your computer and use it in GitHub Desktop.

Revisions

  1. @jarmo jarmo revised this gist Nov 12, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    It supports also second parameter specifying the posts count (default is 10).
    License:
    Copyright (c) 2010-2012 Jarmo Pertman
    Copyright (c) 2012 Jarmo Pertman
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
  2. @jarmo jarmo revised this gist Nov 12, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -75,7 +75,7 @@ Tumblr.RecentPosts = function(el, postsCount) {

    return {
    render: function() {
    var loadingEl = $("<div>").text("Loading recent posts list...").appendTo($(el));
    var loadingEl = $("<div>").text("Loading...").appendTo($(el));
    $.getJSON(apiUrl, function(data) {
    loadingEl.remove();
    $("<ul class='recent-posts'>").appendTo($(el)).hide().append(renderPosts(data.posts).join("\n")).slideDown('slow');
  3. @jarmo jarmo revised this gist Nov 12, 2012. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    <script type='text/javascript' src='https://raw.github.com/gist/4056588'></script>
    <script type='text/javascript'
    $(function() { new TumblrRecentPosts($("#recent-posts")).render() })
    $(function() { new Tumblr.RecentPosts($("#recent-posts")).render() })
    </script>
    It supports also second parameter specifying the posts count (default is 10).
    @@ -39,7 +39,9 @@
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

    var TumblrRecentPosts = function(el, postsCount) {
    var Tumblr = Tumblr || {};

    Tumblr.RecentPosts = function(el, postsCount) {
    var apiUrl = "http://" + document.domain + "/api/read/json?callback=?&filter=text&num=" + (postsCount || 10);

    var titleTypes = {
  4. @jarmo jarmo revised this gist Nov 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    <div id="recent-posts"></div>
    2) Add code into the <head>:
    <script type='text/javascript' src='https://raw.github.com/gist/4056588#file_tumblr_recent_posts.js'></script>
    <script type='text/javascript' src='https://raw.github.com/gist/4056588'></script>
    <script type='text/javascript'
    $(function() { new TumblrRecentPosts($("#recent-posts")).render() })
  5. @jarmo jarmo revised this gist Nov 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    <div id="recent-posts"></div>
    2) Add code into the <head>:
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/c160b66421f3efbae0f973a9141ddcbc059ea7dc/tumblr-recent-posts.js'></script>
    <script type='text/javascript' src='https://raw.github.com/gist/4056588#file_tumblr_recent_posts.js'></script>
    <script type='text/javascript'
    $(function() { new TumblrRecentPosts($("#recent-posts")).render() })
  6. @jarmo jarmo revised this gist Nov 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    <div id="recent-posts"></div>
    2) Add code into the <head>:
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/5f6c3bf0fc610c5ce4955aca216d248cad1769be/tumblr-recent-posts.js'></script>
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/c160b66421f3efbae0f973a9141ddcbc059ea7dc/tumblr-recent-posts.js'></script>
    <script type='text/javascript'
    $(function() { new TumblrRecentPosts($("#recent-posts")).render() })
  7. @jarmo jarmo revised this gist Nov 11, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,9 @@
    <div id="recent-posts"></div>
    2) Add code into the <head>:
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/5f6c3bf0fc610c5ce4955aca216d248cad1769be/tumblr-recent-posts.js'>
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/5f6c3bf0fc610c5ce4955aca216d248cad1769be/tumblr-recent-posts.js'></script>
    <script type='text/javascript'
    $(function() { new TumblrRecentPosts($("#recent-posts")).render() })
    </script>
  8. @jarmo jarmo revised this gist Nov 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    <div id="recent-posts"></div>
    2) Add code into the <head>:
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/c6702d067bb160447a01cb785e027c3823d3f4b0/tumblr-recent-posts.js'>
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/5f6c3bf0fc610c5ce4955aca216d248cad1769be/tumblr-recent-posts.js'>
    $(function() { new TumblrRecentPosts($("#recent-posts")).render() })
    </script>
  9. @jarmo jarmo revised this gist Nov 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@
    2) Add code into the <head>:
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/c6702d067bb160447a01cb785e027c3823d3f4b0/tumblr-recent-posts.js'>
    $(function() { new Tumblr.RecentPosts($("#recent-posts")).render() })
    $(function() { new TumblrRecentPosts($("#recent-posts")).render() })
    </script>
    It supports also second parameter specifying the posts count (default is 10).
  10. @jarmo jarmo revised this gist Nov 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    <div id="recent-posts"></div>
    2) Add code into the <head>:
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/1f49a01c3f238aadd2cae2f17fda8f1a0f03f4fa/tumblr-recent-posts.js'>
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/c6702d067bb160447a01cb785e027c3823d3f4b0/tumblr-recent-posts.js'>
    $(function() { new Tumblr.RecentPosts($("#recent-posts")).render() })
    </script>
  11. @jarmo jarmo revised this gist Nov 11, 2012. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,9 @@
    <div id="recent-posts"></div>
    2) Add code into the <head>:
    $(function() { new Tumblr.RecentPosts($("#recent-posts")).render() })
    <script type='text/javascript' src='https://raw.github.com/gist/4056588/1f49a01c3f238aadd2cae2f17fda8f1a0f03f4fa/tumblr-recent-posts.js'>
    $(function() { new Tumblr.RecentPosts($("#recent-posts")).render() })
    </script>
    It supports also second parameter specifying the posts count (default is 10).
    @@ -35,7 +37,7 @@
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

    Tumblr.RecentPosts = function(el, postsCount) {
    var TumblrRecentPosts = function(el, postsCount) {
    var apiUrl = "http://" + document.domain + "/api/read/json?callback=?&filter=text&num=" + (postsCount || 10);

    var titleTypes = {
  12. @jarmo jarmo created this gist Nov 11, 2012.
    81 changes: 81 additions & 0 deletions tumblr-recent-posts.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    /*
    This widget shows Recent Posts on your Tumblr blog.
    Its dependency is jQuery.
    Usage:
    1) Add html:
    <div id="recent-posts"></div>
    2) Add code into the <head>:
    $(function() { new Tumblr.RecentPosts($("#recent-posts")).render() })
    It supports also second parameter specifying the posts count (default is 10).
    License:
    Copyright (c) 2010-2012 Jarmo Pertman
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:
    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

    Tumblr.RecentPosts = function(el, postsCount) {
    var apiUrl = "http://" + document.domain + "/api/read/json?callback=?&filter=text&num=" + (postsCount || 10);

    var titleTypes = {
    regular: "regular-title",
    link: "link-text",
    quote: "quote-source",
    photo: "photo-caption",
    conversation: "conversation-title",
    video: "video-caption",
    audio: "audio-caption",
    answer: "question"
    };

    var renderPosts = function(posts) {
    return $.map($.map(posts, postInfo), renderPost);
    };

    var renderPost = function(post) {
    return "<li><a href='" + post.url + "'>" + post.title + "</a></li>";
    };

    var postInfo = function(post) {
    var titleType = titleTypes[post.type];
    if (titleType in post) {
    return {
    title: post[titleType],
    url: post["url-with-slug"]
    };
    }
    };

    return {
    render: function() {
    var loadingEl = $("<div>").text("Loading recent posts list...").appendTo($(el));
    $.getJSON(apiUrl, function(data) {
    loadingEl.remove();
    $("<ul class='recent-posts'>").appendTo($(el)).hide().append(renderPosts(data.posts).join("\n")).slideDown('slow');
    });

    return this;
    }
    }
    };