Last active
September 1, 2015 05:28
-
-
Save nesvand/0520ad3082af3d326a0a to your computer and use it in GitHub Desktop.
A Natural Healing for Animals (Blogger Feed)
This file contains 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
<script type='text/javascript' src='http://www.jsviews.com/download/jsrender.min.js'></script> | |
<script id="blogSuccessTemplate" type="text/x-jsrender"> | |
<div class="col-sm-12" id="blog{{:#index}}"> | |
<h2><a href="{{:url}}" target="_blank">{{:title}} <span class="small">{{:date}}</span></a></h2> | |
{{:content}} | |
<div class="small"><a href="{{:url}}" target="_blank">Comment/Share</a></div> | |
</div> | |
</script> | |
<script id="blogFailTemplate" type="text/x-jsrender"> | |
<div class="col-sm-12"> | |
<h3 class="text-center">Blog Currently Unavailable</h3> | |
</div> | |
</script> | |
<div class="row" id="blogContent"> | |
</div> |
This file contains 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
// Returns a long month string based on an Int input of range 0-11 (received from a Date.getMonth() return) | |
function numToMonth(num) { | |
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; | |
return months[num]; | |
} | |
//A Natural Healing For Animals - Blogger v3 Blog Feed Generator | |
var anhfa_blog_api_string = 'https://www.googleapis.com/blogger/v3/blogs/2771946433309956973/posts?key={redacted}}'; //GET string using the format: https://www.googleapis.com/blogger/v3/blogs/<blog id number>/posts?key=<API key> | |
if ($('#topic-of-the-week').length) { | |
var anhfa_blog_jqHXR = $.getJSON(anhfa_blog_api_string) | |
.done(function(anhfa_blog_JSON) { | |
var blogData = []; | |
var len = (anhfa_blog_JSON.items) ? anhfa_blog_JSON.items.length : 0; | |
var i; | |
for (i = 0; i < len; i++) { | |
var published_date = new Date(Date.parse(anhfa_blog_JSON.items[i].published)); //Parse the JSON string (v3 uses ECMAScript 5 ISO-8601 format) to Date prototype | |
blogData.push({ | |
date: 'Posted on ' + published_date.getDate() + ' ' + numToMonth(published_date.getMonth()) + ' ' + published_date.getFullYear(), | |
title: anhfa_blog_JSON.items[i].title, | |
content: anhfa_blog_JSON.items[i].content, | |
url: anhfa_blog_JSON.items[i].url | |
}); | |
} | |
(len) ? $("#blogContent").html($("#blogSuccessTemplate").render(blogData)) : $("#blogContent").html($("#blogFailTemplate").render()); | |
// A mild amount of cleanup (to remove some of the cruft Blogger leaves behind) | |
for (i = 0; i < len; i++) { | |
$('#blog' + i + '-content div').remove(); | |
} | |
// Animate window to content | |
if (window.location.hash) { | |
var hash = window.location.hash.replace('#', ''); | |
console.log(hash); | |
$("html, body").delay(500).animate({ | |
scrollTop: $('#' + hash).offset().top - 45 | |
}, 1000); | |
} | |
}) //End .done | |
//Fallback content to be displayed in case the blog is offline; not responding; or over the limit of daily requests | |
.fail(function() { | |
$("#blogContent").html($("#blogFailTemplate").render()); | |
}); //End .fail and $.getJSON(anhfa_blog_api_string) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment