diff options
author | isaacs <i@izs.me> | 2014-03-19 09:25:40 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-03-19 09:26:05 -0700 |
commit | a65c1aaf3afe21a34cae7b4ad266a6f2723704d1 (patch) | |
tree | 61e4c2a3b069f78d8ef5ae635a887cda13ec1c15 /deps/npm/html/static/toc.js | |
parent | 43a29f53ca11ab48e1d1ef6b2a0e673ae43a42a0 (diff) | |
download | node-npm-1.4.6.tar.gz |
npm: upgrade to 1.4.6npm-1.4.6
Diffstat (limited to 'deps/npm/html/static/toc.js')
-rw-r--r-- | deps/npm/html/static/toc.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/deps/npm/html/static/toc.js b/deps/npm/html/static/toc.js new file mode 100644 index 000000000..2cfebd0aa --- /dev/null +++ b/deps/npm/html/static/toc.js @@ -0,0 +1,29 @@ +;(function () { +var wrapper = document.getElementById("wrapper") +var els = Array.prototype.slice.call(wrapper.getElementsByTagName("*"), 0) + .filter(function (el) { + return el.parentNode === wrapper + && el.tagName.match(/H[1-6]/) + && el.id + }) +var l = 2 + , toc = document.createElement("ul") +toc.innerHTML = els.map(function (el) { + var i = el.tagName.charAt(1) + , out = "" + while (i > l) { + out += "<ul>" + l ++ + } + while (i < l) { + out += "</ul>" + l -- + } + out += "<li><a href='#" + el.id + "'>" + + ( el.innerText || el.text || el.innerHTML) + + "</a>" + return out +}).join("\n") +toc.id = "toc" +document.body.appendChild(toc) +})(); |