Created
May 28, 2012 01:37
Footnotify click handler (excerpt for a blog post)
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
// Click handler below taken from lines 179-213 of footnotify.js | |
// in this Gist: <https://gist.github.com/2793552> | |
$("a").click(function(event){ | |
var target = $(event.currentTarget), | |
href = target.attr('href'), | |
selector, footnote_el, text; | |
if (href) { | |
switch (0) { | |
case href.indexOf(location.pathname): | |
case href.indexOf(location.origin + location.pathname): | |
href = href.replace(/^(.+)(\#.+)$/, '$2'); | |
// fall through: | |
case href.indexOf('#'): | |
selector = '#'+href.substr(1).replace(selectorRegExp,'\\$&'); | |
footnote_el = $(selector); | |
text = target.text(); | |
//consider validate on contents of text (instead of testing for subscript). | |
//Target was not in superscript. | |
if (!target.parents().is("sup")) { return null; } | |
//No target. | |
if (footnote_el.length === 0) { return null; } | |
//Have no children paragraphs, and is not a list element | |
if (footnote_el.children('p').length === 0 && footnote_el.filter('li').length === 0) { return null; } | |
//Contains images so it's probably not a footnote. | |
if (footnote_el.find('img').length > 0) { return null; } | |
return footnote_el; | |
// no default | |
} | |
} | |
return null; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment