/[drupal]/contributions/modules/ajax_newsflash/ajaxticker.js
ViewVC logotype

Contents of /contributions/modules/ajax_newsflash/ajaxticker.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Jun 17 11:12:14 2008 UTC (17 months, 1 week ago) by thenicespider
Branch: MAIN
CVS Tags: DRUPAL-5--1-4, DRUPAL-5--1-15, DRUPAL-5--1-14, DRUPAL-5--1-11, DRUPAL-5--1-10, DRUPAL-5--1-13, DRUPAL-5--1-12, DRUPAL-5--1-9, DRUPAL-5--1-8, DRUPAL-6--1-0-ALPHA1, DRUPAL-5--1-5, DRUPAL-5--1-7, DRUPAL-5--1-6, DRUPAL-5--1-1, DRUPAL-5--1-0, DRUPAL-5--1-3, DRUPAL-5--1-2, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/javascript
First version of AJAX Newsflash. Show Newsflash using AJAX!
1 // -------------------------------------------------------------------
2 // Ajax XML Ticker (txt file source)
3 // Author: Dynamic Drive (http://www.dynamicdrive.com)
4 // -------------------------------------------------------------------
5
6 ////////////No need to edit beyond here//////////////
7
8 function createAjaxObj(){
9 var httprequest=false
10 if (window.XMLHttpRequest){ // if Mozilla, Safari etc
11 httprequest=new XMLHttpRequest()
12 if (httprequest.overrideMimeType)
13 httprequest.overrideMimeType('text/xml')
14 }
15 else if (window.ActiveXObject){ // if IE
16 try {
17 httprequest=new ActiveXObject("Msxml2.XMLHTTP");
18 }
19 catch (e){
20 try{
21 httprequest=new ActiveXObject("Microsoft.XMLHTTP");
22 }
23 catch (e){}
24 }
25 }
26 return httprequest
27 }
28
29 // -------------------------------------------------------------------
30 // Main Ajax Ticker Object function
31 // ajax_ticker(xmlfile, divId, divClass, delay, optionalfadeornot)
32 // -------------------------------------------------------------------
33
34 function ajax_ticker(xmlfile, divId, divClass, delay, fadeornot){
35 this.xmlfile=xmlfile //Variable pointing to the local ticker xml file (txt)
36 this.tickerid=divId //ID of ticker div to display information
37 this.delay=delay //Delay between msg change, in miliseconds.
38 this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over ticker (and pause it if it is)
39 this.pointer=0
40 this.opacitystring=(typeof fadeornot!="undefined")? "width: 100%; filter:progid:DXImageTransform.Microsoft.alpha(opacity=100); -moz-opacity: 1" : ""
41 if (this.opacitystring!="") this.delay+=500 //add 1/2 sec to account for fade effect, if enabled
42 this.opacitysetting=0.2 //Opacity value when reset. Internal use.
43 this.messages=[] //Arrays to hold each message of ticker
44 this.ajaxobj=createAjaxObj()
45 document.write('<div id="'+divId+'" class="'+divClass+'"><div style="'+this.opacitystring+'">Initializing ticker...</div></div>')
46 this.getXMLfile()
47 }
48
49 // -------------------------------------------------------------------
50 // getXMLfile()- Use Ajax to fetch xml file (txt)
51 // -------------------------------------------------------------------
52
53 ajax_ticker.prototype.getXMLfile=function(){
54 if (this.ajaxobj){
55 var instanceOfTicker=this
56 var url=this.xmlfile+"?bustcache="+new Date().getTime()
57 this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
58 this.ajaxobj.open('GET', url, true)
59 this.ajaxobj.send(null)
60 }
61 }
62
63 // -------------------------------------------------------------------
64 // initialize()- Initialize ticker method.
65 // -Gets contents of xml file and parse it using JavaScript DOM methods
66 // -------------------------------------------------------------------
67
68 ajax_ticker.prototype.initialize=function(){
69 if (this.ajaxobj.readyState == 4){ //if request of file completed
70 if (this.ajaxobj.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful
71 this.contentdiv=document.getElementById(this.tickerid).firstChild //div of inner content that holds the messages
72 var xmldata=this.ajaxobj.responseText
73 this.contentdiv.style.display="none"
74 this.contentdiv.innerHTML=xmldata
75 if (this.contentdiv.getElementsByTagName("div").length==0){ //if no messages were found
76 this.contentdiv.innerHTML="<b>Error</b> fetching remote ticker file!"
77 return
78 }
79 var instanceOfTicker=this
80 document.getElementById(this.tickerid).onmouseover=function(){instanceOfTicker.mouseoverBol=1}
81 document.getElementById(this.tickerid).onmouseout=function(){instanceOfTicker.mouseoverBol=0}
82 if (window.attachEvent) //Clean up loose references in IE
83 window.attachEvent("onunload", function(){instanceOfTicker.contentdiv=instanceOfTicker.ajaxobj=null})
84 //Cycle through XML object and store each message inside array
85 for (var i=0; i<this.contentdiv.getElementsByTagName("div").length; i++){
86 if (this.contentdiv.getElementsByTagName("div")[i].className=="message")
87 this.messages[this.messages.length]=this.contentdiv.getElementsByTagName("div")[i].innerHTML
88 }
89 this.contentdiv.innerHTML=""
90 this.contentdiv.style.display="block"
91 this.rotatemsg()
92 }
93 }
94 }
95
96 // -------------------------------------------------------------------
97 // rotatemsg()- Rotate through ticker messages and displays them
98 // -------------------------------------------------------------------
99
100 ajax_ticker.prototype.rotatemsg=function(){
101 var instanceOfTicker=this
102 if (this.mouseoverBol==1) //if mouse is currently over ticker, do nothing (pause it)
103 setTimeout(function(){instanceOfTicker.rotatemsg()}, 100)
104 else{ //else, construct item, show and rotate it!
105 this.fadetransition("reset") //FADE EFFECT- RESET OPACITY
106 this.contentdiv.innerHTML=this.messages[this.pointer]
107 this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100) //FADE EFFECT- PLAY IT
108 this.pointer=(this.pointer<this.messages.length-1)? this.pointer+1 : 0
109 setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container periodically
110 }
111 }
112
113 // -------------------------------------------------------------------
114 // fadetransition()- cross browser fade method for IE5.5+ and Mozilla/Firefox
115 // -------------------------------------------------------------------
116
117 ajax_ticker.prototype.fadetransition=function(fadetype, timerid){
118 var contentdiv=this.contentdiv
119 if (fadetype=="reset")
120 this.opacitysetting=0.2
121 if (contentdiv.filters && contentdiv.filters[0]){
122 if (typeof contentdiv.filters[0].opacity=="number") //IE6+
123 contentdiv.filters[0].opacity=this.opacitysetting*100
124 else //IE 5.5
125 contentdiv.style.filter="alpha(opacity="+this.opacitysetting*100+")"
126 }
127 else if (typeof contentdiv.style.MozOpacity!="undefined" && this.opacitystring!=""){
128 contentdiv.style.MozOpacity=this.opacitysetting
129 }
130 else
131 this.opacitysetting=1
132 if (fadetype=="up")
133 this.opacitysetting+=0.1
134 if (fadetype=="up" && this.opacitysetting>=1)
135 clearInterval(this[timerid])
136 }

  ViewVC Help
Powered by ViewVC 1.1.2