DHTML Lab - dhtmlab.com - Dynamic Headline Fader, Version 2.01 | 3 | WebReference

DHTML Lab - dhtmlab.com - Dynamic Headline Fader, Version 2.01 | 3

Logo

Dynamic Headline Fader, Version 2.01
The Complete Code 2/2

The fader.js External File

This file, plus a sample HTML page and news array may be downloaded in ZIP format.

/*fader.js
 * by Peter Belesis. v2.01 990921
 * Originally published and documented at https://www.dhtmlab.com/
 * Copyright (c) 1999 internet.com Corp. All Rights Reserved.
 * You may re-use this code on a public Web site only if this entire
 * copyright notice appears unchanged and you publicly display
 * on the Web page a link to https://www.dhtmlab.com/.
 *
 * Contact [email protected] for all other uses.
*/
//2.01 added next line:
IE4mac = (IE4 && navigator.appVersion.indexOf("Mac") != -1);
FDRfinite = (FDRmaxLoops > 0);
FDRisOver = false;
FDRloadCount = 0;
if (!window.prefix) prefix = "";
window.onload = FDRcountLoads;
if (NS4) {
   FDRfadeImg = new Image();
   FDRfadeImg.onload = FDRcountLoads;
   FDRfadeImg.src = FDRgifSrc;
}
function FDRcountLoads() {
   if (IE4) {

//2.01 added time interval argument for IE4mac
      setTimeout("FDRinit()",1);
   }
   else {
      FDRloadCount++;
      if (FDRloadCount==2) {
         origWidth = innerWidth;
         origHeight = innerHeight;
         window.onresize = function(){
            if (innerWidth==origWidth && innerHeight==origHeight) return;
            location.reload();
         }
         FDRinit();
      }
   }
}
function FDRinit(){

//2.01 omitted next line
//   if (!window.arNews) return;
//2.01 added compatibility with fader 1.0 arrays
   if(!window.arNews) {
      if(!window.arTXT || !window.arURL) return;
      if(arTXT.length != arURL.length) return;
      arNews = [];
      for (i=0;i<arTXT.length;i++){
         arNews[arNews.length] = arTXT[i];
         arNews[arNews.length] = arURL[i];
      }
   }
    if (NS4) {
      if (!document.elFader) return;
      with(document.classes.newslink.A) {
         textDecoration = FDRlnkDec;
         color = FDRlnkCol;
         fontWeight = FDRfntWgh;
         fontSize = FDRfntSiz;
         fontStyle = FDRfntSty;
         fontFamily = FDRfntFam;
         lineHeight = FDRlinHgt;
         textAlign = FDRtxtAln;
      }
      with(document.classes.nolink.P) {
         color = FDRfntCol;
         fontWeight = FDRfntWgh;
         fontSize = FDRfntSiz;
         fontStyle = FDRfntSty;
         fontFamily = FDRfntFam;
         lineHeight = FDRlinHgt;
         textAlign = FDRtxtAln;
      }
      elFader = document.elFader;
      with (elFader) {
         document.write(" ");
         document.close();
         bgColor = FDRborCol;
         clip.width = FDRboxWid;
         clip.height = FDRboxHgt;
      }
      contWidth = FDRboxWid - (FDRborWid*2);
      contHeight = FDRboxHgt - (FDRborWid*2);
      elCont = new Layer(contWidth,elFader);
      with (elCont) {
         top = FDRborWid;
         left = FDRborWid;
         clip.width = contWidth;
         clip.height = contHeight;
         bgColor = FDRbackCol;
         visibility = "inherit";
      }
      newsWidth = contWidth - (FDRboxPad*2);
      newsHeight = contHeight - (FDRboxPad*2);
      elNews = new Layer(newsWidth,elCont);
      with (elNews) {
         top = FDRboxPad;
         left = FDRboxPad;
         clip.width = newsWidth ;
         clip.height = newsHeight;
      }
      
      elGif = new Layer(contWidth,elCont); 
        imStr = "<IMG SRC=" + FDRgifSrc +" WIDTH="+ Math.max(FDRfadeImg.width,(FDRboxWid - (FDRborWid*2))) +">"
        with (elGif) {
         document.write(imStr);
           document.close();
         moveAbove(elNews);
      }
      imgHeight = elGif.document.height;
   
      slideInc = (imgHeight/(FDRblendDur*1000/FDRgifInt));
      startTop = -(imgHeight - FDRboxHgt);
      elFader.visibility =  "show";
    }
    else {
        if (!window.elFader) return;
      elFader.innerHTML ="";

//2.01 added IE4mac stylesheet creation
      if(IE4mac) {
         document.body.insertAdjacentHTML("BeforeBegin","<STYLE></STYLE>");
      }
      else {
         if (!document.styleSheets.length) document.createStyleSheet();
      }
      with (document.styleSheets(document.styleSheets.length-1)) {
         addRule("A.newslink","text-decoration:"+FDRlnkDec+";color:"+ FDRlnkCol);
         addRule("A.newslink:hover","color:"+ FDRhovCol);
      }
      with (elFader.style) {
         width = FDRboxWid;
         height = FDRboxHgt;
         backgroundColor = FDRbackCol;
         overflow = "hidden";
         color = FDRfntCol;
         fontWeight = FDRfntWgh;
         fontSize = FDRfntSiz;
         fontStyle = FDRfntSty;
         fontFamily = FDRfntFam;
         lineHeight = FDRlinHgt;
         textAlign = FDRtxtAln;
         cursor = "default";
         visibility = "visible";
         borderWidth = FDRborWid;
         borderStyle = FDRborSty;
         borderColor = FDRborCol;
         padding  = FDRboxPad;   
         filter = "blendTrans(duration=" + FDRblendDur + ")";
      }
      elFader.onselectstart = function(){return false};

//2.01 added IE filter support check
      IEhasFilters = (elFader.filters.blendTrans) ? true : false;
    }
   elFader.onmouseover = function(){
      FDRisOver = true;
   }
   elFader.onmouseout = function(){
      FDRisOver = false;
      status = "";
   }
   FDRstart(0);
}
function FDRstart(ind){
    newsCount = ind;
    if (FDRfinite) loopCount = 0;
    FDRdo();
    blendTimer = setInterval("FDRdo()",FDRblendInt*1000)
}
function FDRdo() {
   if (FDRfinite && loopCount==FDRmaxLoops) {
      FDRend();
      return;
   }
   FDRfade();
   newsCount+=2;
   if (newsCount == arNews.length) {
      newsCount = 0;
      if (FDRfinite) loopCount++;
   }
}
function FDRfade(){
   dispStr = arNews[newsCount];
   linkStr = arNews[newsCount+1];
   isLink = linkStr.length;
   if (isLink) {
      newsStr = "<A CLASS=newslink "
              + "HREF='" + prefix + linkStr + "'>"
              + arNews[newsCount] + "</A>"
   }
   else {
      newsStr = (NS4) ? ("<P CLASS=nolink>"+dispStr+"</P>") : dispStr;
   }

// 2.01 added next line to help justify in IE4mac
    if(IE4mac) newsStr += "<BR>"
    if (NS4) {
      elGif.top = startTop;
      elGif.visibility = "inherit";
      elNews.visibility = "hide";
        with (elNews.document) {
            write(newsStr);
            close();
        }
      elNews.visibility = "inherit";
    }
    else {

//2.01 added IE filter support check
        if(IEhasFilters)elFader.filters.blendTrans.Apply();
        elFader.innerHTML = newsStr;
        if(IEhasFilters)elFader.filters.blendTrans.Play();
    }
   window.status = (FDRisOver && isLink) ? (prefix + linkStr) : "";
   if (NS4) FDRslide();
}
function FDRslide(){
    elGif.top += slideInc;
    if (elGif.top >= 0) {elGif.visibility = "hide";return}
    setTimeout("FDRslide()",FDRgifInt);
}
function FDRend(){
   clearInterval(blendTimer);
   if (FDRendWithFirst) {
      newsCount = 0;
      FDRfade();
   }
   if (FDRreplayOnClick) {
      startIndex = FDRendWithFirst ? 2 : 0;
      if (IE4) {
         elFader.title = "Double click to replay";
         elFader.ondblclick = function(){
            this.ondblclick = null;
            this.title = "";
            FDRstart(startIndex);
         }
      }
      else {
         elFader.captureEvents(Event.DBLCLICK);
         elFader.ondblclick = function(){

//2.01 changed next line:
            //this.releaseEvents(Event.DBLCLICK);
//to: (NSmac problem)
            elFader.releaseEvents(Event.DBLCLICK);
            FDRstart(startIndex);
            return false;
         }
      }
    }
}

Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Sep 21, 1999
Revised: Sep 21, 1999

URL: https://www.webreference.com/dhtml/column25/addendum1/allCode2.html