Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NewsTicker = {
- tickerDiv: 'ticker',
- tickerTitle: 'Headlines',
- tickerLink: "/test/",
- tickerLocation: "billboard",
- feedURL: "test.xml",
- pauseLength: 2000,
- timer: 0,
- currentTitle: 0,
- items: [],
- init: function()
- {
- new Ajax.Request(
- NewsTicker.feedURL,
- {
- method: "get",
- onSuccess: function(response) {
- NewsTicker.parseXML(response.responseXML);
- NewsTicker.buildTicker();
- },
- onFailure: function() {
- alert('whoops! feed was not loaded')
- }
- }
- );
- },
- buildTicker: function()
- {
- // build the container HTML
- var container = document.createElement("div");
- container.setAttribute("id", NewsTicker.tickerDiv);
- // build the first paragraph (for the main title on the left)
- var title = document.createElement("p");
- title.setAttribute("class", "left");
- // build the link for the title
- var titleLink = document.createElement("a");
- titleLink.setAttribute("href", NewsTicker.tickerLink);
- // add the headline text to the paragraph
- var headlineTitle = document.createTextNode(NewsTicker.tickerTitle);
- titleLink.appendChild(headlineTitle);
- title.appendChild(titleLink);
- container.appendChild(title); // add the text filled paragraph to the container div
- // add the headline to the container
- var newsPara = document.createElement("p");
- newsPara.setAttribute("class", "right");
- newsPara.setAttribute("id", "ticker-headline");
- var newsLink = document.createElement("a");
- newsLink.setAttribute("id", "news-link");
- newsLink.setAttribute("href", NewsTicker.items[NewsTicker.currentTitle]['link'])
- var newsTitle = document.createTextNode(NewsTicker.items[NewsTicker.currentTitle]['title']);
- newsLink.appendChild(newsTitle);
- newsPara.appendChild(newsLink);
- // add the hot news titles to the container
- container.appendChild(newsPara);
- // get the Element after NewsTicker.tickerLocation and insert the ticker before it
- $(NewsTicker.tickerLocation).up(0).insertBefore(container, $(NewsTicker.tickerLocation).nextSibling);
- /* ----- USE Element.update(var[+1]) OR Element.replace(var[+1]) TO UPDATE THE NEWS DISPLAY ------- */
- // NewsTicker.cycleHeadline(NewsTicker.pauseLength, 0);
- setTimeout(NewsTicker.fadeOut, NewsTicker.pauseLength);
- },
- parseXML: function(xml)
- {
- NewsTicker.xml = xml;
- // build the array of news titles
- $A(xml.getElementsByTagName("item")).each(function(item) {
- title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
- link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue;
- NewsTicker.items.push($H({title: title, link: link}));
- });
- },
- fadeOut: function()
- {
- // fade out the current content of the div
- if ( NewsTicker.currentTitle < NewsTicker.items.length-1 ) {
- NewsTicker.currentTitle = NewsTicker.currentTitle+1;
- } else {
- NewsTicker.currentTitle = 0;
- }
- Effect.Fade('ticker-headline', {afterFinish: function() {NewsTicker.switchData(); NewsTicker.fadeIn();}});
- },
- switchData: function()
- {
- $('news-link').setAttribute("href", NewsTicker.items[NewsTicker.currentTitle]['link']);
- $('news-link').childNodes[0].nodeValue = NewsTicker.items[NewsTicker.currentTitle]['title'];
- },
- fadeIn: function()
- {
- Effect.Appear('ticker-headline', {afterFinish: function() {setTimeout(NewsTicker.fadeOut, NewsTicker.pauseLength);}});
- }
- }
Add Comment
Please, Sign In to add comment