home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 December / DPPCPRO1202.ISO / Extras / Assistum / setup.exe / Msointl.dll / HTML / HALSIZE.JS < prev    next >
Encoding:
JavaScript  |  2001-02-13  |  4.7 KB  |  142 lines

  1. // ---------------------------------------------------------------------------
  2. //
  3. // Owner: Terry Farrell (html_autolayout@hotmail.com)
  4. // Button and ListBox AutoSize Code
  5. //
  6. // Created: March 25th 1999
  7. // Last Updated: May 4th 1999
  8. //
  9. // ---------------------------------------------------------------------------
  10.  
  11. // ---------------------------------------------------------------------------
  12. // fixButtons
  13. //
  14. // This function checks all the <button> tags in the document. It ensures
  15. // that all buttons with the same class name have the same width.
  16. //
  17. // Paramaters:
  18. //  document = document containing the buttons
  19. //  buttonClass = Class of buttons that all need to be the same size
  20. //  enforceMinWidth = Buttons must be at least the default "OK" button size
  21. // ---------------------------------------------------------------------------
  22.  
  23. function HALsizeButtons(document, buttonClass, enforceMinWidth)
  24. {
  25.     var doc = document.all.tags("BUTTON");    // Grab a collection of buttons
  26.     var len = doc.length;            // Find the number of buttons
  27.     var i;                    // Counter variables
  28.     var elem;                // Shortcut pointer to current button
  29.     var buttonEdges = 6;            // The size the edges of a button take
  30.     var buttonPadding = 20;            // Padding to add if len calculated with labels
  31.     var minWidth = 74;            // Standard width of an "OK" button
  32.     var maxWidth = 0;            // Find the longest button
  33.  
  34.    
  35.     // First loop to cycle through all the buttons to find the maximum width
  36.     for (i=0; i < len; i++)
  37.         {
  38.         elem = doc(i);                        // Point to current button
  39.  
  40.         // Only concerned with buttons with a class
  41.         if (elem.className.length != 0 && elem.className == buttonClass)       // check class
  42.             {
  43.             if (elem.children.length > 0 && elem.children[0].tagName == "LABEL")
  44.                 {    // If there is a label, use it's width
  45.                 maxWidth = Math.max(elem.children[0].offsetWidth + buttonPadding, maxWidth)
  46.                 }
  47.             else
  48.                 {    // otherwise, just use the button width
  49.                 maxWidth = Math.max(elem.offsetWidth + buttonEdges, maxWidth);
  50.                 }
  51.             }
  52.         }
  53.  
  54.     // See if this button should have a minimum width
  55.     if (enforceMinWidth && maxWidth < minWidth)
  56.         maxWidth = minWidth;
  57.  
  58.     // Second loop to cycle through all the buttons to set the maximum width
  59.     for (i=0; i < len; i++)
  60.         {
  61.         elem = doc(i);                        // Point to current button
  62.  
  63.         // Only concerned with buttons with a class
  64.         if (elem.className.length != 0 && elem.className == buttonClass)
  65.             {
  66.             elem.style.pixelWidth = maxWidth;
  67.             }
  68.         }
  69.  
  70. }
  71.  
  72. // ---------------------------------------------------------------------------
  73. // HALbuttonWidth
  74. //
  75. // This function checks all the <button> tags in the document. It ensures
  76. // that all buttons with the same ID have the same width. This is done using
  77. // expressions so it will only work for IE 5.0.
  78. //
  79. // Paramaters:
  80. //  buttonClass = Class of buttons that all need to be the same size
  81. //  enforceMinWidth = Buttons must be at least the default "OK" button size
  82. // ---------------------------------------------------------------------------
  83.  
  84. function HALbuttonWidth(buttonTextID, enforceMin)
  85. {
  86.     return getMaxWidth(buttonTextID, enforceMin) + 20
  87. }
  88.  
  89. function getMaxWidth(buttonTextID, enforceMin)
  90. {
  91.     var maxWidth = 0
  92.     for (i = 0 ; i < buttonTextID.length ; i++)
  93.     {
  94.         maxWidth = Math.max(buttonTextID[i].offsetWidth, maxWidth)
  95.     }
  96.     
  97.     if (enforceMin && maxWidth < 55)
  98.         maxWidth = 55;
  99.     
  100.     return maxWidth
  101. }
  102.  
  103.  
  104.  
  105. // ---------------------------------------------------------------------------
  106. // fixListBoxes
  107. //
  108. // This function checks all the <select> tags in the document. It ensures
  109. // that all lists with the same class name have the same width.
  110. //
  111. // Paramaters:
  112. //  document = document containing the List Boxes
  113. //  listClass = Class of list boxes that all need to be the same size
  114. // ---------------------------------------------------------------------------
  115.  
  116. function HALsizeListBoxes(document, listClass)
  117. {
  118.     var doc = document.all.tags("SELECT");    // Grab a collection of list boxes
  119.     var len = doc.length;            // Find the number of list boxes
  120.     var i;                    // Counter variables
  121.     var elem;                // Shortcut pointer to current button
  122.     var maxWidth = 0;            // Find the longest button
  123.  
  124.    
  125.     // First loop to cycle through all the list boxes to find the maximum width
  126.     for (i=0; i < len; i++)
  127.         {
  128.         elem = doc(i);                        // Point to list box
  129.         if (elem.className.length != 0 && elem.className == listClass)
  130.             maxWidth = Math.max(elem.clientWidth, maxWidth);
  131.         }
  132.  
  133.     // Second loop to cycle through all the list boxes to set the width
  134.     for (i=0; i < len; i++)
  135.         {
  136.         elem = doc(i);                        // Point to current list box
  137.  
  138.         if (elem.className.length != 0 && elem.className == listClass)
  139.             elem.style.pixelWidth = maxWidth;
  140.         }
  141.  
  142. }