Skip to content

Instantly share code, notes, and snippets.

@macu
Created May 2, 2015 16:28
Show Gist options
  • Select an option

  • Save macu/a1c6b61d856351ccd33c to your computer and use it in GitHub Desktop.

Select an option

Save macu/a1c6b61d856351ccd33c to your computer and use it in GitHub Desktop.
Convert <sup>*ID</sup> into action blocks that reveal their corresponding <p>*ID: text</p> on hover.
$(function() {
var footnotes = {};
// Gather footnotes.
var footnotePattern = /^\*(\w+):/;
$("p, .footnote").not(".footnote p, p .footnote").each(function() {
var match = footnotePattern.exec($(this).text());
if (match && match.length) {
footnotes[match[1]] = $(this);
}
});
// Connect references.
var referencePattern = /^\*(\w+)$/;
var highlighterCSS = {"background-color": "#f3f315"};
$("sup").each(function() {
var match = referencePattern.exec($(this).text());
if (match && match.length) {
var reference = match[1], referent = footnotes[reference];
if (referent) {
referent.css(highlighterCSS).detach();
$(this).css(highlighterCSS).hover(function() {
var parentBlock = $(this).closest("p, div, body>*");
referent.insertAfter(parentBlock);
}, function() {
referent.detach();
});
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment