MCPcopy Create free account
hub / github.com/BloombergGraphics/whatiscode / renderTOC

Function renderTOC

modules/toc/toc.js:161–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

159 }
160
161 function renderTOC() {
162 var tree = [];
163 d3.selectAll("article section")
164 .each(function(d) {
165 var subtree = [];
166 d3.select(this).selectAll("h2,h3")
167 .each(function(dd) {
168 subtree.push(this);
169 });
170 tree.push(subtree);
171 });
172
173 module.sel.append("div.toc")
174 .selectAll("div.toc-section")
175 .data(tree)
176 .enter()
177 .append("div.toc-section")
178 .selectAll("div.toc-head")
179 .data(function(d) { return d; })
180 .enter()
181 .append("a.toc-head")
182 .attr("data-level", ƒ('tagName'))
183 .attr("href", function(d) { return '#' + d.id; })
184 .html(function(d) { return d.childNodes[0].innerText + ". " + d.childNodes[1].nodeValue; })
185 .on("click", function(d) {
186 d3.event.preventDefault();
187 history.pushState(null, null, '#'+d.id);
188 stats.windows.previous = stats.windows.current;
189 d3.select("body").transition().duration(500)
190 .tween("tocscroll", scrollTopTween(d.getBoundingClientRect().top + pageYOffset));
191 });
192 }
193
194 function renderStats() {
195

Callers 1

toc.jsFile · 0.85

Calls 1

scrollTopTweenFunction · 0.85

Tested by

no test coverage detected