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