home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / ScriptBuilder / NOSB30_TRIAL.exe / data1.cab / Program_Files / CompLib / rotatingBanner.js < prev    next >
Encoding:
JavaScript  |  1998-10-05  |  2.6 KB  |  63 lines

  1. // JavaScript Source File -- Created with NetObjects ScriptBuilder
  2. // Category:    Images// Language:    All
  3. // AUTHOR:      Joe Hage, http://www.exceptional.com, All Rights Reserved.
  4. //              Feel free to reuse this code provided you include this
  5. //              AUTHOR section in your pages.
  6. // DESC:        Ad banners just with JavaScript. No CGI required.
  7. // Sample HTML: ADBANNERS.HTML// PLATFORMS:    Netscape Navigator 3.0 and higher,
  8. //                  Microsoft Internet Explorer 4.0 and higher
  9. //====================================================================
  10.  
  11. function com_netobjects_rotatingBannerComponent( params ) {
  12.         this.addToArray = rbAddToArray;
  13.         this.visitAdvertiser = rbVisitAdvertiser;
  14.         this.rotateBanner = rbRotateBanner;
  15.         this.render = rbRender;
  16.  
  17.         this.imagesrc = (params.imagesrc+"" != "undefined" && params.imagesrc != null ? params.imagesrc+"" : "");
  18.         this.rotateTime = (params.rotateTime+"" != "undefined" && params.rotateTime != null ? params.rotateTime : 1);
  19.         this.name = (params.name+"" != "undefined" && params.name+"" != "" && params.name != null ? params.name : "rotatingBannerComponent1");
  20.  
  21.         this.rbAdvertiser = 0;
  22.         this.rbAdvertiserArray = new Array();
  23.         this.rbImageArray = new Array();
  24.     
  25.    function rbAddToArray( url, img ) {
  26.         newIndex = this.rbAdvertiserArray.length;
  27.         this.rbAdvertiserArray[newIndex] = url;
  28.         this.rbImageArray[newIndex] = img;
  29.    }
  30.  
  31.    //Function to navigate to the advertiser's web site
  32.    function rbVisitAdvertiser() {    
  33.       var outputString;
  34.        if(this.rbAdvertiserArray[this.rbAdvertiser].substring(0, 4) != "http")
  35.           outputString = "http://" + this.rbAdvertiserArray[this.rbAdvertiser];
  36.        else
  37.           outputString = this.rbAdvertiserArray[this.rbAdvertiser];
  38.          window.location.href = outputString
  39.    }
  40.  
  41.    //Function to render the image for banner
  42.    function rbRender() {    
  43.       var output = "<FORM NAME='" + this.imagesrc + "'><IMG NAME='" + this.imagesrc + "'";
  44.         output += " SRC='" + this.rbImageArray[0] + "' onClick='" + this.name + ".visitAdvertiser()'></FORM>";
  45.  
  46.      document.write(output);
  47.    }
  48.  
  49.    //Function to Rotate and Cycle through the images
  50.    function rbRotateBanner() {
  51.       if (this.rbAdvertiser >= this.rbAdvertiserArray.length)
  52.        this.rbAdvertiser = 0; 
  53.      if(this.imagesrc != "")
  54.      {
  55.        document.images[this.imagesrc].src = this.rbImageArray[this.rbAdvertiser++];
  56.        if(document.images[this.imagesrc].src+"" == "undefined") 
  57.          document.images[this.imagesrc].src = this.rbImageArray[0];
  58.     
  59.      setTimeout(this.name + ".rotateBanner()", this.rotateTime*1000);
  60.     }
  61.    }
  62. }
  63.