Advertisement
fahimmurshed

HFE - Mobile toggle menu is not closing while clicking outside

Apr 10th, 2022
1,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. wp_enqueue_script('jquery');
  2.  
  3. function hfe_custom_script() {
  4.     ?>
  5.         <script type="text/javascript">
  6.             jQuery(document).ready(function($) {           
  7.  
  8.                 $( document ).click( function( e ){
  9.  
  10.                     if( 'fas fa-align-justify' != $( e.target ).attr( 'class') ) {
  11.                        
  12.                         var id = $( '.elementor-widget-navigation-menu' ).data( 'id' );
  13.  
  14.                         if( window.matchMedia( "( max-width: 767px )" ).matches ){
  15.  
  16.                             var $this = $( '.elementor-element-' + id + ' .hfe-nav-menu-icon' );
  17.                             var $selector = $this.parent().next();
  18.  
  19.                             if ( $this.parent().hasClass( 'hfe-active-menu' ) ) {
  20.  
  21.                                 var layout = $( '.elementor-element-' + id + ' .hfe-nav-menu' ).data( 'layout' );
  22.                                 var full_width = $selector.data( 'full-width' );
  23.                                 var toggle_icon = $( '.elementor-element-' + id + ' nav' ).data( 'toggle-icon' );
  24.  
  25.                                 $( '.elementor-element-' + id).find( '.hfe-nav-menu-icon' ).html( toggle_icon );
  26.  
  27.                                 $this.parent().removeClass( 'hfe-active-menu' );
  28.                                 $this.parent().attr( 'aria-expanded', 'false' );
  29.                                
  30.                                 if ( 'yes' == full_width ){
  31.  
  32.                                     $this.removeClass( 'hfe-active-menu-full-width' );
  33.                                
  34.                                     $selector.css( 'width', 'auto' );
  35.                                     $selector.css( 'left', '0' );
  36.                                     $selector.css( 'z-index', '0' );
  37.                                 }              
  38.                             }      
  39.                         }
  40.                     }
  41.                 });
  42.             });
  43.         </script>
  44.     <?php
  45. }
  46. add_action( 'wp_footer', 'hfe_custom_script' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement