Home > Programming, javascript, wordpress > Footnotes jQuery inclusion

Footnotes jQuery inclusion

On my main site i've been using the footnotes plugin extensively. I like putting footnotes into the text and signalizing, what I'd rather say, but would not out of respect for the reader. In general placing extended information - be it a citation or an extension to the main text - is a nice way of writing. The plugin i'm using for that is wp-footnotes.

The problem is: for many readers it's hard to read the footnotes especially if they're at the end of a large article. I thought, i would script a little bit and found myself writing the following javascript-snippet which is based on the jQuery-library:

JAVASCRIPT:
  1. jQuery(document).ready(function () {
  2.     jQuery("a[href^='#footnote-'][id^='footnote-link']").each(function () {
  3.         aa = jQuery(this);
  4.         jQuery(jQuery(this).attr("href")).clone().find("a:last").replaceWith("<a href=\"" + aa.attr("href")  + "\">&raquo;</a>").end().contents().wrapAll("<span class='activefootnote'></span>").parent().insertAfter(aa);
  5.     });
  6. });

Update: wp-Footnotes 3.3

Version 3.3 of wp-footnotes formats the footnote-links differently and therefor our selector has to change. This is the new code:

JAVASCRIPT:
  1. jQuery(document).ready(function () {
  2.     jQuery("a[href*='#footnote_'][id^='identifier_']").each(function () {
  3.         aa = jQuery(this);
  4.         href = aa.href("href");
  5.         pos = href.indexOf('#');
  6.         len = href.length;
  7.         jQuery(href.substr(pos,len)).clone().find("a:last").replaceWith("<a href=\"" + aa.attr("href")  + "\">&raquo;</a>").end().contents().wrapAll("<span class='activefootnote'></span>").parent().insertAfter(aa);
  8.     });
  9. });

This inserts a span after the footnote number inside the article, which can then be shown or hidden on the spot. To support that effect, the following css-code should be present:

CSS:
  1. span.activefootnote {
  2.     display: none;
  3. }
  4. sup {
  5.     position: relative;
  6. }
  7. sup:hover span.activefootnote {
  8.     display: block;
  9.     position: absolute;
  10.     background: #fff;
  11.     border: 1px #000 solid;
  12.     top:-.5em;
  13.     left:-100px;
  14.     width: 200px;
  15. }

To make it look nicer, i've expanded the css-code to the following:

CSS:
  1. span.activefootnote {
  2.     display: none;
  3. }
  4. sup {
  5.     position: relative;
  6. }
  7. sup:hover span.activefootnote {
  8.     display: block;
  9.     position: absolute;
  10.     background: #eaeace;
  11.     border: 3px #ccc solid;
  12.     top:-.5em;
  13.     left:-100px;
  14.     width: 200px;
  15.     font-size: 1.2em;
  16.     padding: 6px;
  17.     border-radius: 10px;
  18.     -moz-border-radius: 8px;
  19.     border-radius: 1em;
  20.     -moz-border-radius: 1em;
  21.     opacity: 0.95;
  22. }

Maybe Simon Elvery will integrate this code into his plugin.. I think this would be a nice addition. You can see the effect at this article of mine. Just hover over one of the many footnote-numbers..

  1. No comments yet.
  1. No trackbacks yet.