home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / treePopups.js < prev    next >
Encoding:
JavaScript  |  2001-03-21  |  3.3 KB  |  99 lines

  1. /* -*- Mode: Java; tab-width: 4; c-basic-offset: 4; -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  *
  18.  * Contributor(s):
  19.  *   Dave Hyatt (hyatt@netscape.com)
  20.  *   Peter Annema <disttsc@bart.nl>
  21.  *   Blake Ross <blakeross@telocity.com>
  22.  */
  23.  
  24. function BuildTreePopup( treeColGroup, treeHeadRow, popup, skipCell )
  25. {
  26.   var popupChild = popup.firstChild;
  27.   var firstTime = !popupChild ? true : false;
  28.  
  29.   var currTreeCol = treeHeadRow.firstChild;
  30.   var currColNode = treeColGroup.firstChild;
  31.   var count = 0;
  32.   while (currTreeCol) {
  33.     if (currColNode.localName == "splitter")
  34.       currColNode = currColNode.nextSibling;
  35.  
  36.     if (skipCell != currTreeCol) {
  37.       // Construct an entry for each cell in the row.
  38.       var columnName = currTreeCol.getAttribute("label");
  39.       if (firstTime) {
  40.         if (currTreeCol.getAttribute("collapsed") != "true") {
  41.           popupChild = document.createElement("menuitem");
  42.           popupChild.setAttribute("type", "checkbox");
  43.           popupChild.setAttribute("label", columnName);
  44.           if (!count++) popupChild.setAttribute("disabled", "true");
  45.           if (columnName == "") {
  46.             var display = currTreeCol.getAttribute("display");
  47.             popupChild.setAttribute("label", display);
  48.           }
  49.           popupChild.setAttribute("colid", currColNode.id);
  50.           popupChild.setAttribute("oncommand", "ToggleColumnState(this, document)");
  51.           if ("true" != currColNode.getAttribute("hidden")) {
  52.             popupChild.setAttribute("checked", "true");
  53.           }
  54.           popup.appendChild(popupChild);
  55.         }
  56.       } else {
  57.         if ("true" == currColNode.getAttribute("hidden")) {
  58.           if (popupChild.getAttribute("checked"))
  59.             popupChild.removeAttribute("checked");
  60.         } else {
  61.           if (!popupChild.getAttribute("checked"))
  62.             popupChild.setAttribute("checked", "true");
  63.         }
  64.         if (currColNode.getAttribute("collapsed") == "true")
  65.           popupChild.setAttribute("hidden", "true");
  66.         else
  67.           popupChild.removeAttribute("hidden");
  68.  
  69.         popupChild = popupChild.nextSibling;
  70.       }
  71.     }
  72.  
  73.     currTreeCol = currTreeCol.nextSibling;
  74.     currColNode = currColNode.nextSibling;
  75.   }
  76. }
  77.  
  78. function DestroyPopup(element)
  79. {
  80. /*
  81.   while (element.firstChild) {
  82.     element.removeChild(element.firstChild);
  83.   }
  84.   */
  85. }
  86.  
  87. function ToggleColumnState(popupElement, doc)
  88. {
  89.   var colid = popupElement.getAttribute("colid");
  90.   var colNode = doc.getElementById(colid);
  91.   if (colNode) {
  92.     var checkedState = popupElement.getAttribute("checked");
  93.     if (checkedState == "true")
  94.       colNode.removeAttribute("hidden");
  95.     else
  96.       colNode.setAttribute("hidden", "true");
  97.   }
  98. }
  99.