home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 February / Chip_2004-02_cd1.bin / chplus / jak_psat_web / behavior / tablehl.htc < prev    next >
Text File  |  2003-04-06  |  2KB  |  94 lines

  1.  
  2. <public:event    name="onrowselect" ID=rowSelect />
  3. <public:property name="hlColor" />
  4. <public:property name="slColor" />
  5. <PUBLIC:ATTACH EVENT="ondetach" ONEVENT="cleanup()" />
  6.  
  7. <script language=jscript>
  8.  
  9. var currRow = -1;
  10. var selRow = -1;
  11.  
  12. if (element.tagName == 'TABLE')
  13. {
  14.     element.attachEvent('onmouseover', onMouseOver);
  15.     element.attachEvent('onmouseout', onMouseOut);
  16.     element.attachEvent('onclick', onClick);
  17. }
  18. else
  19. {
  20.     alert("Error: tablehl not attached to a table element");
  21. }
  22.  
  23. function cleanup()
  24. {
  25.     hilite(-1);
  26.  
  27.     element.detachEvent('onmouseover', onMouseOver);
  28.     element.detachEvent('onmouseout', onMouseOut);
  29.     element.detachEvent('onclick', onClick);
  30. }
  31.  
  32. function onClick()
  33. {
  34.     srcElem = window.event.srcElement;
  35.  
  36.     //crawl up the tree to find the table row
  37.     while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE")
  38.         srcElem = srcElem.parentElement;
  39.  
  40.     if(srcElem.tagName != "TR") return;
  41.  
  42.     if(srcElem.rowIndex == 0 ) return;
  43.  
  44.     if (selRow != -1) selRow.runtimeStyle.backgroundColor = '';
  45.  
  46.     srcElem.runtimeStyle.backgroundColor = slColor;
  47.     selRow = srcElem;
  48.     
  49.     var oEvent     = createEventObject();
  50.     oEvent.selected = selRow;
  51.     rowSelect.fire(oEvent);
  52. }
  53.  
  54. function onMouseOver()
  55. {
  56.     srcElem = window.event.srcElement;
  57.     //crawl up to find the row
  58.     while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE")
  59.         srcElem = srcElem.parentElement;
  60.  
  61.     if(srcElem.tagName != "TR") return;
  62.  
  63.     if (srcElem.rowIndex > 0)
  64.         hilite(srcElem);
  65.     else
  66.         hilite(-1);
  67.  
  68. }
  69.  
  70. function onMouseOut()
  71. {
  72.     // Make sure we catch exit from the table
  73.     hilite(-1, -1);
  74. }
  75.  
  76. function hilite(newRow)
  77. {
  78.     if (hlColor != null )
  79.     {
  80.         if (currRow != -1 && currRow!=selRow)
  81.         {
  82.             currRow.runtimeStyle.backgroundColor = '';
  83.         }
  84.  
  85.         if (newRow != -1 && newRow!=selRow)
  86.         {
  87.             newRow.runtimeStyle.backgroundColor = hlColor;
  88.         }
  89.     }
  90.     currRow = newRow;
  91.  
  92. </script>
  93.