/** * ticker.js * * display each item as a typewriter news ticker * referencing to a URL * * @author Stephan Saalfeld * @copyright Copyright (c) 2004-2006, Stephan Saalfeld * @version 1.2 */ var READY = 0; var SCROLLING = 1; var ENDOFTEXT = 2; var TICKERLINES = 3; //var TICKERLINEHEIGHT = 13; var TICKERLINEHEIGHT = 1.3; var SCROLLSTEPS = 13; var TICKTIME = 100; var ENDOFTEXTTIME = 2000; var ENDOFLINETIME = 500; var CURSORBLINKTIME = 100; var ticker = false; function Ticker() { var i; this.text = new Array(); this.link = new Array(); this.text[0] = "Aktuelles:"; this.link[0] = new Array(); this.link[0]["url"] = "http://ziegel.de/?src=presse"; this.link[0]["target"] = ""; this.text[1] = unescape("Deutsche%20Dachziegel%20bringen%20die%0ASonne%20auf%20das%20Haus"); this.link[1] = new Array(); this.link[1]["url"] = "http://ziegel.de/?src=presse&ID=91631&Position=0"; this.link[1]["target"] = ""; this.text[2] = unescape("Ziegelindustrie%3A%20Seit%2015%20Jahren%0Asinkender%20Markt"); this.link[2] = new Array(); this.link[2]["url"] = "http://ziegel.de/?src=presse&ID=91624&Position=0"; this.link[2]["target"] = ""; this.text[3] = unescape("17.%20Internationale%20Tagung%0AZiegeleigeschichte%20%2F%0AZiegeleimuseen"); this.link[3] = new Array(); this.link[3]["url"] = "http://ziegel.de/?src=presse&ID=91549&Position=0"; this.link[3]["target"] = ""; this.text[4] = unescape("Abrisspr%E4mie%3A%20Neu%20bauen%20ist%20oft%0Adie%20beste%20Sanierung"); this.link[4] = new Array(); this.link[4]["url"] = "http://ziegel.de/?src=presse&ID=91526&Position=0"; this.link[4]["target"] = ""; this.text[5] = unescape("Asbest%20runter%20-%20Neue%20Dachziegel%0Aund%20Solarelemente%20rauf"); this.link[5] = new Array(); this.link[5]["url"] = "http://ziegel.de/?src=presse&ID=91388&Position=0"; this.link[5]["target"] = ""; this.index = 0; this.paper = document.getElementById( "ticker" ); this.cursor = document.getElementById( "cursor" ); this.linkImg = document.getElementById( "ticklink" ); this.cursorTimer = false; this.tickTimer = false; this.scrollState = 0; this.lines = 0; for ( i = 1; i < TICKERLINES; ++i ) { this.paper.replaceChild( document.createElement( "br" ), this.cursor ); this.paper.appendChild( this.cursor ); } this.chLink = function() { var link; this.paper.parentNode.removeChild(this.paper.nextSibling); if (this.link[this.index]["url"] != "") { link = document.createElement("a"); link.href = this.link[this.index]["url"]; link.target = this.link[this.index]["target"]; link.appendChild(this.linkImg); this.paper.parentNode.appendChild(link); } else { this.paper.parentNode.appendChild(this.linkImg); } return; } this.lastText = this.text[0]; this.chLink(); this.state = READY; this.tick = function() { var i; var letter; var wait; if (this.tickTimer) { self.clearTimeout(this.tickTimer); this.tickTimer = false; } switch (this.state) { case READY: if (this.lastText.length > 0) { letter = this.lastText.substr(0,1); this.lastText = this.lastText.substr(1,this.lastText.length-1); if (letter.charCodeAt(0) == 10) { this.paper.replaceChild(document.createTextNode(String.fromCharCode(160)), this.cursor); this.paper.appendChild(document.createElement("br")); this.state = SCROLLING; wait = ENDOFLINETIME; } else if (letter.charCodeAt(0) == 8) { this.paper.removeChild(this.paper.lastChild); this.paper.removeChild(this.paper.lastChild); this.paper.appendChild(this.cursor); wait = TICKTIME; } else { this.paper.replaceChild(document.createTextNode(letter), this.cursor); this.paper.appendChild(this.cursor); wait = TICKTIME; } } else { this.paper.replaceChild(document.createTextNode(String.fromCharCode(160)), this.cursor); this.state = ENDOFTEXT; wait = ENDOFTEXTTIME; } break; case SCROLLING: if (this.scrollState%SCROLLSTEPS < SCROLLSTEPS-1) { ++this.scrollState; //this.paper.style.top = Math.floor(-TICKERLINEHEIGHT*this.scrollState/SCROLLSTEPS) + "px"; this.paper.style.top = -TICKERLINEHEIGHT*this.scrollState/SCROLLSTEPS + "em"; } else { this.paper.appendChild(this.cursor); ++this.scrollState; ++this.lines; this.state = READY; } wait = 20; break; case ENDOFTEXT: if (this.scrollState < SCROLLSTEPS*(TICKERLINES+this.lines)) { ++this.scrollState; //this.paper.style.top = Math.max(-TICKERLINEHEIGHT*TICKERLINES, Math.floor(-TICKERLINEHEIGHT*this.scrollState/SCROLLSTEPS)) + "px"; //this.paper.style.top = Math.floor(-TICKERLINEHEIGHT*this.scrollState/SCROLLSTEPS) + "px"; this.paper.style.top = -TICKERLINEHEIGHT*this.scrollState/SCROLLSTEPS + "em"; } else { while(this.paper.firstChild) { this.paper.removeChild(this.paper.firstChild); } this.paper.style.top = "0px"; for (i = 1; i < TICKERLINES; ++i) { this.paper.appendChild(document.createElement("br")); } this.paper.appendChild(this.cursor); this.scrollState = 0; this.lines = 0; this.index = (++this.index)%this.text.length; this.lastText = this.text[this.index]; this.chLink(); this.state = READY; } wait = 20; break; } this.tickTimer = self.setTimeout("ticker.tick()", wait); return; } this.cursorTick = function() { if (this.cursorTimer) { self.clearTimeout(this.cursorTimer); this.cursorTimer = false; } if (this.cursor.className == "pos") this.cursor.className = "neg"; else this.cursor.className = "pos"; this.cursorTimer = self.setTimeout("ticker.cursorTick()", CURSORBLINKTIME); return; } this.tickTimer = self.setTimeout("ticker.tick()", TICKTIME); this.cursorTimer = self.setTimeout("ticker.cursorTick()", CURSORBLINKTIME); } function tick() { if (document.getElementById("ticker")) { ticker = new Ticker(); ticker.paper.parentNode.style.display = "block"; ticker.cursorTick(); //self.status = "Bundesverband der Deutschen Ziegelindustrie e.V."; return; } else return; }