(dictionary)
| 34 | } |
| 35 | |
| 36 | function highlightTerms(dictionary) { |
| 37 | var html = d3.select("article").html(); |
| 38 | dictionary.forEach(function(value, index) { |
| 39 | var re = new RegExp(escapeRegExp(value.title),"gi"); |
| 40 | html = html.replace(re, function(match) { return "<span class='glossary-item' data-term='"+value.title+"'>"+match+"</span>"; }); |
| 41 | }); |
| 42 | d3.select("article").html(html); |
| 43 | |
| 44 | var tooltip = d3.select("body").append("div").classed("glossary-tooltip", true); |
| 45 | d3.selectAll(".glossary-item").on("mouseover", function(d) { |
| 46 | console.log(this.dataset.term, _.findWhere(glossaryLite, {"title": this.dataset.term})) |
| 47 | tooltip.classed("on", true) |
| 48 | .style("top", (this.getBoundingClientRect().top+d3.select("body").node().scrollTop)+"px") |
| 49 | .style("left", this.getBoundingClientRect().left+"px") |
| 50 | .text(_.findWhere(glossaryLite, {"title": this.dataset.term}).description); |
| 51 | }).on("mouseout", function(d) { |
| 52 | tooltip.classed("on", false); |
| 53 | }) |
| 54 | } |
| 55 | |
| 56 | function escapeRegExp(str) { |
| 57 | return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); |
no test coverage detected