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