OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 var outline_root = null; |
| 6 var root = null; |
| 7 var outline_ptr = null; |
| 8 |
| 9 function onEnter(node) { |
| 10 var li = document.createElement('li'); |
| 11 outline_ptr.appendChild(li); |
| 12 |
| 13 var header = node.querySelector('h1'); |
| 14 header.id = 'sec_' + header.textContent.replace(/ /g, '_'); |
| 15 var link = document.createElement('a'); |
| 16 link.href = '#' + header.id; |
| 17 link.textContent = header.textContent; |
| 18 li.appendChild(link); |
| 19 var ul = document.createElement('ul'); |
| 20 li.appendChild(ul); |
| 21 outline_ptr = ul; |
| 22 } |
| 23 |
| 24 function onExit(node) { |
| 25 outline_ptr = outline_ptr.parentNode.parentNode; |
| 26 } |
| 27 |
| 28 function outline(node) { |
| 29 var in_toc = !node.classList.contains('not_in_toc'); |
| 30 if (in_toc) { |
| 31 onEnter(node); |
| 32 } |
| 33 var child = node.firstChild; |
| 34 while (child) { |
| 35 if (child.tagName === 'SECTION') { |
| 36 outline(child); |
| 37 } |
| 38 child = child.nextSibling; |
| 39 } |
| 40 if (in_toc) { |
| 41 onExit(node); |
| 42 } |
| 43 } |
| 44 |
| 45 |
| 46 window.onload = function () { |
| 47 outline_root = document.getElementById('outline'); |
| 48 root = document.getElementById('root'); |
| 49 |
| 50 var ul = document.createElement('ul'); |
| 51 outline_root.appendChild(ul); |
| 52 outline_ptr = ul; |
| 53 |
| 54 outline(root); |
| 55 }; |
OLD | NEW |