'Back to top' feature
mishhh - February 23, 2007 - 19:43
| Project: | Table of Contents |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | AlexisWilke |
| Status: | closed |
Description
I don't know how to remove the other duplicate feature request.
There would be of much help if in front of every h2 and h3 tags was a picture of some kind with a link "Back to top" or "Back to Table of contents". In this way, the user would go fast back and forth between the content and table of contents.
It will be a nice addition to this module. I love what this module does, and it would be of much help if an option would be added to provide this feature.
At present moment, I use the patched version of table of contents for drupal 5.0. The modification will be available for 5.0 version too?

#1
Duplicate of #122064.
#2
Edited wrong ticket...
#3
Done!
That could be good. I would suppose that one should also be added to the very end of the page, with additional links inserted above each header. Would it make sense to make an option per page so that shorter pages wouldn't render the links?
Yes. Within the next week or two hopefully I'll have the time to set up a 5.0 installation to develop against.
#4
I guess putting "Back to top" links at the left of the headers would be nicer. Maybe i didn't understand what you mean by "additional links inserted above each header". But everywhere will do.
Anyway, It would be nice to have some checkboxes in the settings page to permit users to choose these links. Maybe some users would not want to put this "Back to top links"
And yes, one "Back to top" link should be placed at the end of the article too. it didn't cross my mind until you said it.
#5
#6
This feature should be a seperate module I think.
#7
No, I think it should be an optional feature in this module.
It'd also be kinda cool if the headers were numbered with the same numbers as the ToC (again, as an option). It'd be even nicer if you could choose either the header numbering, or the ToC, or both.
#8
Oops, my comment is a duplicate of http://drupal.org/node/144595
#9
I needed this feature, and I already was implementing jQuery on my page to use the LocalScroll plugin with my table of content, so I found that this can be done easily with a little jQuery:
$(document).ready(function() {
$("h2, h3").after("<p class=\"top\"><a href=\"#header\">back to top</a></p>");
//$('.toc-list > ol > ol > li, .top').localScroll( { hash : true } ); to apply LocalScroll (jquery update needed)
});
Having a checkbox in the admin to activate LocalScroll and packaging it with the module would be really cool!
#10
Here is a patch against the D5 version. It still needs settings to control what heading levels to add "Back to top" links, so I won't commit it or do a D6 patch until 296171: Change Defaults? lands.
It includes LocalScroll, and gracefully degrades if jquery_update isn't installed on Drupal 5. After this is committed, the README will need to be updated to indicate jquery_update as a useful module.
--Andrew
#11
#12
Just wanted to say, I was looking for this too. It will be great!
I am on 6.6 for the record
#13
deviantintegral's patch works for me - thanks for that - but the "back to top" link appears in teaser lists. Just to let you know in case you want to change this before committing.
#14
yes, I have added the patch as well. works well, but like freatida said it shows in teasers as well as no configuration options for which header tags to show it on. That was mentioned previously as well.
#15
Here is a very lightly tested patch which should respect *global* settings for inserting the back to top links. I discovered that while Zen and other Drupal themes include a CSS class for teasers, Garland doesn't, so I'm going to have to do it through hook_nodeapi(). I'm going to leave this as postponed until #191683: prevent toc from appearing in teaser lists is committed. If you're interested in this issue, please head over there and test the posted patches.
Thanks!
#16
Haven't tested the latest patch yet, but I forgot to mention that along with specifying heading levels, there should also be an option to only show "back to top" link on nodes which have a table of contents. As it is, the back to top link is appearing on all headers, regardless.
#17
I'll do a version of that for 3.x-dev and it will be in PHP. That way we can make sure it uses it only if the table of content is created.
Thank you.
Alexis Wilke
#18
This is done in 3.x-dev. FYI, I'm not going to port that back to v5.x. It is time for you to move forward anyway!
Thank you.
Alexis Wilke
#19
Thanks for the addition in the latest alexis. I will be testing for sure. I will post back if there are any issues.
#20
Hey Alexis, I'm glad this feature got committed, and yeah much better to do it in php, because it'll work with JS disabled. I mentioned it might be nice to have LocalScroll as an option included with this module and deviantintegral's patch included LocalScroll, is this a feature you are still considering?
#21
ipwa,
Ah! I did not notice the local scroll feature. Does that make the screen scroll back to the top with jQuery?
It could be neat, but I'll put a flag to turn the feature ON or OFF because for large pages it could be real slow.
Thank you.
Alexis
#22
Alexis,
Thanks again for your work on this, just thought I would chime in to say what localscroll does. It does anchor navigation using jQuery animation.
http://demos.flesler.com/jquery/localScroll/
It is a nice feature and I would be interested in it too.
--
Nicholas
#23
Nicholas,
Thank you for the link! Nice demo! That's a crazy feature! Definitively need to have a flag to turn it off!!!
Alexis
#24
Okay. That's done. Let me know if you have a problem and reactivate this issue if so.
Thank you.
Alexis Wilke
#25
This is an example of how I implemented LocalScroll with table of content: http://forestry.spring-php.com/about/grant
I did this when I posted my first comment of the thread: http://drupal.org/node/122064#comment-971086
#26
So what you're saying is that what I have now does not satisfy you?
I would think it would be easy to get the back to top right after the header and/or at the end of a paragraph (before the next header)
And it seemed logical to go back to the existing TOC instead of some random #<name> since we cannot be sure it will be present in all themes. However, we could offer the user a way to enter the name of the anchor to use in their back to top link. Then you could use #header as you do now.
Is the numbering from v1.3? 8-)
Thank you.
Alexis Wilke
#27
Okay, I did another update to you can set where you want the back to top links (i.e. right after the headers or after the paragraph.)
Let me know if that works for you.
You'll have to tweak your CSS, eventually, so it looks better for your theme.
Thank you.
Alexis Wilke
#28
Not at all, I really appreciate you are maintaining this module, thanks for your contributions :)
I just wanted to show an example of this module working with LocalScroll.
Thank you!
Nicolas
#29
Oh and sorry for commenting in a fixed issue :p
#30
ipwa,
Okay. I now added the support of the anchor. So you can enter "header" in the setup to go back to the top of the screen instead of the top of the TOC. Let me know if you are still missing something. 8-)
Thank you.
Alexis Wilke
#31
Automatically closed -- issue fixed for 2 weeks with no activity.