summaryrefslogtreecommitdiffstats
path: root/components/onc/docs/onc_spec.js
blob: 8cc027a0f807eb30926d615c822dbf9eaea44523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2013 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 outline_root = null;
var root = null;
var outline_ptr = null;

function onEnter(node) {
  var li = document.createElement('li');
  outline_ptr.appendChild(li);

  var header = node.querySelector('h1');
  header.id = 'sec_' + header.textContent.replace(/ /g, '_');
  var link = document.createElement('a');
  link.href = '#' + header.id;
  link.textContent = header.textContent;
  li.appendChild(link);
  var ul = document.createElement('ul');
  li.appendChild(ul);
  outline_ptr = ul;
}

function onExit(node) {
  outline_ptr = outline_ptr.parentNode.parentNode;
}

function outline(node) {
  var in_toc = !node.classList.contains('not_in_toc');
  if (in_toc) {
    onEnter(node);
  }
  var child = node.firstChild;
  while (child) {
    if (child.tagName === 'SECTION') {
      outline(child);
    }
    child = child.nextSibling;
  }
  if (in_toc) {
    onExit(node);
  }
}


window.onload = function () {
  outline_root = document.getElementById('outline');
  root = document.getElementById('root');

  var ul = document.createElement('ul');
  outline_root.appendChild(ul);
  outline_ptr = ul;

  outline(root);
};