This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Footnote previews for markdown by David Yates | |
// See an example here: | |
// https://davidyat.es/2020/12/31/footnote-previews/ | |
// | |
// License: MIT | |
// set previewSide to specify an additional class for footnote previews | |
refs = document.querySelectorAll("[id^=fnref]"); | |
activeBox = null; | |
refs.forEach(function (r){ | |
var fnlink = r.getElementsByTagName("a")[0] | |
var fnid = fnlink.href.split("#")[1]; | |
var num = fnid.split(":")[1] | |
var fn = document.getElementById(fnid); | |
fnlink.href = "javascript:void(0)"; | |
r.innerHTML += '<div id="fnbox:'+num+'" class="footnote-preview '+ previewSide +'" style="display: none;">'+fn.innerHTML+'</div>'; | |
var box = document.getElementById("fnbox:"+num); | |
r.addEventListener("click", function(event) { | |
if (box.style.display == "none") { | |
if (activeBox) activeBox.style.display = "none"; | |
box.style.display = "block"; | |
activeBox = box; | |
} | |
else { | |
box.style.display = "none"; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment