Advertisement
Guest User

Sharepoint TOC

a guest
Jan 22nd, 2014
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- SharePoint WIKI Table of Contents. Sunnyape, August -->
  2.  
  3. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  4.  
  5. <script type="text/javascript">
  6. function hideTOC() {
  7.  document.getElementById("theTOC").style.display = 'none';
  8.  document.getElementById("show").style.display = 'block';
  9.  document.getElementById("hide").style.display = 'none';
  10. }
  11. </script>
  12. <script type="text/javascript">
  13. function showTOC() {
  14.  document.getElementById("theTOC").style.display = 'block';
  15.  document.getElementById("show").style.display = 'none';
  16.  document.getElementById("hide").style.display = 'block';
  17. }
  18. </script>
  19.  
  20. <div id="wikiTOC">
  21. <table style="padding: 5px;"><tr>
  22.  <td><div class="TOCheader">Table of Contents</div></td>
  23.  <td>
  24.   <div class="closehide" id='hide'>[<a href='#' title='Click to hide' onClick="hideTOC()">hide</a>]</div>
  25.   <div class="closehide" id='show'>[<a href='#' title='Click to show' onClick="showTOC()">show</a>]</div>
  26.  </td>
  27. </tr></table>
  28. <div id='theTOC'>
  29. <script type="text/javascript">
  30. $(document).ready(function(){
  31.  var L2=0, L3=0, L4=0;
  32. $(".ms-wikicontent h1, .ms-wikicontent h2, .ms-wikicontent h3, .ms-wikicontent h4").each(function(i){
  33. theLevel=$(this).get(0).tagName;
  34. if (theLevel=="H2") {
  35.    L2=L2+1;
  36.    L3=0;
  37.    L4=0;
  38.    theLevelString=""+L2;
  39.    }
  40.   else if (theLevel=="H3") {
  41.    L3=L3+1;
  42.    L4=0;
  43.    theLevelString=""+L2+"."+L3;
  44.    }
  45.   else {
  46.    L4=L4+1;
  47.    theLevelString=""+L2+"."+L3+"."+L4;
  48.    }
  49.   $(this).attr("id", "heading_" + i);
  50.   $("#theTOC").append("<a href='#heading_" + i + "' title='" + theLevel + "'>" + theLevelString + " " + $(this).text() + "</a><br />");
  51.  });
  52. });
  53. showTOC();
  54. </script>
  55. </div>
  56. </div>
  57.  
  58. <style>
  59. #wikiTOC {border: 1px black dashed; background-color: whitesmoke; float: left; padding: 10px; padding-top: 0px;}
  60. #wikiTOC .TOCheader {font-size: 1.1em; font-weight: bold; text-align: center; padding: 5px;}
  61. #wikiTOC .closehide {font-size: 11px; font-weight: normal;}
  62. #wikiTOC a[title=H2] {font-size:12px; font-weight: normal;}
  63. #wikiTOC a[title=H3] {font-size:11px; font-weight: normal; margin-left: 8px;}
  64. #wikiTOC a[title=H4] {font-size:10px; font-weight: normal; margin-left: 16px;}
  65. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement