Reputation: 11
First time I ask a question here so I do apologize in advance if I am not doing it correctly.
I am getting this error:
TypeError: s is undefined
when I click my toggle menu that appears on devices smaller than 1020px.
I am using superfish for the toggle menu and worked fine until I added a new JS file in my directory and registered and enqueued it in my function.php.
I have to click twice for the menu to toggle down and that is why I checked my firebug console for errors.
Update after Adam's comment: In Chrome Console I am getting this message: "Uncaught TypeError: Cannot call method 'replace' of undefined" in my superfish.min.js file. Not sure how I find the line when it is .min file. However I find this line in the .min file. {return s.replace(/display[^;]+;?/g,"")}
Here is the code I am using for the menu.
jQuery(document).ready(function($) {
if( $('.mobile-primary-toggle').length || $('.mobile-secondary-toggle').length ) {
if(dynamik_sf_enabled) {
var sf = $('ul.js-superfish');
}
$('.responsive-primary-menu-container').click(function() {
if(dynamik_sf_enabled && dynamik_reveal_sub_pages) {
sf.superfish('destroy');
}
$('.nav-primary').slideToggle();
$('#nav').slideToggle();
});
$(window).resize(function() {
if(dynamik_sf_enabled && dynamik_reveal_sub_pages) {
if(window.innerWidth <= media_query_small_width) {
sf.superfish('destroy');
} else {
sf.superfish('init');
}
}
if(window.innerWidth > media_query_small_width) {
$('.nav-primary').removeAttr('style');
$('#nav').removeAttr('style');
}
});
}
});
Any suggestions on how to fix this?
Upvotes: 0
Views: 3941
Reputation: 127
Fix is very simple indeed for wordpress ...
Get here : https://wordpress.org/plugins/enable-jquery-migrate-helper/
Click on it and from dropdown choose legacy version .. Check screenshot.
I hope this will help you to solve your issue ....
Upvotes: 0
Reputation: 145
Take the $(window).resize(function() { out of the if statement and outside the ready function; because resizing a window can happen anytime and it rely's on sf having a value.
$.(function(){
$(window).resize(function() {
if(dynamik_sf_enabled && dynamik_reveal_sub_pages) {
if(window.innerWidth <= media_query_small_width) {
sf.superfish('destroy');
} else {
sf.superfish('init');
}
}
if(window.innerWidth > media_query_small_width) {
$('.nav-primary').removeAttr('style');
$('#nav').removeAttr('style');
}
});
});
Upvotes: 0