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
Comment | File | Size | Author |
---|---|---|---|
#7 | 2147159-7.patch | 934 bytes | chishah92 |
Comments
Comment #1
mehrpadin CreditAttribution: mehrpadin commentedHey there,
Please try the development release with the master branch of the library.
Comment #2
nkat2112 CreditAttribution: nkat2112 commentedGreetings 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
Comment #3
nkat2112 CreditAttribution: nkat2112 commentedPardon 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
Comment #4
mehrpadin CreditAttribution: mehrpadin commentedYou're welcome :)
Comment #5
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration commentedChanging 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.
Comment #6
chishah92 CreditAttribution: chishah92 at Blisstering Solutions commentedComment #7
chishah92 CreditAttribution: chishah92 at Blisstering Solutions commentedAdded the suggested changes.
Thanks!
~Chirag
Comment #8
cobasa CreditAttribution: cobasa commentedThanks! 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