diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/tools/scripts/toc.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/tools/scripts/toc.js')
-rw-r--r-- | testing/web-platform/tests/tools/scripts/toc.js | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/scripts/toc.js b/testing/web-platform/tests/tools/scripts/toc.js new file mode 100644 index 000000000..120d4be03 --- /dev/null +++ b/testing/web-platform/tests/tools/scripts/toc.js @@ -0,0 +1,107 @@ +// grab the table of contents filled with all the anchors +function __result_handler() { + function getMap() { + var toc_element = document.getElementById("contents").nextElementSibling; + + function getSection() { + function getIds(node) { + var a = []; + + var nodes = node.querySelectorAll('*[id]'); + for (var i = 0; i < nodes.length; i++) { + a.push(nodes[i].getAttribute("id")); + } + return a; + } + + function getTOCIds() { + var a = []; + + var nodes = toc_element.querySelectorAll('li'); + for (var i = 0; i < nodes.length; i++) { + var href = nodes[i].firstElementChild.getAttribute("href"); + a.push(href.substring(1)); + } + return a; + } + + var obj = new Object(); + var ids = getIds(document); + var toc = getTOCIds(); + + for (var i = 1; i < toc.length; i++) { + var key1 = toc[i-1]; + var key2 = toc[i]; + var map = []; + + var index1 = ids.indexOf(key1); + var index2 = ids.indexOf(key2); + + if ((index2-index1) > 1) { + for (var j = index1+1; j < index2;j++) { + map.push(ids[j]); + } + } + + obj[key1] = map; + } + { + var key = toc[toc.length-1]; + var index = ids.indexOf(key); + var map = []; + + for (var j = index+1; j < ids.length;j++) { + map.push(ids[j]); + } + obj[key] = map; + } + + return obj; + } + + function section(id) { + this.id = id; + } + function addSubSection(section, sub) { + if (typeof section.sections === "undefined") { + section.sections = []; + } + section.sections.push(sub); + } + + function li(el, map) { + var obj = new section(el.firstElementChild.getAttribute("href").substring(1)); + obj.title = el.firstElementChild.textContent; + var child = el.firstElementChild; + + var m = map[obj.id]; + for (var i = 0; i < m.length; i++) { + var sub = new section(m[i]); + addSubSection(obj, sub); + } + while (child !== null) { + if (child.nodeName === "OL") ol(child, obj, map); + child = child.nextElementSibling; + } + return obj; + } + + function ol(el, section, map) { + var child = el.firstElementChild; + while (child !== null) { + addSubSection(section, li(child, map)); + child = child.nextElementSibling; + } + } + + var map = getSection(); + var main = new section("___main___"); + main.title = document.title; + + ol(toc_element, main, map); + + return main; + } + + return getMap(); +} |