( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
//EDIT THESE LINES
//Title of the blog
var TITLE = "";
//RSS url
var RSS = "http://www.nation.co.ke/-/1148/1148/-/view/asFeed/-/vtvnjq/-/index.xml";
//Stores entries
var entries = [];
var selectedEntry = "";
//listen for detail links
$(".contentLink").live("click", function() {
selectedEntry = $(this).data("entryid");
});
function renderEntries(entries) {
if(navigator.network.connection.type == Connection.NONE) {
navigator.notification.alert("Sorry, you are not connected to the internet.", function() {}, "Offline!");
}
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");
}
//Listen for Google's library to load
function initialize() {
console.log('ready to use google');
var feed = new google.feeds.Feed(RSS);
feed.setNumEntries(15);
$.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);
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 main page
$("#news").live("pageinit", function() {
//Set the title
google.load("feeds", "1",{callback:initialize});
});
$("#news").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 + '" class="fullLink" data-role="button">Read Entry on Site</a>';
$("#entryText",this).html(contentHTML);
$("#entryText .fullLink",this).button();
});
$(window).on("touchstart", ".fullLink", function(e) {
e.preventDefault();
window.plugins.childBrowser.showWebPage($(this).attr("href"));
});