home *** CD-ROM | disk | FTP | other *** search
- // ---------------------------------------------------------------------------
- //
- // Owner: Terry Farrell (html_autolayout@hotmail.com)
- // Button and ListBox AutoSize Code
- //
- // Created: March 25th 1999
- // Last Updated: May 4th 1999
- //
- // ---------------------------------------------------------------------------
-
- // ---------------------------------------------------------------------------
- // fixButtons
- //
- // This function checks all the <button> tags in the document. It ensures
- // that all buttons with the same class name have the same width.
- //
- // Paramaters:
- // document = document containing the buttons
- // buttonClass = Class of buttons that all need to be the same size
- // enforceMinWidth = Buttons must be at least the default "OK" button size
- // ---------------------------------------------------------------------------
-
- function HALsizeButtons(document, buttonClass, enforceMinWidth)
- {
- var doc = document.all.tags("BUTTON"); // Grab a collection of buttons
- var len = doc.length; // Find the number of buttons
- var i; // Counter variables
- var elem; // Shortcut pointer to current button
- var buttonEdges = 6; // The size the edges of a button take
- var buttonPadding = 20; // Padding to add if len calculated with labels
- var minWidth = 74; // Standard width of an "OK" button
- var maxWidth = 0; // Find the longest button
-
-
- // First loop to cycle through all the buttons to find the maximum width
- for (i=0; i < len; i++)
- {
- elem = doc(i); // Point to current button
-
- // Only concerned with buttons with a class
- if (elem.className.length != 0 && elem.className == buttonClass) // check class
- {
- if (elem.children.length > 0 && elem.children[0].tagName == "LABEL")
- { // If there is a label, use it's width
- maxWidth = Math.max(elem.children[0].offsetWidth + buttonPadding, maxWidth)
- }
- else
- { // otherwise, just use the button width
- maxWidth = Math.max(elem.offsetWidth + buttonEdges, maxWidth);
- }
- }
- }
-
- // See if this button should have a minimum width
- if (enforceMinWidth && maxWidth < minWidth)
- maxWidth = minWidth;
-
- // Second loop to cycle through all the buttons to set the maximum width
- for (i=0; i < len; i++)
- {
- elem = doc(i); // Point to current button
-
- // Only concerned with buttons with a class
- if (elem.className.length != 0 && elem.className == buttonClass)
- {
- elem.style.pixelWidth = maxWidth;
- }
- }
-
- }
-
- // ---------------------------------------------------------------------------
- // HALbuttonWidth
- //
- // This function checks all the <button> tags in the document. It ensures
- // that all buttons with the same ID have the same width. This is done using
- // expressions so it will only work for IE 5.0.
- //
- // Paramaters:
- // buttonClass = Class of buttons that all need to be the same size
- // enforceMinWidth = Buttons must be at least the default "OK" button size
- // ---------------------------------------------------------------------------
-
- function HALbuttonWidth(buttonTextID, enforceMin)
- {
- return getMaxWidth(buttonTextID, enforceMin) + 20
- }
-
- function getMaxWidth(buttonTextID, enforceMin)
- {
- var maxWidth = 0
- for (i = 0 ; i < buttonTextID.length ; i++)
- {
- maxWidth = Math.max(buttonTextID[i].offsetWidth, maxWidth)
- }
-
- if (enforceMin && maxWidth < 55)
- maxWidth = 55;
-
- return maxWidth
- }
-
-
-
- // ---------------------------------------------------------------------------
- // fixListBoxes
- //
- // This function checks all the <select> tags in the document. It ensures
- // that all lists with the same class name have the same width.
- //
- // Paramaters:
- // document = document containing the List Boxes
- // listClass = Class of list boxes that all need to be the same size
- // ---------------------------------------------------------------------------
-
- function HALsizeListBoxes(document, listClass)
- {
- var doc = document.all.tags("SELECT"); // Grab a collection of list boxes
- var len = doc.length; // Find the number of list boxes
- var i; // Counter variables
- var elem; // Shortcut pointer to current button
- var maxWidth = 0; // Find the longest button
-
-
- // First loop to cycle through all the list boxes to find the maximum width
- for (i=0; i < len; i++)
- {
- elem = doc(i); // Point to list box
- if (elem.className.length != 0 && elem.className == listClass)
- maxWidth = Math.max(elem.clientWidth, maxWidth);
- }
-
- // Second loop to cycle through all the list boxes to set the width
- for (i=0; i < len; i++)
- {
- elem = doc(i); // Point to current list box
-
- if (elem.className.length != 0 && elem.className == listClass)
- elem.style.pixelWidth = maxWidth;
- }
-
- }