Guest User

Untitled

a guest
Jun 12th, 2012
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. $.ajaxSetup({
  3. error:function(x,e,errorThrown) {
  4. console.log(x.getStatusCode());
  5. $("#status").prepend("Error!");
  6. }
  7. });
  8.  
  9. //EDIT THESE LINES
  10.  
  11. //RSS url
  12. var RSS = "...";
  13.  
  14.  
  15. //Stores entries
  16. var entries = [];
  17. var selectedEntry = "";
  18.  
  19. //listen for detail links
  20. $(".contentLink").live("click", function() {
  21. selectedEntry = $(this).data("entryid");
  22. });
  23.  
  24. function renderEntries(entries) {
  25.  
  26. var s = '';
  27. $.each(entries, function(i, v) {
  28. 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>';
  29. });
  30. $("#linksList").html(s);
  31. $("#linksList").listview("refresh");
  32.  
  33. }
  34.  
  35. //Listen for main page
  36. $("#mainPage").live("pageinit", function() {
  37.  
  38. $.ajax({
  39. url:RSS,
  40. success:function(res,code) {
  41. entries = [];
  42. var xml = $(res);
  43. var items = xml.find("item");
  44. $.each(items, function(i, v) {
  45. entry = {
  46. title:$(v).find("title").text(),
  47. link:$(v).find("link").text(),
  48. pubDate:$(v).find("pubDate").text(),
  49. ray:$(v).find("thumbandroid").attr("url"),
  50. description:$.trim($(v).find("description").text()),
  51. };
  52. entries.push(entry);
  53. entries.reverse();
  54. });
  55.  
  56. //store entries
  57. localStorage["entries"] = JSON.stringify(entries);
  58. renderEntries(entries);
  59. },
  60.  
  61. error:function(jqXHR,status,error) {
  62. //try to use cache
  63. if(localStorage["entries"]) {
  64. $("#status").html("Using cached version...");
  65. entries = JSON.parse(localStorage["entries"])
  66. renderEntries(entries);
  67. } else {
  68. $("#status").html("Sorry, we are unable to get the RSS and there is no cache.");
  69. }
  70. }
  71. });
  72.  
  73.  
  74. });
  75.  
  76. $("#mainPage").live("pagebeforeshow", function(event,data) {
  77. if(data.prevPage.length) {
  78. $("h1", data.prevPage).text("");
  79. $("#entryText", data.prevPage).html("");
  80. };
  81. });
  82.  
  83. //Listen for the content page to load
  84. $("#contentPage").live("pageshow", function(prepage) {
  85. //Set the title
  86. $("h1", this).text(entries[selectedEntry].title);
  87. var contentHTML = "";
  88. contentHTML += '<div class="bg-txt-gr">';
  89. contentHTML += '<h3>'+ entries[selectedEntry].title + '</h3>';
  90. contentHTML += '<img src="' + entries[selectedEntry].ray + ' "/>';
  91. contentHTML += '</div>';
  92. contentHTML += '<div class="inh">';
  93. contentHTML += '<div class="small">' + entries[selectedEntry].pubDate + '</div>';
  94. contentHTML += entries[selectedEntry].description;
  95. contentHTML += '</div>';
  96. $("#entryText",this).html(contentHTML);
  97. });
RAW Paste Data