List of in-topic headings? (Flare 7)

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
stephencavers
Jr. Propeller Head
Posts: 9
Joined: Tue Sep 14, 2010 1:51 pm

List of in-topic headings? (Flare 7)

Post by stephencavers »

I'm looking for a way to insert an auto-generated list of headings (H2 and lower) that are in the same topic — sort of like a mini-toc, but for the topic only. Is such a thing possible with Flare, or should I look elsewhere for a solution?
crdmerge
Sr. Propeller Head
Posts: 248
Joined: Tue Dec 16, 2008 5:37 am

Re: List of in-topic headings? (Flare 7)

Post by crdmerge »

It isn't, sorry. My enhancement request from April 2011 (to offer two mini-TOC options, one for external TOC items, another for internal headings) was not addressed in Flare 8. Perhaps if others bombarded Flare with requests, we might see a resolution? Hint, hint, hint...


Good luck,
Leon


[RH had the internal-headings-only mini-TOC several years ago.]
stephencavers
Jr. Propeller Head
Posts: 9
Joined: Tue Sep 14, 2010 1:51 pm

Re: List of in-topic headings? (Flare 7)

Post by stephencavers »

Thanks, crdmerge. That's unfortunate news. I'll have to bug one of our developers for a custom script, I guess.
LTinker68
Master Propellus Maximus
Posts: 7247
Joined: Thu Feb 16, 2006 9:38 pm

Re: List of in-topic headings? (Flare 7)

Post by LTinker68 »

Would the List-Of proxy work in this case? I haven't looked at it in awhile, but I thought you could specify the tag to use to create a list from. In this case you'd select h2. Can't remember if it allowed for selecting multiple tags in the same list. If not, then you might not be able to get lower than h2, but again, haven't looked at the feature in awhile.
Image

Lisa
Eagles may soar, but weasels aren't sucked into jet engines.
Warning! Loose nut behind the keyboard.
crdmerge
Sr. Propeller Head
Posts: 248
Joined: Tue Dec 16, 2008 5:37 am

Re: List of in-topic headings? (Flare 7)

Post by crdmerge »

You know, you're right, Lisa. I never considered that proxy!

But you can only select one tag, as you surmised. Still, that might help stephencavers.


Leon
stephencavers
Jr. Propeller Head
Posts: 9
Joined: Tue Sep 14, 2010 1:51 pm

Re: List of in-topic headings? (Flare 7)

Post by stephencavers »

In case anyone finds this useful, here's a quick-and-dirty solution that we came up with.

1. In the Windows file browser, go to your Resources folder and add a new folder named "topicTOC".

2. In the topicTOC folder, create a new text file named topicTOC.js, open it in a text editor, and paste this code:

Code: Select all

function getElements()
{
	var x=document.getElementsByTagName("h2"); // get list of H2 text
	var returnvalue = "<ul>"; // start the list
	for (var i = 0; i < x.length; i++)
	{
		// Add a list item with the heading text, linked to the numbered bookmark A NAME
		returnvalue += "<li><a href='#toc" + i + "'>" + x[i].innerHTML + "</a></li>";

		// insert a numbered A NAME in front of title
		x[i].innerHTML = "<a name='toc" + i + "' />" + x[i].innerHTML; 
	}
	returnvalue += "</ul>"; // close the list
	document.getElementById("topicTOC").innerHTML = returnvalue; // insert the string where there's an id "topicTOC"
}
3. In Flare, right-click the master page and choose Open with... > Internal Text Editor.

4. Between the <head> and </head> tags, add these lines:

Code: Select all

		<script type="text/javascript" src="../../Resources/topicTOC/topicTOC.js">
		</script>
5. Here's the kludgy bit. You need a way to start the script when the page opens, but Flare strips onload from BODY tags when you generate output. The workaround is to insert a single-pixel transparent image and put the onload element in that. Add your image just after the opening <body> tag in the master page, like this (where the one-pixel image is "spacer.png"):

Code: Select all

<img src="../Images/spacer.png" onload="getElements()" />
6. Now all you have to do is insert a placeholder where the in-topic TOC should appear. Open your topic in the Internal Text Editor, and add this DIV tag where you want your TOC to appear:

Code: Select all

<div id="topicTOC"></div>
7. Save everything and generate the webhelp. If you did everything correctly, a bullet list should appear where you put that DIV tag in any topic.
LTinker68
Master Propellus Maximus
Posts: 7247
Joined: Thu Feb 16, 2006 9:38 pm

Re: List of in-topic headings? (Flare 7)

Post by LTinker68 »

stephencavers wrote:5. Here's the kludgy bit. You need a way to start the script when the page opens, but Flare strips onload from BODY tags when you generate output. The workaround is to insert a single-pixel transparent image and put the onload element in that.
Can't you add the onLoad event to the body tag in the masterpage? That means it would load the script when each page loads, so you might want to create a second masterpage that has that onLoad event and only apply that masterpage to those topics where you insert the DIV and want the effect to appear.
Image

Lisa
Eagles may soar, but weasels aren't sucked into jet engines.
Warning! Loose nut behind the keyboard.
stephencavers
Jr. Propeller Head
Posts: 9
Joined: Tue Sep 14, 2010 1:51 pm

Re: List of in-topic headings? (Flare 7)

Post by stephencavers »

LTinker68 wrote:Can't you add the onLoad event to the body tag in the masterpage? That means it would load the script when each page loads, so you might want to create a second masterpage that has that onLoad event and only apply that masterpage to those topics where you insert the DIV and want the effect to appear.
No, as far as I can tell, you can't add an onload to the body tag in the master page; Flare will omit it in the generated HTML. As I described, you can work around that by adding the single-pixel image to the master page, and the IMG tag supports onload.
LTinker68
Master Propellus Maximus
Posts: 7247
Joined: Thu Feb 16, 2006 9:38 pm

Re: List of in-topic headings? (Flare 7)

Post by LTinker68 »

I know others have put code in the masterpage and had it filter through to the topics. Perhaps one of them will post some instructions, or you could try searching through the forums.
Image

Lisa
Eagles may soar, but weasels aren't sucked into jet engines.
Warning! Loose nut behind the keyboard.
Psider
Propellus Maximus
Posts: 902
Joined: Wed Jul 06, 2011 1:32 am

Re: List of in-topic headings? (Flare 7)

Post by Psider »

Hi all,

Just wanted to confirm whether this may have been included in V9? I've tried looking in the help and can't see anything obvious, but maybe my search-fu isn't working tonight.

If it hasn't been added I'll add my voice to the feature request database. :)

Thanks,
Amber
Post Reply