/** * Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this * source code is governed by a BSD-style license that can be found in the * LICENSE file. */ var TEXT_NODE = 3; // Text nodes have nodeType of 3. /** * Toggles the display of nodes given the status of their associated controls. * * For each node passed to this function, check to see if a toggle has been * inserted into the node's parent. If yes, change the state of the toggle and * hide/reveal the node as needed. * * @param {NodeList|Node|Array.} Nodes to operate on. */ function toggleList(list) { if (typeof list.length != 'number') { list = Array(list); } for (var i = 0; i < list.length; i++) { var toggle = list[i].parentNode && list[i].parentNode.firstChild; if (toggle && toggle.className.substring(0, 6) == 'toggle') { var visible = toggle.className == 'toggle'; list[i].style.display = visible ? 'block' : 'none'; toggle.className = visible ? 'toggle selected' : 'toggle'; } } }; /** * Reveals the hidden ancestor of the passed node, adjusts toggles as needed. * * @param {Node} node The node whose ancestor is a hidden toggleable element. */ function revealAncestor(node) { while (node.parentNode) { if (node.style.display == 'none') { toggleList(node); break; } node = node.parentNode; } }; /** * Adds toggle controls to the sidebar list. * * Controls are inserted as the first children of list items in the sidebar * which contain only text (not a link). Handlers are set up so that when a * toggle control is clicked, any