Javascript error in tableheader.js: $("td" + location.hash).offset() is undefined

markus_petrux - April 12, 2009 - 04:34
Project:Drupal
Version:7.x-dev
Component:javascript
Category:bug report
Priority:critical
Assigned:Unassigned
Status:duplicate
Issue tags:JavaScript
Description

Hi,

The following piece of code in tableheader.js causes javascript error $("td" + location.hash).offset() is undefined when a hash is present in the URL that has no relation with table cells.

      if (prevAnchor != location.hash) {
        if (location.hash != '') {
          var scrollLocation = $('td' + location.hash).offset().top - $(e).height();
          $('body, html').scrollTop(scrollLocation);
        }
        prevAnchor = location.hash;
      }

The error happens when the selector 'td' + location.hash does not match any element. In that case, offset().top is undefined.

I think it could be fixed by adding a condition like this:

      if (prevAnchor != location.hash) {
        if (location.hash != '' && $('td' + location.hash).size()) {
          var scrollLocation = $('td' + location.hash).offset().top - $(e).height();
          $('body, html').scrollTop(scrollLocation);
        }
        prevAnchor = location.hash;
      }

I'm making the issue critical because this issue causes javascript errors when a hash is present in the URL that does not match a TD identifier. This javascript error breaks all the javascript present in the site, including ads, analytics, etc.

Please, consider backporting this fix to D6 too.

#1

markus_petrux - April 12, 2009 - 15:21
Version:6.x-dev» 7.x-dev
Status:active» needs review

I guess this probably needs to be fixed first in dev. Attached patch against HEAD.

AttachmentSizeStatusTest resultOperations
tableheader-431342-1-D7.patch775 bytesIdleFailed: Failed to apply patch.View details | Re-test

#2

System Message - April 12, 2009 - 15:35
Status:needs review» needs work

The last submitted patch failed testing.

#3

markus_petrux - April 12, 2009 - 15:47
Status:needs work» needs review

wow! and now? Why the patch failed?

hmm... adding -p option to the diff command to see if that helps.

AttachmentSizeStatusTest resultOperations
tableheader-431342-3-D7.patch811 bytesIdleFailed: Failed to apply patch.View details | Re-test

#4

System Message - April 12, 2009 - 15:56
Status:needs review» needs work

The last submitted patch failed testing.

#5

markus_petrux - April 12, 2009 - 16:05

hmm... this is kind of frustrating, isn't it? All you can see here is that the patch fails, but it doesn't tell you why.

I hate to turn this into a support question, but can someone drive me in the correct direction?

#6

markus_petrux - April 13, 2009 - 11:12
 
 

Drupal is a registered trademark of Dries Buytaert.