1/*! 2 * hoverIntent v1.8.1 // 2014.08.11 // jQuery v1.9.1+ 3 * http://briancherne.github.io/jquery-hoverIntent/ 4 * 5 * You may use hoverIntent under the terms of the MIT license. Basically that 6 * means you are free to use hoverIntent as long as this header is left intact. 7 * Copyright 2007, 2014 Brian Cherne 8 */ 9 10/* hoverIntent is similar to jQuery's built-in "hover" method except that 11 * instead of firing the handlerIn function immediately, hoverIntent checks 12 * to see if the user's mouse has slowed down (beneath the sensitivity 13 * threshold) before firing the event. The handlerOut function is only 14 * called after a matching handlerIn. 15 * 16 * // basic usage ... just like .hover() 17 * .hoverIntent( handlerIn, handlerOut ) 18 * .hoverIntent( handlerInOut ) 19 * 20 * // basic usage ... with event delegation! 21 * .hoverIntent( handlerIn, handlerOut, selector ) 22 * .hoverIntent( handlerInOut, selector ) 23 * 24 * // using a basic configuration object 25 * .hoverIntent( config ) 26 * 27 * @param handlerIn function OR configuration object 28 * @param handlerOut function OR selector for delegation OR undefined 29 * @param selector selector OR undefined 30 * @author Brian Cherne <brian(at)cherne(dot)net> 31 */ 32 33;(function(factory) { 34 'use strict'; 35 if (typeof define === 'function' && define.amd) { 36 define(['jquery'], factory); 37 } else if (jQuery && !jQuery.fn.hoverIntent) { 38 factory(jQuery); 39 } 40})(function($) { 41 'use strict'; 42 43 // default configuration values 44 var _cfg = { 45 interval: 100, 46 sensitivity: 6, 47 timeout: 0 48 }; 49 50 // counter used to generate an ID for each instance 51 var INSTANCE_COUNT = 0; 52 53 // current X and Y position of mouse, updated during mousemove tracking (shared across instances) 54 var cX, cY; 55 56 // saves the current pointer position coordinates based on the given mousemove event 57 var track = function(ev) { 58 cX = ev.pageX; 59 cY = ev.pageY; 60 }; 61 62 // compares current and previous mouse positions 63 var compare = function(ev,$el,s,cfg) { 64 // compare mouse positions to see if pointer has slowed enough to trigger `over` function 65 if ( Math.sqrt( (s.pX-cX)*(s.pX-cX) + (s.pY-cY)*(s.pY-cY) ) < cfg.sensitivity ) { 66 $el.off(s.event,track); 67 delete s.timeoutId; 68 // set hoverIntent state as active for this element (permits `out` handler to trigger) 69 s.isActive = true; 70 // overwrite old mouseenter event coordinates with most recent pointer position 71 ev.pageX = cX; ev.pageY = cY; 72 // clear coordinate data from state object 73 delete s.pX; delete s.pY; 74 return cfg.over.apply($el[0],[ev]); 75 } else { 76 // set previous coordinates for next comparison 77 s.pX = cX; s.pY = cY; 78 // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs) 79 s.timeoutId = setTimeout( function(){compare(ev, $el, s, cfg);} , cfg.interval ); 80 } 81 }; 82 83 // triggers given `out` function at configured `timeout` after a mouseleave and clears state 84 var delay = function(ev,$el,s,out) { 85 delete $el.data('hoverIntent')[s.id]; 86 return out.apply($el[0],[ev]); 87 }; 88 89 $.fn.hoverIntent = function(handlerIn,handlerOut,selector) { 90 // instance ID, used as a key to store and retrieve state information on an element 91 var instanceId = INSTANCE_COUNT++; 92 93 // extend the default configuration and parse parameters 94 var cfg = $.extend({}, _cfg); 95 if ( $.isPlainObject(handlerIn) ) { 96 cfg = $.extend(cfg, handlerIn); 97 if ( !$.isFunction(cfg.out) ) { 98 cfg.out = cfg.over; 99 } 100 } else if ( $.isFunction(handlerOut) ) { 101 cfg = $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector } ); 102 } else { 103 cfg = $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut } ); 104 } 105 106 // A private function for handling mouse 'hovering' 107 var handleHover = function(e) { 108 // cloned event to pass to handlers (copy required for event object to be passed in IE) 109 var ev = $.extend({},e); 110 111 // the current target of the mouse event, wrapped in a jQuery object 112 var $el = $(this); 113 114 // read hoverIntent data from element (or initialize if not present) 115 var hoverIntentData = $el.data('hoverIntent'); 116 if (!hoverIntentData) { $el.data('hoverIntent', (hoverIntentData = {})); } 117 118 // read per-instance state from element (or initialize if not present) 119 var state = hoverIntentData[instanceId]; 120 if (!state) { hoverIntentData[instanceId] = state = { id: instanceId }; } 121 122 // state properties: 123 // id = instance ID, used to clean up data 124 // timeoutId = timeout ID, reused for tracking mouse position and delaying "out" handler 125 // isActive = plugin state, true after `over` is called just until `out` is called 126 // pX, pY = previously-measured pointer coordinates, updated at each polling interval 127 // event = string representing the namespaced event used for mouse tracking 128 129 // clear any existing timeout 130 if (state.timeoutId) { state.timeoutId = clearTimeout(state.timeoutId); } 131 132 // namespaced event used to register and unregister mousemove tracking 133 var mousemove = state.event = 'mousemove.hoverIntent.hoverIntent'+instanceId; 134 135 // handle the event, based on its type 136 if (e.type === 'mouseenter') { 137 // do nothing if already active 138 if (state.isActive) { return; } 139 // set "previous" X and Y position based on initial entry point 140 state.pX = ev.pageX; state.pY = ev.pageY; 141 // update "current" X and Y position based on mousemove 142 $el.off(mousemove,track).on(mousemove,track); 143 // start polling interval (self-calling timeout) to compare mouse coordinates over time 144 state.timeoutId = setTimeout( function(){compare(ev,$el,state,cfg);} , cfg.interval ); 145 } else { // "mouseleave" 146 // do nothing if not already active 147 if (!state.isActive) { return; } 148 // unbind expensive mousemove event 149 $el.off(mousemove,track); 150 // if hoverIntent state is true, then call the mouseOut function after the specified delay 151 state.timeoutId = setTimeout( function(){delay(ev,$el,state,cfg.out);} , cfg.timeout ); 152 } 153 }; 154 155 // listen for mouseenter and mouseleave 156 return this.on({'mouseenter.hoverIntent':handleHover,'mouseleave.hoverIntent':handleHover}, cfg.selector); 157 }; 158}); 159 160 161 162 163jQuery( document ).ready( function( $ ){ 164 165 function is_preview_menu_item( id ){ 166 var c = false; 167 if ( self !== top ) { 168 try { 169 if ( top.wp.customize ) { 170 if ( top.megamenu_live_previewing == id ) { 171 c = true; 172 } 173 } 174 } catch ( e ) { 175 176 } 177 } 178 return c; 179 } 180 181 var $window = $( window ); 182 $( 'body > *').wrapAll( '<div id="megamenu-wp-page"></div>' ); 183 184 185 var mobileWidth = 0; 186 var isMegaMenuMobile = false; 187 if ( MegamenuWp.theme_support ) { 188 if ( MegamenuWp.theme_support.mobile_mod ) { 189 mobileWidth = parseInt( MegamenuWp.theme_support.mobile_mod ); 190 } 191 } 192 193 if ( 0 >= mobileWidth ) { 194 mobileWidth = 720; 195 } 196 197 function viewPortInit(){ 198 $( '.mega-tab-posts').removeAttr( 'style' ); 199 if ( mobileWidth >= $window.width() ) { 200 $( 'body').addClass( 'megamenu-wp-mobile').removeClass( 'megamenu-wp-desktop') ; 201 isMegaMenuMobile = true; 202 } else { 203 $( 'body').removeClass( 'megamenu-wp-mobile').addClass( 'megamenu-wp-desktop' ) ; 204 isMegaMenuMobile = false; 205 } 206 } 207 208 $window.resize( function(){ 209 viewPortInit(); 210 } ); 211 viewPortInit(); 212 213 214 function guid() { 215 return Math.floor((1 + Math.random()) * 0x10000) 216 .toString(16) 217 .substring(1); 218 } 219 220 function setupMegaLayout( $m ){ 221 var megaLayout = this; 222 this.margin = 0; 223 this.position = 'left'; 224 this.left = 0; 225 this.contentWidth = 0; 226 this.offset = null;
227 this.rightPos = 0; 228 229 // Test 230 var parentLevel = parseInt( MegamenuWp.mega_parent_level ); 231 var $megaMenu = $m; 232 233 if ( parentLevel > 0 ) { 234 var _d = 0; 235 while( parentLevel > 0 ) { 236 $megaMenu = $megaMenu.parent(); 237 parentLevel -- ; 238 _d ++; 239 } 240 } 241 242 var id = $megaMenu.attr( 'id' ) || ''; 243 if ( ! id ) { 244 id = '_mg-'+( new Date().getTime() ); 245 $megaMenu.attr( 'id', id ); 246 } else { 247 248 } 249 250 $megaMenu.addClass( 'megamenu-nav-parent' ); 251 this.cssId = id; 252 253 if ( $( '#megamenu-css-mega-nav-'+this.cssId).length <= 0 ) { 254 $( 'head').append( '<style id="megamenu-css-mega-nav-'+this.cssId+'" type="text/css"></style>' ); 255 } else { 256 $( '#megamenu-css-mega-nav-'+this.cssId).html( '' ); 257 } 258 259 this.setupData = function(){ 260 this._getNavMenuPost(); 261 var w = $window.width(); 262 var megaWidth = 0; 263 264 if ( isNaN( megaWidth ) ) { 265 megaWidth = 0; 266 } 267 268 if ( megaWidth > w - this.margin * 2 ) { 269 megaWidth = w - this.margin * 2; 270 } else { 271 if ( megaWidth == 0 ) 272 { 273 megaWidth = w - this.margin * 2; 274 } 275 } 276 277 if ( megaWidth > w ) { 278 megaWidth = w; 279 } 280 this.contentWidth = megaWidth; 281 if ( this.position == 'right' ) { 282 this.rightPos = this.navWidth + this.offset.left; 283 } else { 284 this.rightPos = this.contentWidth + this.offset.left; 285 } 286 287 return this.contentWidth ; 288 }; 289 290 /** 291 * Get menu position left, right or full width 292 */ 293 this._getNavMenuPost = function(){ 294 var w = $window.width(); 295 // take a test 296 $megaMenu.css( { 'display': 'block', opacity: 0 } ); 297 this.offset = $megaMenu.offset(); 298 this.navWidth = $megaMenu.outerWidth(); 299 var l = Math.round( this.offset.left ) ; 300 this.left = this.offset.left; 301 var mw = $megaMenu.outerWidth(); 302 var r = Math.round( w - ( l + mw ) ) ; 303 304 $megaMenu.css( { 'display' : '', opacity: '' } ); 305 306 if ( l > r ) { 307 this.position = 'right'; // 308 this.margin = r; 309 310 } else { 311 this.position = 'left'; 312 this.margin = l; 313 } 314 315 return this.position; 316 }; 317 318 this.setupContentPos = function (){ 319 this.setupData(); 320 321 var cssCode = ''; 322 $( '#megamenu-css-mega-nav-'+this.cssId ).html( '' ); 323 324 if ( $window.width() <= mobileWidth ) { 325 return false; 326 } 327 328 $megaMenu.find( 'li.mega-item').each( function( index ){ 329 var li = $( this ); 330 var liOf = li.offset(); 331 var l = 0; 332 li.css( 'position', '' ); 333 var pos = li.css( 'position' ); 334 var tr = 0; 335 var itemid = li.attr( 'id' ) || ''; 336 var ul = $( 'ul.mega-content', li ); 337 var ulWidth = ul.data( 'width' ) || 0; 338 if ( ! itemid ) { 339 itemid = '_item_mg-'+ ( new Date().getTime() ) + guid(); 340 li.attr( 'id', itemid ); 341 } 342 343 if ( is_preview_menu_item( itemid ) ) { 344 li.addClass( 'mega-live-view-item mega-hover mega-animation' ); 345 } 346 347 var w, ulpos; 348 349 if ( ulWidth > 0 ) { 350 w = ulWidth; 351 if ( w > megaLayout.contentWidth ) { 352 w = megaLayout.contentWidth; 353 } 354 ulpos = ul.data( 'position' ) || 'left'; 355 cssCode += '#megamenu-wp-page #' + id + ' #' + itemid + '{'; 356 cssCode += ' position: relative;'; 357 cssCode += '}'; 358 359 cssCode += '#megamenu-wp-page #' + id + ' #' + itemid + ' .mega-content {'; 360 cssCode += ' width: ' + w + 'px; '; 361 cssCode += '}'; 362 cssCode += ' #megamenu-wp-page #' + id + ' #' + itemid + '.mega-hover .mega-content, #megamenu-wp-page #' + id + ' #' + itemid + ':hover .mega-content, #megamenu-wp-page #' + id + ' #' + itemid + '.focus .mega-content, #megamenu-wp-page #' + id + ' #' + itemid + '.mega-hover .mega-content{'; 363 364 if ( ulpos == 'left' ) { 365 l = 0; 366 if ( w + liOf.left > megaLayout.rightPos ) { 367 l = ( w + liOf.left ) - megaLayout.rightPos; 368 l = - l; 369 } 370 cssCode += ' left: '+l+'px !important; '; 371 cssCode += ' right: auto !important; '; 372 } else if ( ulpos == 'right' ) { 373 cssCode += ' right: 0px !important; '; 374 cssCode += ' left: auto !important; '; 375 } else { // center 376 var liw = li.outerWidth(); 377 var t; 378 t = l = ( w/2 - liw / 2 ); 379 380 if ( ( liOf.left + w ) - t > megaLayout.rightPos ) { 381 t = ( ( liOf.left + w ) - t ) - megaLayout.rightPos; 382 l += Math.abs( t ); 383 } 384 cssCode += ' right: 0px !important; '; 385 cssCode += ' left: -'+l+'px !important; '; 386 } 387 388 cssCode += ' display: block !important; '; 389 cssCode += '}'; // end hover 390 391 } else { // end custom width 392 // Start Auto width 393 394 w = megaLayout.contentWidth; 395 396 if (megaLayout.position == 'right') { 397 if ('relative' !== pos) { 398 li.css('position', 'relative'); 399 } 400 tr = megaLayout.navWidth + megaLayout.left; 401 l = tr - megaLayout.contentWidth - liOf.left; 402 if (l > 0) { 403 l = -l; 404 } 405 406 } else { 407 if ('relative' !== pos) { 408 l = 0; 409 } else { 410 411 var testLeft = liOf.left; 412 while (megaLayout.rightPos < ( testLeft + megaLayout.contentWidth )) { 413 //while (megaLayout.rightPos < ( megaLayout.offset.left + megaLayout.contentWidth )) { 414 testLeft--; 415 l--; 416 } 417 } 418 419 console.log( 'l - '+pos, l ); 420 } 421 422 423 var ul_left = ul.css( 'left' ) || 0; 424 ul_left = parseFloat( ul_left ); 425 if ( isNaN( ul_left ) ) { 426 ul_left = 0; 427 } 428 429 console.log( 'ul_left', ul_left ); 430 431 cssCode += '#megamenu-wp-page #' + id + ' #' + itemid + ':hover .mega-content, #megamenu-wp-page #' + id + ' #' + itemid + '.focus .mega-content, #megamenu-wp-page #' + id + ' #' + itemid + '.mega-hover .mega-content {'; 432 cssCode += ' width: ' + w + 'px; '; 433 if( ul_left < -1600 ) { 434 cssCode += ' left: ' + l + 'px; '; 435 } 436 cssCode += '}'; 437 438 cssCode += '#megamenu-wp-page #' + id + ' #' + itemid + ' .mega-content, #megamenu-wp-page #' + id + ' #' + itemid + ' .mega-content {'; 439 cssCode += ' width: ' + w + 'px; '; 440 if( ul_left >= -1600 ) { 441 cssCode += ' left: ' + l + 'px !important; '; 442 } 443 cssCode += '}'; 444 445 // cssCode += ' width: ' + w + 'px !important'; 446 } 447 448 } ); // end loop mega items 449 450 //cssCode += '.megamenu-wp-desktop #megamenu-wp-page #'+id+' li:hover .mega-content, #megamenu-wp-page '+id+' li.mega-hover .mega-content { margin-left: 0px !important; margin-right: 0px !important; max-width: '+( $window.width() )+'px !important; min-width: 0px!important; right: auto !important; }'; 451 cssCode += '.megamenu-wp-desktop #megamenu-wp-page #'+id+' li .mega-content { margin-left: 0px !important; margin-right: 0px !important; max-width: '+( $window.width() )+'px !important; min-width: 0px!important; right: auto !important; }'; 452 cssCode += '.megamenu-wp-desktop #megamenu-wp-page #'+id+' { position: relative; } '; 453 cssCode += '.megamenu-wp-desktop #megamenu-wp-page #'+id+' .mega-content { z-index: -1; max-width: 99999999px; } '; 454 cssCode += '.megamenu-wp-desktop #megamenu-wp-page #'+id+':hover .mega-content,.megamenu-wp-desktop #megamenu-wp-page #'+id+'.focus .mega-content, .megamenu-wp-desktop #megamenu-wp-page #'+id+'.mega-hover .mega-content { z-index: 999; } '; 455 // mega-content-full 456 if ( this.contentWidth < $window.width() ) { 457 var md = $window.width() - this.contentWidth; 458 md = md / 2; 459 //cssCode += '#megamenu-wp-page .mega-content-full .mega-builder-container, #megamenu-wp-page .mega-content-full .mega-posts-wrapper, #megamenu-wp-page .mega-content-full .mega-inner{ margin-left: -'+md+'px; margin-right: -'+md+'px; } '; 460 cssCode += '.megamenu-wp-desktop #megamenu-wp-page .mega-content-full .mega-inner { margin-left: -'+md+'px; margin-right: -'+md+'px; } '; 461 } 462 463 $( '#megamenu-css-mega-nav-'+this.cssId ).html( cssCode ); 464 $( document).trigger( 'wp_mega_menu_css_changed', [ cssCode, $megaMenu, this.cssId ] ); 465 466 }; 467 468 469 this.init = function(){ 470 var custom_css = ''; 471 $('.mega-item .mega-content').each( function () { 472 var item = $( this ).closest('.mega-item'); 473 var css = $( this ).data( 'style' ) || ''; 474 var id = item.attr( 'id' ) || ''; 475 if ( css ) { 476 css = css.replace(/__id__/g, id ); 477 custom_css += css; 478 } 479 } ); 480 481 if ( custom_css ) { 482 if ( $( '#megamenu-wp-custom-css' ).length <= 0 ) { 483 $( 'head' ).append( '<style id="megamenu-wp-custom-css" type="text/css">'+custom_css+'</style>' ); 484 } else { 485 $( '#megamenu-wp-custom-css' ).html( custom_css ); 486 } 487 } else { 488 $( '#megamenu-wp-custom-css' ).remove( ); 489 } 490 491 if ( MegamenuWp.theme_support.disable_auto_css ) { 492 return ; 493 } 494 495 this.timeout = null; 496 $window.resize( function(){ 497 $( '#megamenu-css-mega-nav-'+megaLayout.cssId ).html( '' ); 498 megaLayout.setupContentPos(); 499 } ); 500 megaLayout.setupContentPos(); 501 502 }; 503 504 this.init(); 505 } 506 507 $('.mega-item').parent().addClass('megamenu-wp'); 508 509 $('.megamenu-wp').each(function () { 510 new setupMegaLayout( $(this) ); 511 });
512 513 514 515 516 517 var tabs_layout = function(){ 518 $( '.mega-tab-posts').each( function(){ 519 // $( this).closest( '.menu-item' ).addClass( 'mega-item' ); 520 var tabs = $( this ); 521 522 var nav = $( '.mega-tab-post-nav', tabs ); 523 var loading = $( MegamenuWp.loading_icon ); 524 var showWhen = tabs.data( 'show-when' ) || 'hover'; 525 if ( showWhen != 'click' ) { 526 showWhen = 'hover'; 527 } 528 529 tabs.css( { 'min-height': tabs.height() } ); 530 531 if ( $( '.li.active', nav ).length == 0 ) { 532 $( '.li', nav ).eq( 0 ).addClass( 'active' ); 533 var data = $( '.li.active', nav).eq( 0 ).data( 'query' ); 534 tabs.data( 'last-query', data ); 535 536 $( '.mega-tab-post-cont .nav-posts-tab', tabs ).eq( 0 ).addClass( 'active animation' ); 537 } 538 539 $( '.mega-tab-post-cont', tabs ).append( loading ); 540 541 $( '.li', nav ).on( showWhen, function( e ) { 542 // e.preventDefault(); 543 if ( showWhen != 'hover' ) { 544 e.preventDefault(); 545 } 546 var li = $( this ); 547 if ( isMegaMenuMobile && showWhen != 'hover' ) { 548 var url = $( 'a', li).attr( 'href' ) || ''; 549 if ( url ) { 550 window.location = url; 551 return; 552 } 553 554 } 555 556 $( '.li', nav ).removeClass( 'active' ); 557 li.addClass( 'active' ); 558 var id = li.attr( 'data-id' ) || ''; 559 if ( id ) { 560 561 $( '.mega-tab-post-cont .nav-posts-tab', tabs ).removeClass( 'animation' ); 562 $( '.mega-tab-post-cont .nav-posts-tab', tabs ).removeClass( 'active' ); 563 $( '.mega-tab-post-cont .nav-posts-tab[data-id="'+id+'"]', tabs ).addClass( 'active' ); 564 setTimeout( function(){ 565 $( '.mega-tab-post-cont .nav-posts-tab[data-id="'+id+'"]', tabs ).addClass( 'animation' ); 566 }, 10 ); 567 568 } 569 570 } ); 571 572 tabs.on( 'click', '.tab-paging', function( e ) { 573 e.preventDefault(); 574 var a = $( this ); 575 if ( a.hasClass( 'active' ) ) { 576 //var data = tabs.data('last-query') || null; 577 var data = null; 578 var li; 579 580 if ( $('.li.active', nav).eq(0).length > 0 ) { 581 if (!data) { 582 data = $('.li.active', nav).eq(0).data('query'); 583 } 584 li = $('.li.active', nav); 585 } 586 587 if ( ! data ) { 588 data = a.closest( '.mega-tab-post-cont').data( 'query' ) || null; 589 } 590 591 var paged = a.attr('data-paged') || 0; 592 paged = parseInt( paged ); 593 var current_tab = a.closest( '.nav-posts-tab' ); 594 if ( paged > 0 ) { 595 data.paged = paged; 596 data.action = 'megamneu_wp_load_posts'; 597 598 tabs.addClass( 'loading' ); 599 if ( tabs._xhr ) { 600 tabs._xhr.abort(); 601 } 602 tabs._xhr = $.ajax( { 603 url: MegamenuWp.ajax_url, 604 data: data, 605 success: function( res ) { 606 tabs.css( { height: 'auto' } ); 607 //tabs.css( { height: tabs.height() } ); 608 tabs.css( { height: 'auto' } ); 609 current_tab.removeClass( 'animation' ); 610 if ( res.data ) { 611 current_tab.html ( res.data ); 612 } else { 613 a.removeClass( 'active' ).addClass( 'disable' ); 614 } 615 616 setTimeout( function(){ 617 tabs.removeClass( 'loading' ); 618 current_tab.addClass( 'animation' ); 619 }, 20 ); 620 621 tabs._xhr = null; 622 } 623 }).fail( function(){ 624 tabs.removeClass( 'loading' ); 625 tabs._xhr = null; 626 } ); 627 } 628 } 629 630 } ); 631 } ); 632 }; 633 634 tabs_layout(); 635 636 637 // Selective refresh 638 if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) { 639 wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) { 640 641 $( '.megamenu-wp').each( function(){ 642 $( this ).find( 'li' ).removeClass( 'mega-live-view-item mega-hover mega-animation' ); 643 new setupMegaLayout( $( this ) ); 644 } ); 645 646 tabs_layout(); 647 648 } ); 649 } 650 651 652} );
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.