1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * Adds toggle controls to the sidebar list.
8 * Finds all elements marked as toggleable, and adds an onClick event to
9 * collapse and expand the element's children.
12 var sidebar = document.getElementById('gc-sidebar');
16 Array.prototype.forEach.call(sidebar.querySelectorAll('[toggleable]'),
17 function(toggleable) {
18 var button = toggleable.parentNode.querySelector('.button');
19 var toggleIndicator = button.querySelector('.toggleIndicator');
20 var isToggled = false;
23 toggleable.classList.add('hidden');
24 toggleIndicator.classList.remove('toggled');
26 toggleable.classList.remove('hidden');
27 toggleIndicator.classList.add('toggled');
29 isToggled = !isToggled;
31 button.setAttribute('href', 'javascript:void(0)');
32 button.addEventListener('click', toggle);