0

I've stumbled upon a issue that i can't fix.

I've implemented a autocollapse menu ..all works fine UNTILL i go to mobile version where the wp core's menu bugs out with my menu js code.

Basicly i have a js file that contains the auto-collapse menu code and would like to run this bit

$('#adminmenuwrap, #adminmenuback').mouseenter(function() { expandIt($adminMenuWrap); }); 
    $('#wpcontent , .box').mouseenter(function() { collapseIt($adminMenuWrap); });
    $('img').load(function($){collapseIt($adminMenuWrap);});      
    });   

ONLY if you are NOT in mobile version.

fiddled around with if (wp_is_mobile() ) {} function but doesn't work.

Please guys help me fix this cuz it's giving me headakes. Thanks in advance and have a nice day!

Entire JS file :

    /* Display and echo mobile specific stuff here */

// MyDash Collapse Menu
jQuery(document).ready(function($) {

    // Defineste functii
    $adminMenuWrap = $('#adminmenuwrap');
    var collapseIt = function($adminMenuWrap) {
        if ( !$(document.body).hasClass('folded') ) {
            $("#collapse-menu").trigger('click');
            $(document.body).toggleClass('expanded');
        }
    };

    var expandIt = function($adminMenuWrap) {
        adminMenuWrap = $('#adminmenuwrap');
        if ( $(document.body).hasClass('folded') ) {
            $("#collapse-menu").trigger('click');
            $(document.body).toggleClass('expanded');
        }
    }




     if ($(window).width() > 768){
    // here's the magic
    $('#adminmenuwrap, #adminmenuback').mouseenter(function() { expandIt($adminMenuWrap); }); 
    $('#wpcontent , .box').mouseenter(function() { collapseIt($adminMenuWrap); });
    $('img').load(function($){collapseIt($adminMenuWrap);});      
    });    
     }


// Customizer
jQuery(document).ready(function($) {

    $(".boxes").mouseenter(function() {
        if ( $('.wp-full-overlay').hasClass('collapsed') ) {
            $(".collapse-sidebar").trigger('click');
        }
    });

    $("#customize-preview").mouseover(function() {
        if ( $('.wp-full-overlay').hasClass('expanded') ) {
            $(".collapse-sidebar").trigger('click');
        }
    });

});    
7
  • explain what doesn't work and what append, what is shown
    – mmm
    Commented Jul 27, 2015 at 21:40
  • You could just try if ($(window).width() < 768) to detemine if you want to run the code Commented Jul 27, 2015 at 21:47
  • @mmm it simply stops autocollapsing without any error Commented Jul 27, 2015 at 22:05
  • @czerspalace still no result Commented Jul 27, 2015 at 22:06
  • 1
    Are your braces matched up correctly? What if you move the width check inside the mouseenter functions (and 768 was just an arbitrary number, you may need to change that) Commented Jul 27, 2015 at 22:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.