Skip to content

Instantly share code, notes, and snippets.

@julzhk
Last active August 29, 2015 14:05
Show Gist options
  • Save julzhk/0376e2cfd96f4d02b7a8 to your computer and use it in GitHub Desktop.
Save julzhk/0376e2cfd96f4d02b7a8 to your computer and use it in GitHub Desktop.
object of the day demo
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="http://www.vam.ac.uk/_designs/new-squiz/css/main.css" media="all">
<script type='text/javascript' src='http://code.jquery.com/jquery-2.1.1.min.js'></script>
<script type='text/javascript' src='recent_tumblr.js'></script>
<style>
</style>
</head>
<body>
<h1>
</h1>
<div id="recent-posts"></div>
</body>
<script type='text/javascript'>
$(function() { new Tumblr.RecentPosts($("#recent-posts")).render() })
</script>
</html>
/*
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>:
<script type='text/javascript' src='https://raw.github.com/gist/4056588'></script>
<script type='text/javascript'
$(function() { new Tumblr.RecentPosts($("#recent-posts")).render() })
</script>
It supports also second parameter specifying the posts count (default is 10).
License:
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
"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.
*/
var tumblrfeed = 'thevamuseum';
var Tumblr = Tumblr || {};
var postsCount = 1;
var apiUrl = "http://"+tumblrfeed+".tumblr.com/api/read/json?callback=?&filter=text&num=" + (postsCount || 10);
Tumblr.RecentPosts = function(el, postsCount) {
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 "<div>" +
"<a class='link' href='" + post.url + "' target='_blank'>" +
"<img class='ood_img' src='"+ post.photourl + "'>" +
"<span class='caption'"+ post.photocaption + "</span></a>" +
"</div>"
};
var postInfo = function(post) {
var titleType = titleTypes[post.type];
if (titleType in post) {
console.log(post);
return {
title: post[titleType],
photocaption: post["photo-caption"],
photourl: post["photo-url-250"],
url: post["url-with-slug"]
};
}
};
return {
render: function() {
var loadingEl = $("<div>").text("Loading...").appendTo($(el));
$.getJSON(apiUrl, function(data) {
loadingEl.remove();
$("<div class='recent-posts'>").appendTo($(el)).hide().append(
renderPosts(data.posts).join("\n")).slideDown('slow');
});
return this;
}
}
};
@julzhk
Copy link
Author

julzhk commented Aug 11, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment