List page contents at the top of the page

If you have questions about using mojoPortal, you can post them here.

You may want to first review our site administration documentation to see if your question is answered there.

This thread is closed to new posts. You must sign in to post in the forums.
1/12/2011 9:32:39 PM
Gravatar
Total Posts 12

List page contents at the top of the page

Is there a way to list the different modules that are on a page at the top of the page, preferably hyperlinked? I am looking for something like a table of contents at the top of the page.

I have done something like that by using a single HTML content module and using anchor tags and hyperlinks, but that requires a lot of manual maintenance.

So, for example, a page might have 5 HTML content modules. What I would like to enable at the top of the page is a list of the titles of all 5 content modules that hyperlink to the actual content. This might have the same style as the child pages menu.

Any ideas?

SA.

1/12/2011 10:14:54 PM
Gravatar
Total Posts 2239

Re: List page contents at the top of the page

Hi,

I have done this in the past with a bit of jQuery. This basically grabs each h2 element with a moduletitle class and then lists those elements in an unordered list above your content. 

<style type="text/css">
#toc .ModuleEditLink{visibility: hidden; display: none;}</style>
<script type="text/javascript">
        $(document).ready(function() {
            var items = "<ul>";
            $("h2.moduletitle").each(function(i) {
                var current = $(this);
                current.attr("id", "title" + i);

                items += "<li><a id='link" + i + "' href='#title" + i + "' title='" + current.attr("tagName") + "'>" + current.html() + "</a></li>";
            });
            items += "</ul>";
            $("#toc").append(items);
        });
</script><p id="toc">
    On this page:</p>

Hope this helps,
Joe D.

1/14/2011 9:28:41 AM
Gravatar
Total Posts 2239

Re: List page contents at the top of the page

I finally remembered where I got this from. I adapted the code a bit to render a list but the concept rightfully belongs to Janko Jovanovic. http://www.jankoatwarpspeed.com/post/2009/08/20/Table-of-contents-using-jQuery.aspx

You must sign in to post in the forums. This thread is closed to new posts.