Skip to content

Instantly share code, notes, and snippets.

@TimoStahl
Last active March 10, 2016 10:57
Show Gist options
  • Save TimoStahl/ab0717db4d93e77c0cc8 to your computer and use it in GitHub Desktop.
Save TimoStahl/ab0717db4d93e77c0cc8 to your computer and use it in GitHub Desktop.
Sharepoint 2010 Wiki - Webpart - Table of Contents
<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>Automagic Table of Contents</Title>
<FrameType>Standard</FrameType>
<Description>This web part renders headlines for SharePoint 2010 wiki pages. (by Timo Litzbarski)</Description>
<IsIncluded>true</IsIncluded>
<ZoneID>Bottom</ZoneID>
<PartOrder>1</PartOrder>
<FrameState>Normal</FrameState>
<Height />
<Width />
<AllowRemove>true</AllowRemove>
<AllowZoneChange>true</AllowZoneChange>
<AllowMinimize>true</AllowMinimize>
<AllowConnect>false</AllowConnect>
<AllowEdit>false</AllowEdit>
<AllowHide>true</AllowHide>
<IsVisible>true</IsVisible>
<DetailLink />
<HelpLink />
<HelpMode>Modeless</HelpMode>
<Dir>Default</Dir>
<PartImageSmall />
<MissingAssembly>Cannot import this Web Part.</MissingAssembly>
<PartImageLarge>/_layouts/images/itdl.gif</PartImageLarge>
<IsIncludedFilter />
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
<![CDATA[<script src=http://code.jquery.com/jquery-latest.js type=text/javascript></script>
<script type=text/javascript>
$(function(){
function t(){
$("#tl_toc").empty();
$("h1, h2, h3, h4").each(function(i) {
var current = $(this);
var space = "";
switch (current.prop("tagName")) {
case "H2":
space = "&emsp;";
break;
case "H3":
space = "&emsp;&emsp;";
break;
case "H4":
space = "&emsp;&emsp;&emsp;";
break;
}
current.attr("id", "title" + i);
$("#tl_toc").append(space + "<a id='link" + i + "' href='#title" + i + "'>" + current.text() + "</a><br>");
});
}
ExecuteOrDelayUntilScriptLoaded(t,"sp.js")});</script>
<div id="tl_toc"></div>]]>
</Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment