Advertisement
bpmitchell

coasterfusionnewsrss

Apr 11th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. //EDIT THESE LINES
  2. //Title of the blog
  3. var TITLE = "";
  4. //RSS url
  5. var RSS = "http://feeds.feedburner.com/CoasterfusionNews";
  6. //Stores entries
  7. var entries = [];
  8. var selectedEntry = "";
  9.  
  10. //listen for detail links
  11. $(".contentLink").live("click", function() {
  12. selectedEntry = $(this).data("entryid");
  13. });
  14.  
  15. function renderEntries(entries) {
  16. var s = '';
  17. $.each(entries, function(i, v) {
  18. s += '<li><a href="#contentPage" class="contentLink" data-entryid="'+i+'">' + '<div class="navtit"><h2>' + v.title + '</h2></div>' + '<div class="small">'+ v.pubDate + '</div>' + '</a></li>'
  19. ;});
  20. $("#linksList").html(s);
  21. $("#linksList").listview("refresh");
  22. }
  23.  
  24. //Listen for main page
  25. $("#mainPage").live("pageinit", function() {
  26. //Set the title
  27. $("h1", this).text(TITLE);
  28. $.ajax({
  29. url:RSS,
  30. success:function(res,code) {
  31. entries = [];
  32. var xml = $(res);
  33. var items = xml.find("item");
  34. $.each(items, function(i, v) {
  35.  
  36. var ray = $(v).find("media:thumbnail");
  37. console.log(ray);
  38.  
  39. entry = {
  40. title:$(v).find("title").text(),
  41. link:$(v).find("link").text(),
  42. pubDate:$(v).find("pubDate").text(),
  43. ray:$(v).find("media:thumbnail").text(),
  44. description:$.trim($(v).find("description").text())
  45.  
  46. };
  47.  
  48. entries.push(entry);
  49.  
  50. });
  51. //store entries
  52. localStorage["entries"] = JSON.stringify(entries);
  53. renderEntries(entries);
  54.  
  55. },
  56. error:function(jqXHR,status,error) {
  57. //try to use cache
  58. if(localStorage["entries"]) {
  59. $("#status").html("Using cached version...");
  60. entries = JSON.parse(localStorage["entries"])
  61. renderEntries(entries);
  62. } else {
  63. $("#status").html("Sorry, we are unable to get the RSS and there is no cache.");
  64. }
  65. }
  66. });
  67.  
  68. });
  69.  
  70. $("#mainPage").live("pagebeforeshow", function(event,data) {
  71. if(data.prevPage.length) {
  72. $("h1", data.prevPage).text("");
  73. $("#entryText", data.prevPage).html("");
  74. };
  75. });
  76.  
  77. //Listen for the content page to load
  78. $("#contentPage").live("pageshow", function(prepage) {
  79. //Set the title
  80. var contentHTML = "";
  81. contentHTML += '<h3>'+ entries[selectedEntry].title + '</h3>';
  82. contentHTML += '<h4>' + entries[selectedEntry].pubDate + '</h4>';
  83. contentHTML += entries[selectedEntry].description;
  84. $("#entryText",this).html(contentHTML);
  85. });
  86.  
  87. $(window).on("touchstart", ".fullLink", function(e) {
  88. e.preventDefault();
  89. window.plugins.childBrowser.showWebPage($(this).attr("href"));
  90. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement