/*! jsFootnotes 28/12/2013 http://soqr.fr/footnotes/ * @author : Pascal Cauhépé @eQRoeil * @desc : add the footnote content next to the link to the footnote */ ;(function jsFootnotes() { if (!('querySelector' in document && 'addEventListener' in window)) return ; /* * change links selector here if needed... */ var notes = document.querySelectorAll('a[rel="footnote"]'); /** * find closest block parent of a[rel="footnote"] */ function findBlockParent(el) { while (el.parentNode) { el = el.parentNode; if (el.tagName === 'P' || el.tagName === 'LI'|| el.tagName === 'BLOCKQUOTE' || el.tagName === 'DIV' || el.tagName === 'BODY') return el; } return null; } /** * remove .js-footnote */ function removeNotes() { var footnotes = document.querySelectorAll('.js-footnote'); for (var i = 0; i < footnotes.length; i++) { var f = footnotes[i]; if (f.parentNode) { f.parentNode.removeChild(f); } } } /** * add div.js-footnote (with footnote content) to the closest parent */ function showFootnote(noteLink) { var footnoteId = noteLink.hash.substr(1); var footnoteContent = document.getElementById(footnoteId).innerHTML; var blck = findBlockParent(noteLink); if (getComputedStyle(blck, null).getPropertyValue("position") == "static") { blck.style.position = 'relative'; } var jsFootnoteTop = Math.round(noteLink.getBoundingClientRect().top - blck.getBoundingClientRect().top + noteLink.getBoundingClientRect().height); var jsFootnoteRight = 8; if (noteLink.getBoundingClientRect().left > 0.75 * blck.getBoundingClientRect().width) { jsFootnoteRight = Math.round(blck.getBoundingClientRect().width - noteLink.getBoundingClientRect().left); } blck.insertAdjacentHTML('beforeend', '