Guest User

Untitled

a guest
Jun 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. (function($){
  2. $(document).ready(function(){
  3. alert('hi');
  4. var dest = $('dl.toc dd.portletItem');
  5. var content = getContentArea();
  6. if (!content || !dest.length) return;
  7.  
  8. dest.empty();
  9.  
  10. var location = window.location.href;
  11. if (window.location.hash)
  12. location = location.substring(0, location.lastIndexOf(window.location.hash));
  13.  
  14. var stack = [];
  15. // Get headers in document order
  16. $(content).find('*').filter(function() { return /^h[1234]$/.test(this.tagName.toLowerCase()) })
  17. .not('.documentFirstHeading').each(function(i) {
  18. var level = this.nodeName.charAt(1) - 1;
  19. // size the stack to the current level
  20. while (stack.length < level) {
  21. var ol = $('<ol>');
  22. if (stack.length) {
  23. var li = $(stack[stack.length - 1]).children('li:last');
  24. if (!li.length)
  25. // create a blank li for cases where, e.g., we have a subheading before any headings
  26. li = $('<li>').appendTo($(stack[stack.length - 1]));
  27. li.append(ol);
  28. }
  29. stack.push(ol);
  30. }
  31. while (stack.length > level) stack.pop();
  32.  
  33. $(this).before($('<a name="section-' + i + '" />'));
  34.  
  35. $('<li>').append(
  36. $('<a />').attr('href', location + '#section-' + i)
  37. .text($(this).text()))
  38. .appendTo($(stack[stack.length - 1]));
  39. });
  40.  
  41. if (stack.length) {
  42. $('dl.toc').show();
  43. oltoc = $(stack[0]);
  44. numdigits = oltoc.children().length.toString().length;
  45. //Use a clever class name to add margin that's MUCH easier to customize
  46. oltoc.addClass("TOC"+numdigits+"Digit");
  47. dest.append(oltoc);
  48. }
  49. });
  50. })(jQuery);
Add Comment
Please, Sign In to add comment