BUG Don't show an empty table of contents

This commit is contained in:
Sean Harvey 2013-02-20 10:22:18 +13:00
parent 0350495d20
commit 158db9d415

View File

@ -13,14 +13,18 @@
// Remove existing anchor redirection in the url // Remove existing anchor redirection in the url
var pageURL = window.location.href.replace(/#[a-zA-Z0-9\-\_]*/g, ''); var pageURL = window.location.href.replace(/#[a-zA-Z0-9\-\_]*/g, '');
var itemCount = 0;
$('#content-column h1[id], #content-column h2[id], #content-column h3[id], #content-column h4[id]').each(function(i) { $('#content-column h1[id], #content-column h2[id], #content-column h3[id], #content-column h4[id]').each(function(i) {
var current = $(this); var current = $(this);
var tagName = current.prop("tagName"); var tagName = current.prop("tagName");
if(typeof tagName == "String") tagName = tagName.toLowerCase(); if(typeof tagName == "String") tagName = tagName.toLowerCase();
itemCount++;
toc += '<li class="' + tagName + '"><a id="link' + i + '" href="'+ pageURL +'#' + $(this).attr('id') + '" title="' + current.html() + '">' + current.html() + '</a></li>'; toc += '<li class="' + tagName + '"><a id="link' + i + '" href="'+ pageURL +'#' + $(this).attr('id') + '" title="' + current.html() + '">' + current.html() + '</a></li>';
}); });
// if no items in the table of contents, don't show anything
if(itemCount == 0) return false;
toc += '</ul></div>'; toc += '</ul></div>';
// Table of content location // Table of content location