Guest User

main.js

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