Ticket #9364 (closed Bug: fixed)

Opened 6 years ago

Last modified 6 years ago

toc.js not being loaded when you directly link to anchor tag

Reported by: vangheem Owned by: vangheem
Priority: major Milestone: 3.3.5
Component: JavaScript Version:
Keywords: Cc:

Description

toc.js not being loaded when you directly link to anchor tag like " http://localhost/site/page#section-5".

Stepping through the javascript, for some reason it just decides not to load the js when the anchor is present. I changed the js to be wrapped like,

(function($){
.....
})(jQuery);

and it fixed the issue of it not being loaded. Only then the js would load before the content of the page would load. Naturally, you needed to add something like,

(function($){
   $(document).ready(function(){
      .....
   });
})(jQuery);

With this, the code never gets ran for some reason; however, if you remove the "#section" from the url, it will work fine.

So I couldn't find a fix as of yet--will look more into it. It might be a jquery bug.

The issue seems to persist in Firefox and Safari. Haven't tested in other browsers.

Attachments

toc-diff.js Download (429 bytes) - added by vangheem 6 years ago.
toc-fixed.js Download (2.0 KB) - added by vangheem 6 years ago.

Change History

comment:1 Changed 6 years ago by vangheem

This only seems to be an issue with Plone 3.3. It works fine in 3.2. So far how I've been able to get it working is by moving toc.js right below jquery.js in portal_javascripts. So something between jquery.js and the original location of toc.js is screwing the ready call up for this script--really odd. I'll keep digging....

comment:2 Changed 6 years ago by wichert

  • Priority changed from minor to major

comment:3 Changed 6 years ago by vangheem

So it seems like somehow form_tabbing.js is the culprit. Once you move toc.js above form_tabbing.js in portal_javascripts, it works. Yet, it doesn't bring you down to the correct anchor. Also, had to do a few mods to toc.js to make it work this way yet. Most notably are wrapping the code in the jquery ready call and such. Also, had to change,

        $('dl.toc').show();

to

        $('dl.toc').css({'display' : 'block'});

for some odd reason jquery wan't doing what it was supposed to do there.

still working on it...

Changed 6 years ago by vangheem

Changed 6 years ago by vangheem

comment:4 Changed 6 years ago by vangheem

The best I can do to offer a fix for this right now is to simply move toc.js above form_tabbing.js and use the modified version of toc.js I attached here. Ended up adding a scroll js statement so it actually moves to the selected anchor.

comment:5 Changed 6 years ago by mj

The need to move the file and the need to use .css({'display' : 'block'}) both smell distinctly fishy. Could you try and upgrade jQuery to the latest instead and see what happens? Also, could you use unified diffs when uploading patches? :-)

I'll need to find some 10% time to debug this properly.

comment:6 Changed 6 years ago by vangheem

  • Owner changed from mj to vangheem
  • Status changed from new to assigned

comment:7 Changed 6 years ago by vangheem

  • Status changed from assigned to closed
  • Resolution set to fixed

(In [32066]) added scroll to anchor tag in toc.js because when you linked to an anchor tag, firefox would firefox would not bring you to that anchor. Closes #9364

comment:8 Changed 6 years ago by psol

quick questions:

  1. are you planning to merge this with the plone.app.javascript copy and with the 4.0 branch?
  1. did you test the code outside of firefox, with and without hash tags?

comment:9 Changed 6 years ago by dunlapm

(In [33261]) Check for existance of a hash in the location before attempting to scroll to that location in toc.js. Fixes bug introduced in r32066, and refs #9364

comment:10 Changed 6 years ago by dunlapm

(In [33262]) Check for existance of a hash in the location before attempting to scroll to that location in toc.js. Fixes bug introduced in r32066, and refs #9364. Ports r33261.

Note: See TracTickets for help on using tickets.