user3501825
user3501825

Reputation: 11

TypeError: s is undefined - Superfish On WordPress site

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

Answers (2)

Ashik Mahmud
Ashik Mahmud

Reputation: 127

Fix is very simple indeed for wordpress ...

  1. Install Enable jQuery Migrate Helper plugin and enable it

Get here : https://wordpress.org/plugins/enable-jquery-migrate-helper/

  1. Then enter your Wordpress Admin and Go to Tools Menu item from left side. In where you will see jquery migrate as submenu.

Click on it and from dropdown choose legacy version .. Check screenshot.

I hope this will help you to solve your issue ....

jQuery Migrate Helper configuration screenshot

Upvotes: 0

Mr. Butterworth
Mr. Butterworth

Reputation: 145

  1. Make sure sf always has a value, this is the issue.
  2. 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

Related Questions