1// -------------------------------------------------------------------
2// Advanced RSS Ticker (Ajax invocation) core file
3// Author: Dynamic Drive (http://www.dynamicdrive.com)
4// -------------------------------------------------------------------
5
6//Relative URL syntax:
7var lastrssbridgeurl="lib/plugins/rssticker/bridge.php"
8
9//Absolute URL syntax. Uncomment below line if you wish to use an absolute reference:
10//var lastrssbridgeurl="http://"+window.location.hostname+"/rssticker/bridge.php"
11
12////////////No need to edit beyond here//////////////
13
14function createAjaxObj(){
15var httprequest=false
16if (window.XMLHttpRequest){ // if Mozilla, Safari etc
17httprequest=new XMLHttpRequest()
18if (httprequest.overrideMimeType)
19httprequest.overrideMimeType('text/xml')
20}
21else if (window.ActiveXObject){ // if IE
22try {
23httprequest=new ActiveXObject("Msxml2.XMLHTTP");
24}
25catch (e){
26try{
27httprequest=new ActiveXObject("Microsoft.XMLHTTP");
28}
29catch (e){}
30}
31}
32return httprequest
33}
34
35// -------------------------------------------------------------------
36// Main RSS Ticker Object function
37// rssticker_ajax(RSS_id, cachetime, divId, divClass, delay, optionallogicswitch)
38// -------------------------------------------------------------------
39
40function rssticker_ajax(RSS_url, cachetime, divId, divClass, delay, logicswitch){
41this.RSS_url=RSS_url //Array key indicating which RSS feed to display
42this.cachetime=cachetime //Time to cache feed, in minutes. 0=no cache.
43this.tickerid=divId //ID of ticker div to display information
44this.delay=delay //Delay between msg change, in miliseconds.
45this.logicswitch=(typeof logicswitch!="undefined")? logicswitch : ""
46this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over ticker (and pause it if it is)
47this.pointer=0
48this.opacitysetting=0.2 //Opacity value when reset. Internal use.
49this.title=[], this.link=[], this.description=[], this.pubdate=[] //Arrays to hold each component of an RSS item
50this.ajaxobj=createAjaxObj()
51document.write('<div id="'+divId+'" class="'+divClass+'" >Initializing ticker...</div>')
52if (window.getComputedStyle) //detect if moz-opacity is defined in external CSS for specified class
53this.mozopacityisdefined=(window.getComputedStyle(document.getElementById(this.tickerid), "").getPropertyValue("-moz-opacity")==1)? 0 : 1
54this.getAjaxcontent()
55}
56
57// -------------------------------------------------------------------
58// getAjaxcontent()- Makes asynchronous GET request to "bridge.php" with the supplied parameters
59// -------------------------------------------------------------------
60
61rssticker_ajax.prototype.getAjaxcontent=function(){
62if (this.ajaxobj){
63var instanceOfTicker=this
64var parameters="rss_url="+encodeURIComponent(this.RSS_url)+"&cachetime="+this.cachetime+"&bustcache="+new Date().getTime()
65this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
66this.ajaxobj.open('GET', lastrssbridgeurl+"?"+parameters, true)
67this.ajaxobj.send(null)
68}
69}
70
71// -------------------------------------------------------------------
72// initialize()- Initialize ticker method.
73// -Gets contents of RSS content and parse it using JavaScript DOM methods
74// -------------------------------------------------------------------
75
76rssticker_ajax.prototype.initialize=function(){
77if (this.ajaxobj.readyState == 4){ //if request of file completed
78if (this.ajaxobj.status==200){ //if request was successful
79var xmldata=this.ajaxobj.responseXML
80if(xmldata.getElementsByTagName("item").length==0){ //if no <item> elements found in returned content
81document.getElementById(this.tickerid).innerHTML="<b>Error</b> fetching remote RSS feed!<br />"+this.ajaxobj.responseText
82return
83}
84var instanceOfTicker=this
85this.feeditems=xmldata.getElementsByTagName("item")
86//Cycle through RSS XML object and store each peice of an item inside a corresponding array
87for (var i=0; i<this.feeditems.length; i++){
88this.title[i]=this.feeditems[i].getElementsByTagName("title")[0].firstChild.nodeValue
89this.link[i]=this.feeditems[i].getElementsByTagName("link")[0].firstChild.nodeValue
90this.description[i]=this.feeditems[i].getElementsByTagName("description")[0].firstChild.nodeValue
91this.pubdate[i]=this.feeditems[i].getElementsByTagName("pubDate")[0].firstChild.nodeValue
92}
93document.getElementById(this.tickerid).onmouseover=function(){instanceOfTicker.mouseoverBol=1}
94document.getElementById(this.tickerid).onmouseout=function(){instanceOfTicker.mouseoverBol=0}
95this.rotatemsg()
96}
97}
98}
99
100// -------------------------------------------------------------------
101// rotatemsg()- Rotate through RSS messages and displays them
102// -------------------------------------------------------------------
103
104rssticker_ajax.prototype.rotatemsg=function(){
105var instanceOfTicker=this
106if (this.mouseoverBol==1) //if mouse is currently over ticker, do nothing (pause it)
107setTimeout(function(){instanceOfTicker.rotatemsg()}, 100)
108else{ //else, construct item, show and rotate it!
109var tickerDiv=document.getElementById(this.tickerid)
110var linktitle='<div class="rsstitle"><a href="'+this.link[this.pointer]+'">'+this.title[this.pointer]+'</a></div>'
111var description='<div class="rssdescription">'+this.description[this.pointer]+'</div>'
112var feeddate='<div class="rssdate">'+this.pubdate[this.pointer]+'</div>'
113if (this.logicswitch.indexOf("description")==-1) description=""
114if (this.logicswitch.indexOf("date")==-1) feeddate=""
115var tickercontent=linktitle+feeddate+description //STRING FOR FEED CONTENTS
116this.fadetransition("reset") //FADE EFFECT- RESET OPACITY
117tickerDiv.innerHTML=tickercontent
118this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100) //FADE EFFECT- PLAY IT
119this.pointer=(this.pointer<this.feeditems.length-1)? this.pointer+1 : 0
120setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container every second
121}
122}
123
124// -------------------------------------------------------------------
125// fadetransition()- cross browser fade method for IE5.5+ and Mozilla/Firefox
126// -------------------------------------------------------------------
127
128rssticker_ajax.prototype.fadetransition=function(fadetype, timerid){
129var tickerDiv=document.getElementById(this.tickerid)
130if (fadetype=="reset")
131this.opacitysetting=0.2
132if (tickerDiv.filters && tickerDiv.filters[0]){
133if (typeof tickerDiv.filters[0].opacity=="number") //IE6+
134tickerDiv.filters[0].opacity=this.opacitysetting*100
135else //IE 5.5
136tickerDiv.style.filter="alpha(opacity="+this.opacitysetting*100+")"
137}
138else if (typeof tickerDiv.style.MozOpacity!="undefined" && this.mozopacityisdefined){
139tickerDiv.style.MozOpacity=this.opacitysetting
140}
141if (fadetype=="up")
142this.opacitysetting+=0.2
143if (fadetype=="up" && this.opacitysetting>=1)
144clearInterval(this[timerid])
145}