home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2002 July / APC0702D1.iso / isp / tpgi / tpgdialup / highlite_button.js < prev    next >
Encoding:
Text File  |  2000-06-20  |  2.5 KB  |  74 lines

  1. function HighlightButton(document, width, height, label, onclick)
  2. {
  3.     // First time called, document will be false. Ignore this call.
  4.     if (document == null) return;
  5.  
  6.     if (!HighlightButton.prototype.over) {
  7.         // Initialize the prototype object to create our methods.
  8.         HighlightButton.prototype.over = _HighlightButton_over;
  9.         HighlightButton.prototype.out = _HighlightButton_out;
  10.         HighlightButton.prototype.click = _HighlightButton_click;
  11.  
  12.     }
  13.         this.imagenames = new Array(2);
  14.         this.imagenames[0] = HighlightButton.imagenames[0];
  15.         this.imagenames[1] = HighlightButton.imagenames[1];
  16.     
  17.         this.images = new Array(2);
  18.         this.images[0] = new Image(width, height);
  19.         this.images[1] = new Image(width, height);
  20.         this.images[0].src = this.imagenames[0];
  21.         this.images[1].src = this.imagenames[1];
  22.  
  23.     // Save some of the arguments we were passed.
  24.     this.document = document;
  25.     this.label = label;
  26.  
  27.     // Remember that the mouse is not currently on top of us.
  28.     this.highlighted = false;
  29.  
  30.     this.onclick = onclick;
  31.     if (typeof this.onclick == "string")
  32.         this.onclick = new Function("state", this.onclick);
  33.  
  34.     var index = document.images.length;
  35.  
  36.     document.write('<A HREF ="" ' +
  37.       'onMouseOver="document.images[' + index + ']._hl.over();return true;" '+
  38.       'onMouseOut="document.images[' + index + ']._hl.out()" '+
  39.       'onClick="document.images[' + index + ']._hl.click(); return false;">');
  40.     document.write('<IMG SRC="' + HighlightButton.imagenames[0] +'"'+
  41.                    ' WIDTH=' + width +
  42.                    ' HEIGHT=' + height +
  43.                    ' BORDER=0 HSPACE=0 VSPACE=0>');
  44.     document.write('</A>');
  45.  
  46.     this.image = document.images[index];
  47.     this.image._hl = this;
  48. }
  49.  
  50. // This becomes the over() method.
  51. function _HighlightButton_over()
  52. {
  53.     // Change the image, and remember that we're highlighted.
  54.     this.image.src = this.imagenames[1];
  55.     this.highlighted = true;
  56.     window.status = this.label;
  57. }
  58.  
  59. // This becomes the out() method.
  60. function _HighlightButton_out()
  61. {
  62.     // Change the image, and remember that we're not highlighted.
  63.     this.image.src = this.imagenames[0];
  64.     this.highlighted = false;
  65.     window.status = "";
  66. }
  67.  
  68. // This becomes the click() method.
  69. function _HighlightButton_click()
  70. {
  71.     // Toggle the state of the button, change the image, and call the
  72.     // onclick method, if it was specified for this ToggleButton.
  73.     if (this.onclick) this.onclick();
  74. }