Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function() { | 5 (function() { |
| 6 /** | 6 /** |
| 7 * Toggles the display of nodes given the status of their associated controls. | 7 * Toggles the display of nodes given the status of their associated controls. |
| 8 * | 8 * |
| 9 * For each node passed to this function, check to see if a toggle has been | 9 * For each node passed to this function, check to see if a toggle has been |
| 10 * inserted into the node's parent. If yes, change the state of the toggle | 10 * inserted into the node's parent. If yes, change the state of the toggle |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 * toggle control is clicked, any <ul> elements who are siblings of the | 51 * toggle control is clicked, any <ul> elements who are siblings of the |
| 52 * control are hidden/revealed as appropriate given the control's state. | 52 * control are hidden/revealed as appropriate given the control's state. |
| 53 * | 53 * |
| 54 * If a list item possesses the class "leftNavSelected" its ancestor <ul> is | 54 * If a list item possesses the class "leftNavSelected" its ancestor <ul> is |
| 55 * revealed by default (it represents the current page). | 55 * revealed by default (it represents the current page). |
| 56 */ | 56 */ |
| 57 function initSidebar() { | 57 function initSidebar() { |
| 58 var toc = document.getElementById('gc-toc'); | 58 var toc = document.getElementById('gc-toc'); |
| 59 if (!toc) | 59 if (!toc) |
| 60 return; | 60 return; |
| 61 var links = toc.getElementsByTagName('a'); | |
| 62 var selectedNode = null; | |
|
not at google - send to devlin
2012/08/13 23:17:21
nit: some separation between steps here would be n
cduvall
2012/08/13 23:46:10
Done.
| |
| 63 for (var i = 0; i < links.length; i++) { | |
| 64 if (links[i].href == document.location.href) { | |
|
not at google - send to devlin
2012/08/13 23:17:21
href isn't quite right. If somebody navigates dire
cduvall
2012/08/13 23:46:10
Done.
| |
| 65 links[i].className = 'leftNavSelected'; | |
| 66 links[i].href = 'javascript:void(0);'; | |
|
not at google - send to devlin
2012/08/13 23:17:21
if you do removeAttribute('href') it would convey
cduvall
2012/08/13 23:46:10
Done.
| |
| 67 selectedNode = links[i]; | |
| 68 break; | |
| 69 } | |
| 70 } | |
| 61 var items = toc.getElementsByTagName('li'); | 71 var items = toc.getElementsByTagName('li'); |
|
not at google - send to devlin
2012/08/13 23:17:21
nit: as above,
// Blah.
cduvall
2012/08/13 23:46:10
Done.
| |
| 62 var selectedNode = null; | |
| 63 for (var i = 0; i < items.length; i++) { | 72 for (var i = 0; i < items.length; i++) { |
| 64 var item = items[i]; | 73 var item = items[i]; |
| 65 if (item.className == 'leftNavSelected') { | 74 if (item.firstChild && item.firstChild.tagName == 'SPAN') { |
|
not at google - send to devlin
2012/08/13 23:17:21
if (!item.firstChild || item.firstChild.tagName !=
cduvall
2012/08/13 23:46:10
Done.
| |
| 66 selectedNode = item; | |
| 67 } else if (item.firstChild && | |
| 68 item.firstChild.tagName == 'SPAN') { | |
| 69 // Only assign toggles to text nodes in the sidebar. | 75 // Only assign toggles to text nodes in the sidebar. |
| 70 var a = document.createElement('a'); | 76 var a = document.createElement('a'); |
| 71 a.className = 'toggle selected'; | 77 a.className = 'toggle selected'; |
| 72 a.appendChild(document.createTextNode(' ')); | 78 a.appendChild(document.createTextNode(' ')); |
| 73 a.onclick = function() { | 79 a.onclick = function() { |
| 74 toggleList(this.parentNode.getElementsByTagName('ul')); | 80 toggleList(this.parentNode.getElementsByTagName('ul')); |
| 75 }; | 81 }; |
| 76 item.firstChild.onclick = function() { | 82 item.firstChild.onclick = function() { |
| 77 toggleList(this.parentNode.getElementsByTagName('ul')); | 83 toggleList(this.parentNode.getElementsByTagName('ul')); |
| 78 }; | 84 }; |
| 79 item.insertBefore(a, item.firstChild); | 85 item.insertBefore(a, item.firstChild); |
| 80 toggleList(item.getElementsByTagName('ul')); | 86 toggleList(item.getElementsByTagName('ul')); |
| 81 } | 87 } |
| 82 } | 88 } |
| 83 if (selectedNode) { | 89 if (selectedNode) { |
| 84 revealAncestor(selectedNode); | 90 revealAncestor(selectedNode); |
| 85 } | 91 } |
| 86 }; | 92 }; |
| 87 | 93 |
| 88 initSidebar(); | 94 initSidebar(); |
| 89 })() | 95 })() |
| OLD | NEW |