Guest User

Untitled

a guest
May 24th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. NewsTicker = {
  2. tickerDiv: 'ticker',
  3. tickerTitle: 'Headlines',
  4. tickerLink: "/test/",
  5. tickerLocation: "billboard",
  6. feedURL: "test.xml",
  7. pauseLength: 2000,
  8. timer: 0,
  9. currentTitle: 0,
  10. items: [],
  11. init: function()
  12. {
  13. new Ajax.Request(
  14. NewsTicker.feedURL,
  15. {
  16. method: "get",
  17. onSuccess: function(response) {
  18. NewsTicker.parseXML(response.responseXML);
  19. NewsTicker.buildTicker();
  20. },
  21. onFailure: function() {
  22. alert('whoops! feed was not loaded')
  23. }
  24. }
  25. );
  26. },
  27. buildTicker: function()
  28. {
  29. // build the container HTML
  30. var container = document.createElement("div");
  31. container.setAttribute("id", NewsTicker.tickerDiv);
  32. // build the first paragraph (for the main title on the left)
  33. var title = document.createElement("p");
  34. title.setAttribute("class", "left");
  35. // build the link for the title
  36. var titleLink = document.createElement("a");
  37. titleLink.setAttribute("href", NewsTicker.tickerLink);
  38. // add the headline text to the paragraph
  39. var headlineTitle = document.createTextNode(NewsTicker.tickerTitle);
  40. titleLink.appendChild(headlineTitle);
  41. title.appendChild(titleLink);
  42. container.appendChild(title); // add the text filled paragraph to the container div
  43.  
  44. // add the headline to the container
  45. var newsPara = document.createElement("p");
  46. newsPara.setAttribute("class", "right");
  47. newsPara.setAttribute("id", "ticker-headline");
  48. var newsLink = document.createElement("a");
  49. newsLink.setAttribute("id", "news-link");
  50. newsLink.setAttribute("href", NewsTicker.items[NewsTicker.currentTitle]['link'])
  51. var newsTitle = document.createTextNode(NewsTicker.items[NewsTicker.currentTitle]['title']);
  52. newsLink.appendChild(newsTitle);
  53. newsPara.appendChild(newsLink);
  54.  
  55. // add the hot news titles to the container
  56. container.appendChild(newsPara);
  57.  
  58. // get the Element after NewsTicker.tickerLocation and insert the ticker before it
  59. $(NewsTicker.tickerLocation).up(0).insertBefore(container, $(NewsTicker.tickerLocation).nextSibling);
  60.  
  61. /* ----- USE Element.update(var[+1]) OR Element.replace(var[+1]) TO UPDATE THE NEWS DISPLAY ------- */
  62. // NewsTicker.cycleHeadline(NewsTicker.pauseLength, 0);
  63. setTimeout(NewsTicker.fadeOut, NewsTicker.pauseLength);
  64. },
  65. parseXML: function(xml)
  66. {
  67. NewsTicker.xml = xml;
  68. // build the array of news titles
  69. $A(xml.getElementsByTagName("item")).each(function(item) {
  70. title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
  71. link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue;
  72. NewsTicker.items.push($H({title: title, link: link}));
  73. });
  74. },
  75. fadeOut: function()
  76. {
  77. // fade out the current content of the div
  78. if ( NewsTicker.currentTitle < NewsTicker.items.length-1 ) {
  79. NewsTicker.currentTitle = NewsTicker.currentTitle+1;
  80. } else {
  81. NewsTicker.currentTitle = 0;
  82. }
  83. Effect.Fade('ticker-headline', {afterFinish: function() {NewsTicker.switchData(); NewsTicker.fadeIn();}});
  84.  
  85. },
  86. switchData: function()
  87. {
  88. $('news-link').setAttribute("href", NewsTicker.items[NewsTicker.currentTitle]['link']);
  89. $('news-link').childNodes[0].nodeValue = NewsTicker.items[NewsTicker.currentTitle]['title'];
  90. },
  91. fadeIn: function()
  92. {
  93. Effect.Appear('ticker-headline', {afterFinish: function() {setTimeout(NewsTicker.fadeOut, NewsTicker.pauseLength);}});
  94. }
  95. }
Add Comment
Please, Sign In to add comment