complete.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. $(document).ready(function() {
  2. // Use attr() to add an id, rel, and title.
  3. $('div.chapter a[href*="wikipedia"]').attr({
  4. rel: 'external',
  5. title: function() {
  6. return 'Learn more about ' + $(this).text() + ' at Wikipedia.';
  7. },
  8. id: function(index, oldValue) {
  9. return 'wikilink-' + index;
  10. }
  11. });
  12. // Add "back to top" links.
  13. $('<a href="#top">back to top</a>').insertAfter('div.chapter p');
  14. $('<a id="top"></a>').prependTo('body');
  15. // Create footnotes.
  16. var $notes = $('<ol id="notes"></ol>').insertBefore('#footer');
  17. $('span.footnote').each(function(index) {
  18. $(this)
  19. .before([
  20. '<a href="#footnote-',
  21. index + 1,
  22. '" id="context-',
  23. index + 1,
  24. '" class="context">',
  25. '<sup>',
  26. index + 1,
  27. '</sup></a>'
  28. ].join(''))
  29. .appendTo($notes)
  30. .append([
  31. '&nbsp;(<a href="#context-',
  32. index + 1,
  33. '">context</a>)'
  34. ].join(''))
  35. .wrap('<li id="footnote-' + (index + 1) + '"></li>');
  36. });
  37. // Style pull quotes.
  38. $('span.pull-quote').each(function(index) {
  39. var $parentParagraph = $(this).parent('p');
  40. $parentParagraph.css('position', 'relative');
  41. var $clonedCopy = $(this).clone();
  42. $clonedCopy
  43. .addClass('pulled')
  44. .find('span.drop')
  45. .html('&hellip;')
  46. .end()
  47. .text($clonedCopy.text())
  48. .prependTo($parentParagraph);
  49. });
  50. });