PageSourceSearch

https://igutag.com/wp-content/plugins/mobile-menu/includes/js/mobmenu.js?ver=2.8.3

js igutag.com collected 2026-09-24 14:45:06 UTC 16,173 bytes, 482 lines download raw bytes

1
2  /*
3    *
4    *   Javascript Functions
5    *   ------------------------------------------------
6    *   WP Mobile Menu
7    *   Copyright WP Mobile Menu 2018 - http://www.wpmobilemenu.com
8    *
9    */
10
11    "use strict";
12    function getSelector(el){
13      var $el = jQuery(el);
14  
15      var id = $el.attr("id");
16      if (id) { //"should" only be one of these if theres an ID
17          return "#"+ id;
18      }
19  
20      var selector = $el.parents()
21                  .map(function() { return this.tagName; })
22                  .get().reverse().join(" ");
23  
24      if (selector) {
25          selector += " "+ $el[0].nodeName;
26      }
27  
28      var classNames = $el.attr("class");
29      if (classNames) {
30          selector += "." + jQuery.trim(classNames).replace(/\s/gi, ".");
31      }
32  
33      var name = $el.attr('name');
34      if (name) {
35          selector += "[name='" + name + "']";
36      }
37      if (!name){
38          var index = $el.index();
39          if (index) {
40              index = index + 1;
41              selector += ":nth-child(" + index + ")";
42          }
43      }
44      return selector;
45    }
46
47    function enableMobileMenuElementPicker(){
48      const p = new Picker({
49          elm: document.getElementById('elm1'),
50          mode: 'cover',
51          excludeElmName: ['body'],
52          events: [{
53              key: 'contextmenu',
54              fn(event) {
55                  event.preventDefault();
56              },
57          }],
58          onInit() {
59          },
60          onClick(event) {
61            var selector = getSelector(event.target).toLowerCase();
62            window.parent.receivePickedElement(selector);
63            jQuery(selector).hide();
64          },
65          onHover(event) {
66          },
67      });
68
69      document.getElementById('m_on').addEventListener('click', () => {
70          p.on();
71      });
72
73      document.getElementById('m_off').addEventListener('click', () => {
74          p.off();
75      });
76
77      document.getElementById('m_cover').addEventListener('click', () => {
78          p.changeMode('cover');
79      });
80
81      document.getElementById('m_target').addEventListener('click', () => {
82          p.changeMode('target');
83      });
84
85    }
86    jQuery( document ).ready( function($) {
87
88      const urlParams = new URLSearchParams( window.location.search );
89
90      if ( urlParams.get( 'mobmenu-action' ) == 'find-element' ) {
91        enableMobileMenuElementPicker();
92      }
93
94      function mobmenuOpenSubmenus( menu ) {
95        var submenu = $(menu).parent().next();
96
97        if ( $(menu).parent().next().hasClass( 'show-sub-menu' )  ) {
98          $(menu).find('.show-sub-menu' ).hide();
99          $(menu).toggleClass( 'show-sub');
100        } else {
101          if ( ! $( menu ).parents('.show-sub-menu').prev().hasClass('mob-expand-submenu') && submenu[0] !== $('.show-sub-menu')[0] && $( menu ).parent('.sub-menu').length <= 0 ) {
102  
103            $(menu).parent().find( '.show-submenu' ).first().hide().toggleClass( 'show-sub-menu' );
104            $(menu).toggleClass( 'show-sub');
105  
106          }
107        }
108
109        if ( !$( menu ).parent().next().hasClass( 'show-sub-menu' ) ) {
110          submenu.fadeIn( 'slow' );
111        } else {  
112          submenu.hide();
113        }
114
115        if ( ! $('body').hasClass('mob-menu-sliding-menus') ) {
116          $( menu ).find('.open-icon').toggleClass('hide');
117          $( menu ).find('.close-icon').toggleClass('hide');
118        }
119
120        submenu.toggleClass( 'show-sub-menu');
121        
122
123      }
124
125      if ( $( 'body' ).find( '.mobmenu-push-wrap' ).length <= 0 &&  $( 'body' ).hasClass('mob-menu-slideout') ) {
126
127        $( 'body' ).wrapInner( '<div class="mobmenu-push-wrap"></div>' );
128        $( '.mobmenu-push-wrap' ).after( $( '.mobmenu-left-alignment' ).detach() );
129        $( '.mobmenu-push-wrap' ).after( $( '.mobmenu-right-alignment' ).detach() );
130        $( '.mobmenu-push-wrap' ).after( $( '.mob-menu-header-holder' ).detach() ); 
131        $( '.mobmenu-push-wrap' ).after( $( '.mobmenu-footer-menu-holder' ).detach() ); 
132        $( '.mobmenu-push-wrap' ).after( $( '.mobmenu-overlay' ).detach() ); 
133        $( '.mobmenu-push-wrap' ).after( $( '#wpadminbar' ).detach() );
134
135        if ( $('.mob-menu-header-holder' ).attr( 'data-detach-el' ) != '' ) {
136          $( '.mobmenu-push-wrap' ).after( $(   $('.mob-menu-header-holder' ).attr( 'data-detach-el' ) ).detach() );
137        }
138
139      }
140      // Double Check the the menu display classes where added to the body.
141      var menu_display_type = $( '.mob-menu-header-holder' ).attr( 'data-menu-display' );
142
143      if ( menu_display_type != '' && !$( 'body' ).hasClass( 'mob-menu-slideout' ) && !$( 'body' ).hasClass( 'mob-menu-slideout-over' ) && !$( 'body' ).hasClass( 'mob-menu-slideout-top' ) && !$( 'body' ).hasClass( 'mob-menu-overlay' ) ) {
144        $( 'body' ).addClass( menu_display_type );
145      }
146
147      // Only force autoplay videos in desktop
148      if(! ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) ){
149        $( 'video' ).each( function(){
150          if( 'autoplay' === $( this ).attr('autoplay') ) {
151            $( this )[0].play();
152          } 
153        });
154      }
155
156      var submenu_open_icon  = $( '.mob-menu-header-holder' ).attr( 'data-open-icon' );
157      var submenu_close_icon = $( '.mob-menu-header-holder' ).attr( 'data-close-icon' );
158
159      $( '.mobmenu-content .sub-menu' ).each( function(){
160
161        $( this ).prev().append('<div class="mob-expand-submenu"><i class="mob-icon-' + submenu_open_icon + ' open-icon"></i><i class="mob-icon-' + submenu_close_icon + ' close-icon hide"></i></div>');
162
163        if ( 0 < $( this ).parents( '.mobmenu-parent-link' ).length  ) {
164          $( this ).prev().attr('href', '#');
165        }
166
167      });
168      
169      $( document ).on( 'click', '.mobmenu-parent-link .menu-item-has-children' , function ( e ) {
170        
171        if ( e.target.parentElement != this) return;
172        
173        e.preventDefault();
174        $(this).find('a').find('.mob-expand-submenu').first().trigger('click');
175        e.stopPropagation();
176        
177      });
178      $( document ).on( 'click', '.show-nav-left .mobmenu-push-wrap,  .show-nav-left .mobmenu-overlay', function ( e ) { 
179  
180        e.preventDefault();
181        $( '.mobmenu-left-bt' ).first().trigger( 'click' );
182        e.stopPropagation();
183
184      });
185      
186      $( document ).on( 'click', '.mob-expand-submenu' , function ( e ) {
187
188        // Check if any menu is open and close it.
189        if ( 1 == $( '.mob-menu-header-holder' ).attr( 'data-autoclose-submenus' ) && ! $(this).parent().next().hasClass( 'show-sub-menu' ) ) {
190          if ( 0 < $( '.mob-expand-submenu.show-sub' ).length &&  $(this).parents('.show-sub-menu').length <= 0 ) {
191            mobmenuOpenSubmenus( $( '.mob-expand-submenu.show-sub' ) );
192          }
193        }
194
195        mobmenuOpenSubmenus( $(this) );
196        e.preventDefault();
197        e.stopPropagation();
198
199      });
200
201      $( document ).on( 'keyup', '.mobmenu-left-bt', function(e){
202        if( e.type != 'click' && e.which != 13 || e.which == 9 || jQuery(this).hasClass( 'mobmenu-trigger-action' ) ) {
203          return;
204        }
205
206        mobmenuClosePanel( 'mobmenu-left-panel' );
207        e.stopPropagation();
208      });
209
210      $( document ).on( 'keyup', '.mobmenu-right-bt', function(e){
211        if( e.type != 'click' && e.which != 13 || e.which == 9 || jQuery(this).hasClass( 'mobmenu-trigger-action' ) ) {
212          return;
213        }
214
215        mobmenuClosePanel( 'mobmenu-right-panel' );
216        e.stopPropagation();
217      });
218
219      
220     
221      $( document ).on( 'click', '.mobmenu-panel.show-panel .mob-cancel-button, .show-nav-right .mobmenu-overlay, .show-nav-left .mobmenu-overlay', function ( e ) { 
222        
223        
224
225        e.preventDefault();
226        mobmenuClosePanel( 'show-panel' );
227        if ( $('body').hasClass('mob-menu-sliding-menus') ) {
228          $( '.mobmenu-trigger-action .hamburger' ).toggleClass('is-active');
229        }
230
231      });
232
233      $( document ).on( 'click', '.mobmenu-trigger-action', function(e){
234        e.preventDefault();
235        
236        var targetPanel = $( this ).attr( 'data-panel-target' );
237        
238        if ( ! $( 'body' ).hasClass( 'show-nav-left' ) &&  ! $( 'body' ).hasClass( 'show-nav-right' )  ) {
239          if ( 'mobmenu-filter-panel' !==  targetPanel ) {
240            mobmenuOpenPanel( targetPanel );
241          }
242        }
243
244      });
245
246      $( document ).on( 'click', '.hamburger', function(e){
247        var targetPanel = $(this).parent().attr('data-panel-target');
248        e.preventDefault();
249        e.stopPropagation();
250        
251        $(this).toggleClass( 'is-active' );
252        
253        setTimeout(function(){ 
254          if ( $( 'body' ).hasClass('show-nav-left') ) {
255            if ( $('body').hasClass('mob-menu-sliding-menus') ) {
256              $( '.mobmenu-trigger-action .hamburger' ).toggleClass('is-active');
257            }
258            mobmenuClosePanel( targetPanel );
259            
260          } else {
261            mobmenuOpenPanel( targetPanel );
262          }
263            
264        }, 400);
265        
266
267      });
268     
269      $('.mobmenu a[href*="#"], .mobmenu-panel a[href*="#"]')
270        // Remove links that don't actually link to anything
271        .not('[href="#0"]')
272        .on( 'click', function(event) {
273          // On-page links  
274  
275        if (
276          location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') 
277          && 
278          location.hostname == this.hostname
279          &&
280          $(this).parents('.mobmenu-content').length > 0
281        ) {
282          // Figure out element to scroll to.
283          var target;
284
285          try {
286	          target = decodeURIComponent( this.hash );
287          } catch(e) {
288 	          target = this.hash;
289          }
290
291          $( 'html' ).css( 'overflow', '' );
292
293          // Does a scroll target exist?
294          if (target.length) {
295
296            
297          if ( 0 < $(this).parents('.mobmenu-left-panel').length ) {
298            mobmenuClosePanel( 'mobmenu-left-panel' );
299          } else {
300            mobmenuClosePanel( 'mobmenu-right-panel' );
301          }
302
303            target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
304
305            $('body,html').animate({
306              scrollTop: target.offset().top - $(".mob-menu-header-holder").height() - 50
307            }, 1000);
308          }
309        }
310      });
311      function mobmenuClosePanel( target ) {
312
313        $( '.' + target ).toggleClass( 'show-panel' );
314        $( 'html' ).removeClass( 'show-mobmenu-filter-panel' );
315        $( 'body' ).removeClass( 'show-nav-right' );
316        $( 'body' ).removeClass( 'show-nav-left' );
317        $( 'html' ).removeClass( 'mob-menu-no-scroll' ); 
318
319        setTimeout(function(){
320          $( '.mob-menu-sliding-menus [data-menu-level]' ).scrollTop( '0' );
321          if ( 1 == $( '.mob-menu-header-holder' ).attr( 'data-autoclose-submenus' )  ) {
322            $( '.mob-expand-submenu.show-sub' ).click();
323            $( '.mobmenu-content .show-sub-menu' ).removeClass( 'show-sub-menu' );
324          }
325          
326        }, 400);
327
328      }
329    
330      function mobmenuOpenPanel( target) {
331        $( '.mobmenu-content' ).scrollTop(0);
332        $( 'html' ).addClass( 'mob-menu-no-scroll' ); 
333    
334        if ( $('.' + target ).hasClass( 'mobmenu-left-alignment' ) ) {
335          $('body').addClass('show-nav-left');
336        }
337        if ( $('.' + target ).hasClass( 'mobmenu-right-alignment' ) ) {
338          $('body').addClass('show-nav-right');
339        }
340    
341        $('.' + target ).addClass( 'show-panel' );
342    
343      }
344    });
345
346window.Picker = class Picker {
347  constructor(options = {}) {
348      this.elm = options.elm || document.querySelector('body');
349      this.mode = options.mode || 'target';
350      this.excludeElmName = options.excludeElmName || [];
351      this.switch = typeof options.switch === 'boolean' ? options.switch : true;
352
353      this.events = options.events || [];
354      this.onInit = options.onInit;
355      this.onClick = options.onClick ? options.onClick.bind(this) : null;
356      this.onHover = options.onHover ? options.onHover.bind(this) : null;
357
358
359      // Internal handler
360      this.fn_bind_clickHandle = null;
361      this.fn_bind_hoverHandle = null;
362      this.fn_bind_contextmenuHandle = null;
363      this._init();
364  }
365  on() {
366      this.switch = true;
367  }
368  off() {
369      this.switch = false;
370      this._removeTargetShowPos();
371      this._removeCoverShowPos();
372  }
373  changeMode(mode) {
374      let modeArr = ['cover', 'target'];
375      if (modeArr.includes(mode)) {
376          this.mode = mode;
377          this._removeTargetShowPos();
378          this._removeCoverShowPos();
379      } else {
380          console.error(`Mode error, only includes [ ${modeArr.join(" | ")} ]`);
381      }
382  }
383  destroy() {
384      this.events.forEach((eo) => {
385          eo.fn_bind = eo.fn.bind(this);
386          this.elm.removeEventListener(eo.key, this[`_${eo.key}_Handle`], false);
387      });
388
389      this.elm.removeEventListener('mouseover', this.fn_bind_hoverHandle, false);
390      this.elm.removeEventListener('click', this.fn_bind_clickHandle, false);
391
392      this._removeTargetShowPos();
393      document.querySelector("#_picker_cover_wrap_box").remove();
394  }
395  _init() {
396      let wrapDom = document.createElement('div');
397      wrapDom.setAttribute("id", "_picker_cover_wrap_box");
398      wrapDom.innerHTML = '<svg></svg>';
399      document.body.appendChild(wrapDom);
400      this._initEvent();
401      this.onInit && this.onInit();
402  }
403  _initEvent() {
404      this.events.forEach((eo) => {
405          this[`_${eo.key}_Handle`] = (event) => {
406              if (this._triggerEvent(event) === false) return;
407              eo.fn && eo.fn(event);
408          };
409          eo.fn_bind = this[`_${eo.key}_Handle`].bind(this);
410          this.elm.addEventListener(eo.key, this[`_${eo.key}_Handle`], false);
411      });
412
413      this.fn_bind_hoverHandle = this._hoverHandle.bind(this);
414      this.fn_bind_clickHandle = this._clickHandle.bind(this);
415
416      this.elm.addEventListener('mouseover', this.fn_bind_hoverHandle, false);
417      this.elm.addEventListener('click', this.fn_bind_clickHandle, false);
418
419  }
420  _triggerEvent(event) {
421      let tipsDom = document.querySelector("#_pick_tips_content");
422      if (
423          this.switch &&
424          !this.excludeElmName.includes(event.target.localName.toLocaleLowerCase()) &&
425          !(tipsDom ? tipsDom.contains(event.target) : 0)
426      ) {
427          event.stopPropagation();
428          event.preventDefault();
429          return true;
430      } else {
431          return false;
432      }
433  }
434  _hoverHandle(event) {
435      if (this._triggerEvent(event) === false) return;
436      switch (this.mode) {
437          case 'cover':
438              this._coverShowPos(event);
439              break;
440          case 'target':
441              this._targetShowPos(event);
442              break;
443      }
444      this.onHover && this.onHover(event);
445  }
446  _clickHandle(event) {
447      if (this._triggerEvent(event) === false) return;
448      this.onClick && this.onClick(event);
449  }
450  _targetShowPos(event) {
451      this._removeTargetShowPos();
452      if (event.target.localName === 'body') return;
453      event.target.classList.add("_picker_target_elm");
454  }
455  _removeTargetShowPos() {
456      document.querySelectorAll("._picker_target_elm").forEach((elm) => {
457          elm.classList.remove("_picker_target_elm");
458      });
459  }
460  _coverShowPos(event) {
461      let elm = event.target;
462      let W_W = window.screen.availWidth;
463      let W_H = window.screen.availHeight;
464      let pos = elm.getBoundingClientRect();
465      let p = {
466          tX: pos.left > 0 ? pos.left : 0,
467          tY: pos.top > 0 ? pos.top : 0,
468          w: pos.right - pos.left,
469          h: pos.bottom - pos.top,
470      };
471      let path_W = `M 0 0 h ${W_W} v ${W_H} h -${W_W} Z`;
472      let path_box = `M ${p.tX} ${p.tY} h ${p.w} v ${p.h} h -${p.w} Z`;
473      let elm_path1 = `<path d="${path_W} ${path_box}"></path>`;
474      let elm_path2 = `<path d="${path_box}"></path>`;
475      document.querySelector("#_picker_cover_wrap_box svg").innerHTML = elm_path1 + elm_path2;
476  }
477  _removeCoverShowPos() {
478      document.querySelector("#_picker_cover_wrap_box svg").innerHTML = '';
479  }
480};
481  
482

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.