05.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. $(document).ready(function () {
  2. 'use strict';
  3. // Use attr() to add an id, rel, and title.
  4. $('div.chapter a[href*="wikipedia"]').attr({
  5. rel: 'external',
  6. title: function () {
  7. return 'Learn more about ' + $(this).text() + ' at Wikipedia.';
  8. },
  9. id: function (index, oldValue) {
  10. return 'wikilink-' + index;
  11. }
  12. });
  13. // Add "back to top" links.
  14. $('<a href="#top">back to top</a>').insertAfter('div.chapter p');
  15. $('<a id="top"></a>').prependTo('body');
  16. // insertBefore <elem> prependTo <children /> appendTo </elem> insertAfter
  17. // Create footnotes.
  18. var $notes = $('<ol id="notes"></ol>').insertBefore('#footer');
  19. $('span.footnote').each (function (index) {
  20. $(this)
  21. .before([
  22. '<a href="#footnote-',
  23. index + 1,
  24. '" id="context-',
  25. index + 1,
  26. '" class="context">',
  27. '<sup>',
  28. index + 1,
  29. '</sup></a>'
  30. ].join(''))
  31. .appendTo($notes)
  32. .append([
  33. '&nbsp;(<a href="#context-',
  34. index + 1,
  35. '">context</a>)'
  36. ].join(''))
  37. .wrap('<li id="footnote-' + (index + 1) + '"></li>');
  38. });
  39. });