MyBB Community Forums

Full Version: Table of Contents within Post?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I just have a questions about this. I don't know if can be done or not. I have a "rule" type post in a topic. I want to make my table of contents be able to be clickable links that scroll me to the correct portion of the text. It's kind of like what pdf can do with table of contents. So navigating within side a post itself. Is it possible? Thanks!
The attachment on this post might help:

http://community.mybb.com/thread-148295-...pid1069387

Its a mycodepack made by zingaburga long ago. I have his permission to share it. Try changing compatibility and see if the anchor mycodes do what you need.
not have this codepack. clickable links that scroll me to the correct portion of the text.
install the codepack - its a plugin and adds mycodes; one of which is the anchor tag which is what you want.
/*function for table of contents */
function toc(y,d)
{
/*change below to what you need to be */
  var ToC =
  "<nav role='navigation' class='table-of-contents' >" +
  "<h2>On this page:</h2>" +
  "<ul class=\"list-group\" >";
/* end change*/ 
  var newLine, el, title, link;

  $(y).each(function()
    {

      el = $(this);
      title = el.text();
      link = "#" + el.attr("id");
/* change as well newLine */
      newLine =
      "<li class=\"list-group-item\">" +
      "<a href='" + link + "'>" +
      title +
      "</a>" +
      "</li>";
/* end change */

      ToC += newLine;

    });
/* change as well */
  ToC +=
  "</ul>" +
  "</nav>";
/* end change */
  $(d).prepend(ToC);
}

/* enter the headings for what you want to select for the links. for the id part its what you have set to be the toc.
example: toc('sector :header','#toc');
<div id='toc'></div> (toc links sent here).

btw you need to set ids for each heading for it to work tho. 
example: <h2 id='terms'>Terms</h2>
so the script takes the id and turn its into #terms while it show Terms as the title. 
/*
toc(selector,id attachted to);

just need someone to make a table of contents mycode for you and you will actually have a toc script.

i could make a bbcode but mycode is different then my parser so the way i make mine is different then mybb's parser.


you can change the script to match your design. this is based on bootstrap newest 3.0 version.

so you may have to change the formats of the headings to match mybb theme.

i commented what to change.

--------------------

i will see if i can make a code for you. i can't make no promises. its been awhile since i messed with mybb products since i started to build my own system.
so what is the difference bw bbcode and mycode?

the problem i am having is the you need to specify the headers h1-h6 mycode

by the time the headers are injected its too late for any TOC myCode since its already fired

edit: i wonder if the order of the mycode might work?