Okay
  Public Ticket #1465472
Javascript Withemes function
Closed

Comments

  • margr started the conversation

    Hello!

    I need to overwrite this function from main.js file in my child theme, because I have included my logo with id: "enlace-ppal-home" in the mobile menu, and I want to click on logo to access homepage, but when I click on it, it slides up as a back to top.

    WITHEMES.mobile_menu = function() {
        // document click
        $(document).on('click',function(e){
            if (matchMedia('(max-width: 979px)').matches) { // desktop size
                var target = e.target;
                if (!$(target).is('#toggle-menu') && ($(target).closest('#toggle-menu').length == 0) && ($(target).closest('#wi-mainnav').length == 0) ) {
                    $('#wi-mainnav').slideUp('fast','easeOutExpo');
                }
            }
        }); // click }

    In my functions.js file I write this: 

    jQuery('#enlace-ppal-home').on('click',function(e){
                
        document.location.href=e.currentTarget.href;
                
    });  

    When I click on logo, the page slides up before go to url. Could you help me to override the slide up? 

    Thanks in advance!

    Best regards,
    Marina.

  •  177
    John replied

    Hi Margr,

    The main.js file is not used in the theme right now.

    The general procedure to override the default one with yours would be do dequeue and then queue yours in the functions.php file.

    Take a look at:

    fox \ functions.php file line 428

    That is the JS file in use by the theme.

    What you can do is in your child theme's functions.php file you can create a similar function - wi_scripts - to dequeue and enqueue your child theme's version of the JS file.

    Then connect that function with and action like on line 322 in fox \ functions.php so that its ran when the site theme is being initialized.

    These might help with the adding and removing of that JS file:

    https://wordimpress.com/removing-styles-scripts-from-your-wordpress-parent-theme/
    https://premium.wpmudev.org/blog/adding-scripts-and-styles-wordpress-enqueueing/

    Hope you can work it from there.

  • margr replied

    Thanks John,

    Finally I solved it with this code in my JS functions:

    $(document).on('click',function(e) {
    
        if (matchMedia('(max-width: 979px)').matches) {
            var target = e.target;
                    
            //Stop animation on wi-mainnav (scroll up)
            if ( $(target).is('#enlace-ppal-home') )  {         
                                     $('#wi-mainnav').stop();
            }
        }
    });


    Ticket can be closed, thank you.

    Regards,
    Marina.