TinyPortal

Development => Support => Topic started by: mythus on March 05, 2017, 11:59:26 PM

Title: [SOLVED] Table of Contents for Articles?
Post by: mythus on March 05, 2017, 11:59:26 PM
Greetings,

I'm not sure if this is the correct forum to post this question in. My appologies if not.

I am thinking about moving over to SMF + Tiny Portal from Joomla + Kunena. Basically my site is becoming more dependant upon a forum and Kunena is lacking in that department (with no other real good ones for Joomla). SMF is the better forum IMO, and it seems like to me that TinyPortal would do a good job at replicating the rest of what I need. I have a very robust and large collection of articles on my Joomla site that I am thinking TinyPortal's categories and articles will be able to accommodate.

However, there is one thing that I'm missing in TinyPortal articles, that is a Table of Contents. Basically, the table of contents would put a table of links automatically at the top of the article linking to the various h1 to h6 tags found throughout the article. A table of contents makes it much easier to go through large articles.

I've looked around but so far I've found nothing in TinyPortal that would give me a table of contents for my articles. Does such a thing exist here, and if so could you please point it out to me?
Title: Re: Table of Contents for Articles?
Post by: WillyP on March 06, 2017, 01:04:49 AM
I'm not aware of anything made for TP but you could adapt some javascript like this: JavaScript - ToC script (http://www.quirksmode.org/dom/toc.html)
Title: Re: Table of Contents for Articles?
Post by: illori on March 06, 2017, 10:20:35 AM
since you can use html etc in TP you can create your own table of contents. even using bbc you can use the anchor tag to create the links and add to your own table of contents. there is no way to automatically create it though.
Title: Re: Table of Contents for Articles?
Post by: mythus on March 06, 2017, 02:20:12 PM
I appreciate your responses, even though those were what I was afraid you'd say. Well consider this my feature request lol :P.

Manually creating a ToC for 250 articles is not something I would look forward to doing I'm afraid. Maybe later I'd do so for the longer articles. To be fair, Joomla doesn't come with such capabilities out of the box either, someone had to make a plugin for it.

I'd so use a javascript script for generating ToC's IF I knew the correct paths for the plugins/javascript folder and the css file. I'd imagine I could put in a toc.css file in the same place as a javascript file? It has been a year since I've done any javascript and then it was very limited so I'll have to restudy it some... but javascript with a simple html call would be a lot easier than making by hand all those anchor links and such.
Title: Re: Table of Contents for Articles?
Post by: mythus on March 06, 2017, 03:53:31 PM
OK, I was able to make a javascript ToC. I should be able to easily copy/paste it into all of my articles to get a working table of contents. The only issue I am having with it is that it is pulling in everything from the page that is surrounded with header tags (<h2> to <h6>) inluding the user block, the shoutbox, etc. I'm not quite sure how to get it to skip those lol, but hey, a table of contents!
Title: Re: Table of Contents for Articles?
Post by: WillyP on March 06, 2017, 11:57:35 PM
Now that you have it working, here is a another idea.

Presumably, you are copy/pasting from your old site to the new site, or to a file. Instead, copy your article to a file, run the JavaScript in your file, and then copy the resulting source html to your new site, without the JS.

That way you will have your ToC, nothing indexed but your article, and not have the visitor have to download and run the JS every page load.
Title: Re: Table of Contents for Articles?
Post by: mythus on March 07, 2017, 12:06:48 AM
That's an interesting idea, I'll give that a try.

I did try putting the JavaScript in the theme head, but that killed the theme. I also tried using the global headers mod and putting it in there, but it wouldn't work for some reason. Seems like I have to put the script at the top of each article.
Title: Re: Table of Contents for Articles?
Post by: WillyP on March 07, 2017, 01:45:46 AM
Should probably go in the footer, but if you use my suggestion and it produces valid HTML, it doesn't matter where it goes.
Title: Re: Table of Contents for Articles?
Post by: mythus on March 07, 2017, 02:56:50 AM
As far as I know you can't put javascript in the footer. You can put it in either the head or at the end of the body just before the body closing tag. The head position is usually advised to prevent complications such as a person trying to click on a script-ran button before the script has ran. But again, my knowledge here is rudimentary at best - I only had some javascript as a module in my web programming 2 classes. I learned enough to be dangerous (as long as I remember it) but not enough to be really useful or whatever at it lol.

I wanted to try your suggestion about running it in a text editor... but sadly I don't seem to know how to do so (see above comment about not enough to be really useful). I mean, I can put it all in a text editor and save it and open it in a browser to test just fine, but I'm not sure how you'd go about getting it to output html source. Care to give me some pointers?
Title: Re: Table of Contents for Articles?
Post by: WillyP on March 07, 2017, 11:01:06 PM
You are right, I meant just before the body closing tag. The reason is to load content first, then JS. But JS will run when the browser gets to it, wherever you put it. I frequently do put a bit of JS in the page at other locations, for example a copyright that uses JS to output the current year goes in the footer.

To get the HTML source in your browser, right click and choose view source. Then select it all and copy.
Title: Re: [SOLVED] Table of Contents for Articles?
Post by: mythus on March 20, 2017, 07:14:27 PM
I never did get the whole source thing to work. It just displayed the javascript code. But that's ok, I got all the articles moved over just fine with the javascript.

I went ahead and marked the topic solved. After all, I achieved what I was asking for in this topic. Thanks for the help everyone!