Created
February 24, 2022 04:31
-
-
Save dmyates/b702befbe0cc1acba2a745921dcf9e93 to your computer and use it in GitHub Desktop.
This file contains hidden or 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