Show/hide for non-javascript users
ozzin - February 21, 2009 - 16:32
| Project: | Table of Contents |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | AlexisWilke |
| Status: | closed |
Description
Users that do not have Javascript enabled will still see the 'hide' link in the table of contents, but the link will do nothing. It should either not be there for non-JS users, or it should link back to the page with the table of contents collapsed/expanded. The first option seems more desirable.

#1
This patch removes the creation of the 'hide' link from the module and moves it to the tableofcontents.js file. That way, users that do not have Javascript enabled will never see the link. If this is to be combined with one of the previous ideas of having show/hide being optional, one would need to set a javascript variable and then check this before creating the link.
#2
Done in 3.x-dev. Although what I do is show the link if jQuery is available instead.
Thank you.
Alexis Wilke
#3
Am I right in thinking that the link is still being created in HTML, but is now hidden in CSS and then revealed in JavaScript? If so, this will still not work for users that are not using a CSS-enabled browser, such as Lynx or other text browsers. It may also create problems for accessibility-oriented browsers, though I don't know much about these. This is why the original patch does not create the link through HTML at all: since it's a link that is *only* used if JS is enabled (assuming that this is still the case), it may as well be entirely created through JS, thereby avoiding any issues with any types of browsers.
Using the idea in the original patch, you just have to supply a variable from PHP to JS to say whether 'hideshow' is set to true or not, and then create the link as before if it is set to true.
Best wishes,
ozzin
#4
ozzin,
Indeed.
Could you tell me how I could best make this work... I have a flag to make the TOC appear hidden (closed) by default. Do you think that should also be done in Javascript?
I guess it should go like this:
* HTML includes the title + list.
* Add a small <script>...</script> that sets a variable to know whether the table should be closed and whether the hide/show link should be shown.
* Javascript is run and (1) hides the table if marked that way, (2) add the hide/show link.
Thank you.
Alexis
#5
Okay. That should now be fixed. The hide/show labels can be defined in Javascript with Drupal.t() for translation.
Let me know if you still see a problem and reactivate the issue if so.
Thank you!
Alexis Wilke
#6
Automatically closed -- issue fixed for 2 weeks with no activity.