It appears that the TOC is not generated when an alternative URL path is added to a story. It shows up when the story is previewed (because the alternative URL is not used) but then disappears when it is posted.

Comments

Ignas’s picture

Yes, this script is not url frendly :)
Just remove 5-8 lines from the script:
var url = location.href;
if (url.indexOf('node/') == -1) {
return;
}

I do not understand puspose of that bus script works then.

droopy’s picture

That worked for the stories with alternative urls, but on my site it left a toc box before the first article on the frontpage.

nedjo’s picture

We need some way to restrict this behaviour to given pages. The current test for node/ is weak. We could improve it by enclosing the node body in a div with a given ID using the _nodeapi hook (only if we were on a node page, (arg(0)== 'node'). Doing so might also be useful to other modules, e.g., edit in place, and so might be best to put in jstools.module.

cracky@thealphasite.org’s picture

StatusFileSize
new3.83 KB

Hi, this is my first contribution.

I've modified the TOC script so it detects if you are inside of a node or into a listing by checking for the existance of the "read-more" class wich may not always work (if you've got a listing in wich none of the nodes is summarized) but wich anyhow usually works ... need to find a better way though.

In addition I've added a recursive mechanisim to list not only the H2 headers but also the subheaders (meaning H3, H4 an so on) to make a nested ordered list. The script itself got two global variables named "InitLevel" and "EndLevel" wich define the start tag (2 meaning H2, 3 meaning H3 and so on) and the endtag (both included). If you define InitLevel as, for example, 2 and EndLevel as 4 (wich I have left as default values) and no H2 tag is found then the script will look for H3 tags and root the TOC in that tags, if no H3 are found the it wiil look for H4 and so on to the EndLevel.

I've got it working on my site The Alphasite and there's a goog example at this article

Hope you find it useful.

cracky@thealphasite.org’s picture

StatusFileSize
new4.48 KB

I've (painfully) discovered that IE won't handle the element.setAttribute correctly so the previous script will display the toc but will not have working anchors to jump to the header sections. I've found a nice function on Death to bad DOM Implementations wich fixes the problem so here's the updated script.

nedjo’s picture

Very nice! This is what I had in mind when I first roughed this module in, but I haven't returned to do anything with it since then. Thanks for posting this contribution.

A few comments on the approach:

1. The global variables would be better passed in via user-configurable settings as

jstools.tocInitLevel = 3;
jstools.tocEndLevel = 5;

See the way this is done in other jstools modules, e.g., collapsiblock_defaults() and its menu item. We would

2. Testing for the 'read-more' class is clever but not infallible. We may need to pass a setting from the server indicating we are on a node page. E.g., we could use _nodeapi to append an element to the node body.

3. I don't want to add getElementsByClass just for this usage. (If we did add it, it would be to jstools.js.) I intend to refactor to use the jQuery library, which will render this sort of function unnecessary. Meantime I'd prefer a traditional approach of iterating through getElementsByTagName('a') with hasClass.

4. I suspect we should be able to use the ProcessTocFor() function for the initial h level as well as subsequent ones, avoiding code duplication.

Altogether a nice addition that I'd be happy to add. I'm not likely to find time soon to make these changes to the patch though. Might you be able to?

cracky@thealphasite.org’s picture

Ok, I hadn't really looked the jstools script so I didn't know there was a way to set global variables. I'll take a look at it. I'll think I'll begin by refactoring the code (wich indeed you're right and it's duplicated) then insert the globals as configurable variables, then the substitution for getElementByClass and finally use the _nodeapi to hint the script about where to showup.

I'm a complete newby to the drupal modules (and I don't even have a clear idea of how the CVS works) so it may take a while til it's finished. For the time being anyway the script might do the work for anyone wich can't wait until I get it working.