Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.ajaxSetup({
- error:function(x,e,errorThrown) {
- console.log(x.getStatusCode());
- $("#status").prepend("Error!");
- }
- });
- //EDIT THESE LINES
- //RSS url
- var RSS = "...";
- //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+'">' + '<img src="' + v.ray + ' "/>' + '<div class="navtit">' + v.title + '</div>' + '<div class="small-nav">'+ v.pubDate + '</div>' + '</a></li>';
- });
- $("#linksList").html(s);
- $("#linksList").listview("refresh");
- }
- //Listen for main page
- $("#mainPage").live("pageinit", function() {
- $.ajax({
- url:RSS,
- success:function(res,code) {
- entries = [];
- var xml = $(res);
- var items = xml.find("item");
- $.each(items, function(i, v) {
- entry = {
- title:$(v).find("title").text(),
- link:$(v).find("link").text(),
- pubDate:$(v).find("pubDate").text(),
- ray:$(v).find("thumbandroid").attr("url"),
- description:$.trim($(v).find("description").text()),
- };
- entries.push(entry);
- entries.reverse();
- });
- //store entries
- localStorage["entries"] = JSON.stringify(entries);
- renderEntries(entries);
- },
- error:function(jqXHR,status,error) {
- //try to use cache
- 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.");
- }
- }
- });
- });
- $("#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 += '<div class="bg-txt-gr">';
- contentHTML += '<h3>'+ entries[selectedEntry].title + '</h3>';
- contentHTML += '<img src="' + entries[selectedEntry].ray + ' "/>';
- contentHTML += '</div>';
- contentHTML += '<div class="inh">';
- contentHTML += '<div class="small">' + entries[selectedEntry].pubDate + '</div>';
- contentHTML += entries[selectedEntry].description;
- contentHTML += '</div>';
- $("#entryText",this).html(contentHTML);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement