Greetings to all.

In a simple, non-nested superfish menu that is configured with the "NavBar" menu type (as opposed to the default "Horizontal", which appears to introduce an accordion-styled menu when the screen width becomes too small [i.e., mobile]), the following error might be observed when refreshing any of the site pages:

TypeError: fontsize.attr(...).appendTo(...)[0] is undefined

at line 39 of sites/all/libraries/superfish/supersubs.js, which is the following line:

.appendTo($$)[0].clientWidth; //clientWidth is faster than width()

It appears, in this case, that the $$ result set does not contain at least one item, is consequently not an array, and the appendTo method is unable to append anything to it (the target). Consequently, the subsequent [0] reference against it results in undefined. This raises an exception when the clientWidth property is invoked on undefined.

I observed that following snippet of code just a few lines prior to this issue:

      // Jump on level if it's a "NavBar"
      if ($$.hasClass('sf-navbar')) {
        $$ = $$.children('li').children('ul');
      }

(I think 'on' in the comment was supposed to read 'one', but that doesn't matter.) Changing it to the following seemed to resolve the issue, but I'm not sure how safe this change is:

      // Jump on level if it's a "NavBar"
//      if ($$.hasClass('sf-navbar')) {
//        $$ = $$.children('li').children('ul');
//      }

      if ($$.hasClass('sf-navbar') && $$.children('li').children('ul')[0]) {
        $$ = $$.children('li').children('ul');
      }

I decided to make this change in my local code base because it's obvious $$ needs to contain a query set of at least one element. But please point out any errors in my assumptions, if you'd be so kind.

Many thanks,
Nick

CommentFileSizeAuthor
#7 2147159-7.patch934 byteschishah92
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mehrpadin’s picture

Hey there,

Please try the development release with the master branch of the library.

nkat2112’s picture

Greetings to you, Mehrpadin!

Thank you so much for your very helpful response. Using the development release and the master branch of the library fixed everything.

Thanks so much!
Nick

nkat2112’s picture

Pardon me, Mehrpadin.

I've made an error in my earlier response. I'm still seeing this issue. However, using your latest code has taken care of other matters particularly pertaining to responsive design and narrow browser windows - so I'm really excited about that. Thanks. Given this error that I'm discussing here, I've re-introduced the little if-statement tweak I mentioned earlier and all is fine.

If you'd like me to do any testing with any other variations, please let me know. I'm all fine here with things as they are.

Many kind thanks again,
nkat2112

mehrpadin’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)

You're welcome :)

jacob.embree’s picture

Version: 7.x-1.9 » 7.x-2.0
Category: Support request » Bug report
Status: Closed (works as designed) » Active

Changing status and version because this is still an issue in superfish-7.x-2.0. Changing to "Bug report" because the plugin should be able to be benign even with only a single menu entry.

I believe that .appendTo($$)[0].clientWidth; //clientWidth is faster than width() is assuming that [0] is the first result. jQuery.first() accomplishes the same thing regardless of the number of results, so I recommend changing that line to
.appendTo($$).first().clientWidth; //clientWidth is faster than width()
That solves the problem for me.

chishah92’s picture

Assigned: Unassigned » chishah92
chishah92’s picture

Assigned: chishah92 » Unassigned
Status: Active » Needs review
FileSize
934 bytes

Added the suggested changes.

Thanks!
~Chirag

cobasa’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! I can confirm patch at #7 is working.
Tested on a clean install Drupal 7.69, Superfish 7.x-2.0, patched library Superfish-for-Drupal-1.x