PDA

View Full Version : Script text dynamic



giansard
03-15-2005, 01:02 PM
Hi
I'm a Italian webmaster and I need a information about a script that I' ve seen in the website of subaru rally team.SUBARU (http://www.swrt.com)
The script is that "latest rally news" at the right of home page.

Somebody can help me to find that script?

Thank you.....and sorry for my english not correct.

Gianluca

TheBigT
03-15-2005, 10:26 PM
Here is the one off the website.. but you better ask them if you are allowed to use the code. I don't have the skill to write something like this.



// Ticker code
var tickercharsvisible=0;
var tickernum=0;
var tickerAutoReload = false; // May be overridden on some pages
var tickerFirstArticleCount = 0; // Number of times 1st article has been shown.
var tickerUrlBase = ""; // URL base (relative to current doc)

var TICKER_SPEED = 2; // Chars each tick.
var TICKER_DELAY = 5000; // ms between messages

/*
If we've seen the first article twice or more, and the reload is enabled,
reload the page.
*/

/*
This code now stores the last ticker which has *started* to build in a cookie.
This is only a temporary cookie, but it remembers stuff from page to page. This
cookie means you see the same story again on the next page, then it proceeds
(rather than starting again from the beginning)
*/

/* Loads global tickernum variable from a cookie.
* Checks if it's beyond the end, if so sets back to 0
*/
function loadTickerNum()
{
// Split out any cookies the browser may have
var bits;
bits = document.cookie.split(";");
var i;
for (i in bits) { // scan cookies
var bit = bits[i];
// This holds the name & value in array 0,1 respectively
var nameandval = bit.split("=");
nameandval[0] = nameandval[0].replace(/ /g,""); // trim whitespace
if (nameandval[0] == "tickernum")
tickernum = parseInt(nameandval[1]);
}
// Check it isn't too big - if we've fallen off, start again.
if (tickernum >= tickermessages.length) {
tickernum=0;
}
}

/*
* Save the ticker number into a cookie
*/
function saveTickerNum()
{
document.cookie = "tickernum=" + tickernum;
}

function showForNs4(strHeading, strBody)
{
if (! document.layers) return; // Ignore unless we're actually on NS4 :)
var oLayer = document.layers['tickeril'].document.layers['tickerl'];
var html = "<a href='news.html' onclick='tickerClick(); return false;'>" +
"<strong>" + strHeading + "</strong><br>" + strBody + "</a>";
oLayer.document.open();
oLayer.document.write(html);
oLayer.document.close();
return;
}

function setHtml(strId, html) {
// The "nice" DOM-1 way of doing it - IE5, Gecko (i.e. NS6) etc
if (typeof(document.getElementById) != "undefined") {
document.getElementById(strId).innerHTML = html;
return;
}
// The "nonstandard" IE4 specific "all"
if (typeof(document.all) != "undefined") {
document.all[strId].innerHTML = html;
return;
}
return; // else do nowt
}

function scrollIt() {
var txt;
var blnComplete;
var message = tickermessages[tickernum];
var link = tickerlinks[tickernum];
tickercharsvisible += TICKER_SPEED;
// Work out how many characters of the heading and body should be visible.
var headingCharsVisible = tickercharsvisible;
var strHeading, strBody;
// Split the message into heading and body
var bits = message.split("|");
strHeading = bits[0];
strBody = bits[1];
// Do the sums
var bodyCharsVisible = tickercharsvisible - strHeading.length;

blnComplete = (bodyCharsVisible >= strBody.length);
var blnHeadingComplete = (headingCharsVisible > (strHeading.length+TICKER_SPEED));

if (! blnHeadingComplete)
setHtml("tickerheading",strHeading.substr(0,headingCharsVisible));
setHtml("tickerbody",strBody.substr(0,bodyCharsVisible));
if (tickercharsvisible ==2)
showForNs4(strHeading,strBody);
if (! blnComplete) {
setTimer();
} else {
setTimeout("nextMsg()",TICKER_DELAY);
}
}

function setTimer() {
setTimeout("scrollIt()",100);
}

function nextMsg() {
tickercharsvisible=0;
tickernum ++;
// If we've reached the end, start again
if (tickernum >= tickermessages.length) {
tickernum=0;
tickerFirstArticleCount++;
if ((tickerFirstArticleCount >=2) && tickerAutoReload) {
saveTickerNum(); // Make sure we start at the beginning
window.location.reload(true);
return; // Don't reset the timer.
}
}
saveTickerNum(); // stash it.
setTimer();
}

// Returns a bool true if the ticker exists on the page.
// Check to see if ticker is present to avoid errors if it isn't
function checkTickerPresent()
{
if (document.getElementById) {
if (document.getElementById("tickerheading"))
return true;
}
if (document.all) {
if (document.all["tickerheading"])
return true;
}
if (document.layers) {
if (document.layers['tickeril'])
return true;
}
return false;
}

function tickerStartUp() {
if (! checkTickerPresent()) return; // give up
loadTickerNum();
setTimer();
}

function tickerClick() {
var link = tickerlinks[tickernum];
if (link == "") return;
if (window.top) {
window.top.location.href=tickerUrlBase + link;
} else {
window.location.href=tickerUrlBase + link;
}
}