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

Function footnotes

scripts/main.js:124–203  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

122
123
124function footnotes() {
125 var isMobile = innerWidth < 800
126
127 // read footnotes out of footer and stick into hidden popup divs
128 !(function() {
129 var footrefs = $(".footref:not(.correx)").unwrap();
130 var footnotes = $(".footdef");
131 footnotes.each(function(i, fn) {
132 var fnId = $(fn).find("a").eq(0).attr("id").split(".")[1];
133 $(fn).attr("data-fn-id", fnId);
134
135 var footref = $(document.getElementById("fnr."+fnId));
136 footref.wrap("<div class='footwrapper'></div>");
137 footref.attr("data-fn-id", fnId);
138 footref.parent().attr("data-fn-id", fnId);
139
140 var fnContent = $(fn).html().split("</sup>")[1];
141 footref.parent().append("<div class='fn-popup'>" + fnContent + "</div>");
142 });
143 })();
144
145 // Footnote popups
146 d3.selectAll(".footref")
147 .on("mouseover", showFootnote)
148 .on("mouseout", hideFootnote)
149 .on("click", toggleFootnote)
150 .on("touchend", toggleFootnote)
151
152 d3.selectAll('fn-popup')
153 .on('touchend', toggleFootnote)
154
155 function showFootnote(d,i) {
156 var popup = d3.select(this.parentElement).select(".fn-popup");
157 if(!popup.classed("stick") || isMobile) {
158 popup
159 .style("opacity", 0)
160 .style("display", "block")
161 .transition().duration(300)
162 .style("opacity", 1);
163 }
164
165 d3.select(this.parentElement)
166 .style('position', isMobile ? 'static' : 'relative')
167
168 var bb = this.getBoundingClientRect()
169 if (isMobile){
170 popup
171 .style('top', bb.top + scrollY + 20 + 'px')
172 .style('left', 160 + 'px')
173 } else{
174 popup
175 .style('top', '')
176 .style('left', '')
177 }
178
179
180 }
181

Callers 1

main.jsFile · 0.85

Calls 1

$Function · 0.50

Tested by

no test coverage detected