Created
August 4, 2012 12:25
-
-
Save cfjedimaster/3257160 to your computer and use it in GitHub Desktop.
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
//EDIT THESE LINES | |
//Title of the blog | |
var TITLE = "Raymond Camden's Blog"; | |
//RSS url | |
var RSS = "http://feedproxy.google.com/RaymondCamdensColdfusionBlog"; | |
//Stores entries | |
var entries = []; | |
var selectedEntry = ""; | |
//listen for detail links | |
$(".contentLink").live("click", function() { | |
selectedEntry = $(this).data("entryid"); | |
}); | |
function renderEntries(entries) { | |
var s = ''; | |
$.each(entries, function(i, v) { | |
s += '<li><a href="#contentPage" class="contentLink" data-entryid="'+i+'">' + v.title + '</a></li>'; | |
}); | |
$("#linksList").html(s); | |
$("#linksList").listview("refresh"); | |
} | |
function checkCacheFalBack() { | |
if(localStorage["entries"]) { | |
$("#status").html("Using cached version..."); | |
entries = JSON.parse(localStorage["entries"]); | |
renderEntries(entries); | |
} else { | |
$("#status").html("Sorry, we are unable to get the RSS and there is no cache."); | |
} | |
} | |
//Listen for Google's library to load | |
function initialize() { | |
console.log('ready to use google'); | |
var feed = new google.feeds.Feed(RSS); | |
feed.setNumEntries(10); | |
$.mobile.showPageLoadingMsg(); | |
feed.load(function(result) { | |
$.mobile.hidePageLoadingMsg(); | |
if(!result.error) { | |
entries = result.feed.entries; | |
localStorage["entries"] = JSON.stringify(entries); | |
renderEntries(entries); | |
} else { | |
console.log("Error - "+result.error.message); | |
checkCacheFalBack(); | |
} | |
}); | |
} | |
//Listen for main page | |
$("#mainPage").live("pageinit", function() { | |
//Set the title | |
$("h1", this).text(TITLE); | |
try { | |
google.load("feeds", "1",{callback:initialize}); | |
} catch(e) { | |
console.log('Error - try to hit local cache'); | |
checkCacheFalBack(); | |
} | |
}); | |
$("#mainPage").live("pagebeforeshow", function(event,data) { | |
if(data.prevPage.length) { | |
$("h1", data.prevPage).text(""); | |
$("#entryText", data.prevPage).html(""); | |
}; | |
}); | |
//Listen for the content page to load | |
$("#contentPage").live("pageshow", function(prepage) { | |
//Set the title | |
$("h1", this).text(entries[selectedEntry].title); | |
var contentHTML = ""; | |
contentHTML += entries[selectedEntry].content; | |
contentHTML += '<p/><a href="'+entries[selectedEntry].link + '">Read Entry on Site</a>'; | |
$("#entryText",this).html(contentHTML); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment