1( function( $ ) { 2 3 'use strict'; 4 5 // Keep JetPopup bound to its isolated anime.js instance. 6 var anime = window.JetPopupAnime; 7 8 window.JetPopupFrontend = { 9 10 addedScripts: {}, 11 12 addedStyles: {}, 13 14 addedAssetsPromises: [], 15 16 getTooltipReference: function( $trigger ) { 17 const popper = $trigger && $trigger.closest( '[data-tippy-root]' )[0], 18 instance = popper && popper._tippy; 19 20 if ( instance && $( instance.reference ).closest( '.jet-tooltip-widget' ).length ) { 21 return $( instance.reference ); 22 } 23 24 return $(); 25 }, 26 27 getTooltipPopupData: function( popupData, $trigger ) { 28 const $reference = JetPopupFrontend.getTooltipReference( $trigger ), 29 settings = $trigger && $trigger.closest( '[data-jet-popup]' ).data( 'jet-popup' ); 30 31 if ( ! $reference.length ) { 32 return popupData; 33 } 34 35 if ( settings && ! settings['is-jet-engine'] && ! popupData.isJetEngine && ! popupData.loopDynamicPopup ) { 36 return popupData; 37 } 38 39 // Tippy can render outside the listing. Resolve context from its owner, 40 // using JetEngine's existing resolver to preserve query/source metadata. 41 if ( window.JetEngine && window.JetEngine.prepareJetPopup 42 && $reference.closest( '.jet-listing-grid__item, .jet-calendar-week__day-event, [data-item-object]' ).length ) { 43 popupData = window.JetEngine.prepareJetPopup( 44 $.extend( {}, popupData ), { 'is-jet-engine': true }, $reference 45 ); 46 } else if ( popupData.loopDynamicPopup ) { 47 popupData = $.extend( {}, popupData, JetPopupFrontend.getLoopItemData( $reference ) ); 48 } 49 50 if ( popupData.postId && ( popupData.isJetEngine || popupData.loopDynamicPopup ) ) { 51 popupData.forceLoad = true; 52 } 53 54 return popupData; 55 }, 56 57 getLoopItemData: function( $trigger ) { 58 59 let $loopItem = $(); 60 61 if ( ! $trigger || ! $trigger.length ) { 62 return {}; 63 } 64 65 $loopItem = $trigger.closest( '[data-elementor-type="loop-item"], .e-loop-item' ); 66 67 if ( ! $loopItem.length ) { 68 $loopItem = $trigger.find( '[data-elementor-type="loop-item"], .e-loop-item' ).first(); 69 } 70 71 if ( ! $loopItem.length ) { 72 return {}; 73 } 74 75 let postId = $loopItem.data( 'post-id' ) || false, 76 className = $loopItem.attr( 'class' ) || '', 77 matches = [ 78 className.match( /\be-loop-item-(\d+)\b/ ), 79 className.match( /\bpost-(\d+)\b/ ), 80 className.match( /\bpage-id-(\d+)\b/ ), 81 className.match( /\battachment-(\d+)\b/ ), 82 ]; 83 84 if ( ! postId ) { 85 for ( let match of matches ) { 86 if ( match && match[1] ) { 87 postId = match[1]; 88 break; 89 } 90 } 91 } 92 93 if ( ! postId ) { 94 return {}; 95 } 96 97 return { 98 postId: +postId, 99 }; 100 }, 101 102 maybeExtendPopupData: function( popupData, $trigger ) { 103 let loopItemData = {}; 104 105 popupData = popupData || {}; 106 107 if ( popupData.postId ) { 108 return popupData; 109 } 110 111 if ( popupData.loopDynamicPopup && $trigger && $trigger.length ) { 112 loopItemData = JetPopupFrontend.getLoopItemData( $trigger ); 113 } 114 115 if ( loopItemData.postId ) { 116 return jQuery.extend( {}, popupData, loopItemData ); 117 } 118 119 if ( window.jetPopupData && window.jetPopupData.currentPostId ) { 120 return jQuery.extend( {}, popupData, { 121 postId: +window.jetPopupData.currentPostId, 122 } ); 123 } 124 125 return popupData; 126 }, 127 128 init: function() { 129 let $popup_list = $( '.jet-popup.jet-popup--front-mode' ); 130 131 $popup_list.each( function( index ) { 132 let $target = $( this ), 133 instance = null, 134 settings = $target.data( 'settings' ); 135 136 instance = new window.jetPopup( $target, settings ); 137 instance.init(); 138 } ); 139 140 JetPopupFrontend.initAttachedPopups(); 141 142 JetPopupFrontend.initBlocks(); 143 144 $( window ).on( 'jet-popup/ajax/frontend-init', ( event, payload ) => { 145 146 switch ( payload.contentType ) { 147 case 'elementor': 148 JetPopupFrontend.maybeElementorFrontendInit( payload.$container ); 149 break; 150 case 'default': 151 JetPopupFrontend.maybeDefaultFrontendInit( payload ); 152 break 153 } 154 } ); 155 }, 156 157 initAttachedPopups: function ( $scope ) { 158 $scope = $scope || $( 'body' ); 159 160 $scope.find( '[data-popup-instance]' ).each( ( index, el ) => {
161 let $this = $( el ), 162 popupId = $this.data( 'popup-instance' ) || 'none', 163 triggerType = $this.data( 'popup-trigger-type' ) || 'none', 164 clickedCustomClass = $this.data( 'popup-custom-selector' ) || '', 165 popupData = { 166 popupId: `jet-popup-${ popupId }`, 167 }; 168 169 if ( $this.hasClass( 'jet-popup-attach-event-inited' ) ) { 170 return; 171 } 172 173 $this.addClass( 'jet-popup-attach-event-inited' ); 174 175 switch( triggerType ) { 176 case 'click-self': 177 $this.addClass( 'jet-popup-cursor-pointer' ); 178 JetPopupFrontend.makeTriggerAccessible( $this, popupData.popupId ); 179 180 $this.on( 'click.JetPopup', function( event ) { 181 event.preventDefault(); 182 183 $( window ).trigger( { 184 type: 'jet-popup-open-trigger', 185 popupData: popupData, 186 triggeredBy: $( event.currentTarget ), 187 } ); 188 189 return false; 190 } ); 191 break; 192 case 'click-selector': 193 194 if ( '' !== clickedCustomClass ) { 195 $this.find( clickedCustomClass ).addClass( 'jet-popup-cursor-pointer' ); 196 JetPopupFrontend.makeTriggerAccessible( $this.find( clickedCustomClass ), popupData.popupId ); 197 198 $this.on( 'click.JetPopup', clickedCustomClass, function( event ) { 199 event.preventDefault(); 200 201 $( window ).trigger( { 202 type: 'jet-popup-open-trigger', 203 popupData: popupData, 204 triggeredBy: $( event.currentTarget ), 205 } ); 206 207 return false; 208 } ); 209 } 210 break; 211 case 'hover': 212 $this.on( 'mouseenter.JetPopup', function( event ) { 213 214 $( window ).trigger( { 215 type: 'jet-popup-open-trigger', 216 popupData: popupData, 217 triggeredBy: $this, 218 } ); 219 } ); 220 break; 221 case 'scroll-to': 222 const observer = new IntersectionObserver(( entries ) => { 223 entries.forEach(( entry ) => { 224 225 if ( entry.isIntersecting ) { 226 227 $( window ).trigger( { 228 type: 'jet-popup-open-trigger', 229 popupData: popupData, 230 triggeredBy: $this, 231 } ); 232 } 233 }) 234 }, 235 { 236 threshold: 0.5 237 }); 238 239 for ( let i = 0; i < $( $this ).length; i++ ) { 240 const elements = $( $this )[i]; 241 observer.observe( elements ); 242 } 243 244 break; 245 } 246 } ); 247 }, 248 249 initBlocks: function( $scope ) { 250 $scope = $scope || $( 'body' ); 251 252 window.JetPlugins.init( $scope, [ 253 { 254 block: 'jet-popup/action-button', 255 callback: ( $scope ) => { 256 let $button = $( '.jet-popup-action-button__instance', $scope ), 257 actionType = $scope.data( 'action-type' ); 258 259 JetPopupFrontend.actionButtonHandle( $button, actionType ); 260 } 261 } 262 ] ); 263 }, 264 265 actionButtonBlock: function( $scope ) { 266 var $button = $( '.jet-popup-action-button__instance', $scope ), 267 actionType = $scope.data( 'action-type' ); 268 269 JetPopupFrontend.actionButtonHandle( $button, actionType ); 270 }, 271 272 getPopupActionButtonCloseState: function( $popup, constantly ) { 273 var popupSettings = $popup.data( 'settings' ) || {}; 274 275 if ( undefined !== constantly ) { 276 return constantly; 277 } 278 279 return popupSettings['show-once'] || false; 280 }, 281 282 redirectPopupActionButton: function( $button ) { 283 var link = $button.attr( 'href' ), 284 target = $button.attr( 'target' ); 285 286 if ( ! link || '#' === link ) { 287 return; 288 } 289 290 if ( '_blank' === target ) { 291 window.open( link, '_blank' ); 292 } else { 293 window.open( link, '_self' ); 294 } 295 }, 296 297 actionButtonHandle: function ( $button, actionType = 'link' ) { 298 299 switch ( actionType ) { 300 301 case 'link': 302 303 $button.on( 'click.JetPopup', function( event ) { 304 event.preventDefault(); 305 306 var $currentPopup = $button.closest( '.jet-popup' ), 307 popupId = $currentPopup.attr( 'id' ); 308 309 $( window ).trigger( { 310 type: 'jet-popup-close-trigger', 311 popupData: { 312 popupId: popupId, 313 constantly: JetPopupFrontend.getPopupActionButtonCloseState( $currentPopup ) 314 } 315 } ); 316 317 JetPopupFrontend.redirectPopupActionButton( $( this ) ); 318 319 return false; 320 } ); 321 break; 322
323 case 'leave': 324 $button.on( 'click.JetPopup', function( event ) { 325 event.preventDefault(); 326 327 window.history.back(); 328 } ); 329 break; 330 331 case 'close-popup': 332 $button.on( 'click.JetPopup', function( event ) { 333 event.preventDefault(); 334 335 var $currentPopup = $button.closest( '.jet-popup' ), 336 popupId = $currentPopup.attr( 'id' ); 337 338 $( window ).trigger( { 339 type: 'jet-popup-close-trigger', 340 popupData: { 341 popupId: popupId, 342 constantly: false 343 } 344 } ); 345 346 JetPopupFrontend.redirectPopupActionButton( $( this ) ); 347 } ); 348 break; 349 350 case 'close-all-popups': 351 $button.on( 'click.JetPopup', function( event ) { 352 event.preventDefault(); 353 354 var $popups = $( '.jet-popup' ); 355 356 if ( $popups[0] ) { 357 $popups.each( function( index ) { 358 var $popup = $( this ), 359 popupId = $popup.attr( 'id' ); 360 361 $( window ).trigger( { 362 type: 'jet-popup-close-trigger', 363 popupData: { 364 popupId: popupId, 365 constantly: false 366 } 367 } ); 368 } ); 369 } 370 371 JetPopupFrontend.redirectPopupActionButton( $( this ) ); 372 } ); 373 break; 374 375 case 'close-constantly': 376 $button.on( 'click.JetPopup', function( event ) { 377 event.preventDefault(); 378 379 var $currentPopup = $button.closest( '.jet-popup' ), 380 popupId = $currentPopup.attr( 'id' ); 381 382 $( window ).trigger( { 383 type: 'jet-popup-close-trigger', 384 popupData: { 385 popupId: popupId, 386 constantly: true 387 } 388 } ); 389 390 JetPopupFrontend.redirectPopupActionButton( $( this ) ); 391 } ); 392 break; 393 394 case 'close-all-constantly': 395 $button.on( 'click.JetPopup', function( event ) { 396 event.preventDefault(); 397 398 var $popups = $( '.jet-popup' ); 399 400 if ( $popups[0] ) { 401 $popups.each( function( index ) { 402 var $popup = $( this ), 403 popupId = $popup.attr( 'id' ); 404 405 $( window ).trigger( { 406 type: 'jet-popup-close-trigger', 407 popupData: { 408 popupId: popupId, 409 constantly: true 410 } 411 } ); 412 } ); 413 } 414 415 JetPopupFrontend.redirectPopupActionButton( $( this ) ); 416 } ); 417 break; 418 } 419 }, 420 421 isNativeInteractiveElement: function( element ) { 422 if ( ! element || ! element.tagName ) { 423 return false; 424 } 425 426 const tagName = element.tagName.toLowerCase(); 427 428 return -1 !== [ 'a', 'button', 'input', 'select', 'textarea', 'option', 'summary' ].indexOf( tagName ); 429 }, 430 431 makeTriggerAccessible: function( $elements, popupId ) { 432 if ( ! $elements || ! $elements.length ) { 433 return; 434 } 435 436 $elements.each( function() { 437 const $element = $( this ); 438 439 if ( popupId ) { 440 $element.attr( { 441 'aria-haspopup': 'dialog', 442 'aria-controls': popupId, 443 'aria-expanded': 'false', 444 } ); 445 } 446 447 if ( JetPopupFrontend.isNativeInteractiveElement( this ) ) { 448 return; 449 } 450 451 if ( ! $element.is( '[role]' ) ) { 452 $element.attr( 'role', 'button' ); 453 } 454 455 if ( ! $element.is( '[tabindex]' ) ) { 456 $element.attr( 'tabindex', '0' ); 457 } 458 } ); 459 460 $elements.off( 'keydown.jetPopupA11yTrigger' ).on( 'keydown.jetPopupA11yTrigger', function( event ) { 461 const key = event.key || ''; 462 463 if ( JetPopupFrontend.isNativeInteractiveElement( event.currentTarget ) ) { 464 return; 465 } 466 467 if ( 'Enter' === key || ' ' === key || 'Spacebar' === key || 13 === event.keyCode || 32 === event.keyCode ) { 468 event.preventDefault(); 469 $( this ).trigger( 'click' ); 470 } 471 } ); 472 }, 473 474 loadScriptAsync: function( script, uri ) { 475 476 if ( JetPopupFrontend.addedScripts.hasOwnProperty( script ) ) { 477 return script; 478 } 479 480 JetPopupFrontend.addedScripts[ script ] = uri; 481 482 const asset = document.getElementById( script + '-js' ); 483 484 if ( asset ) { 485 return script; 486 } 487 488 return new Promise( function( resolve, reject ) { 489 var tag = document.createElement( 'script' ); 490 491 tag.src = uri; 492 tag.async = false; 493 tag.onload = function() { 494 resolve( script ); 495 }; 496 497 document.head.appendChild( tag ); 498 } ); 499 }, 500 501 loadStyle: function( style, uri ) { 502 503 if ( JetPopupFrontend.addedStyles.hasOwnProperty( style ) && JetPopupFrontend.addedStyles[ style ] === uri) { 504 return style; 505 } 506 507 JetPopupFrontend.addedStyles[ style ] = uri; 508 509 return new Promise( function( resolve, reject ) { 510 var tag = document.createElement( 'link' ); 511 512 tag.id = style; 513 tag.rel = 'stylesheet'; 514 tag.href = uri; 515 tag.type = 'text/css'; 516 tag.media = 'all'; 517 tag.onload = function() { 518 resolve( style ); 519 }; 520 521 document.head.appendChild( tag ); 522 }); 523 }, 524 525 assetsLoaderPromise: function() { 526 return Promise.all( JetPopupFrontend.addedAssetsPromises ); 527 }, 528 529 maybeElementorFrontendInit: function( $popupContainer ) { 530 $popupContainer.find( 'div[data-element_type]' ).each( function() { 531 var $this = $( this ), 532 elementType = $this.data( 'element_type' ); 533 534 if ( ! elementType ) { 535 return; 536 } 537 538 try { 539 if ( 'widget' === elementType ) { 540 elementType = $this.data( 'widget_type' ); 541 542 if ( window.elementorFrontend && window.elementorFrontend.hooks ) { 543 window.elementorFrontend.hooks.doAction( 'frontend/element_ready/widget', $this, $ ); 544 } 545 } 546 547 if ( window.elementorFrontend && window.elementorFrontend.hooks ) { 548 window.elementorFrontend.hooks.doAction( 'frontend/element_ready/global', $this, $ ); 549 window.elementorFrontend.hooks.doAction( 'frontend/element_ready/' + elementType, $this, $ ); 550 } 551 552 } catch ( err ) { 553 console.log(err); 554 $this.remove(); 555 556 return false;
557 } 558 } ); 559 }, 560 561 maybeDefaultFrontendInit: function ( payload ) { 562 const contentElements = payload.contentElements || [], 563 $container = payload.$container; 564 565 $container.find( '[data-is-block*="/"]' ).each( ( index, el ) => { 566 window.JetPlugins.hooks.doAction( window.JetPlugins.hookNameFromBlock( el.dataset.isBlock ), jQuery( el ) ); 567 } ); 568 } 569 }; 570 571 /** 572 * [jetPopup description] 573 * @param {[type]} $popup [description] 574 * @param {[type]} settings [description] 575 * @return {[type]} [description] 576 */ 577 window.jetPopup = function( $popup, settings ) { 578 var self = this, 579 $window = $( window ), 580 $document = $( document ), 581 popupSettings = settings, 582 id = popupSettings['id'], 583 popupId = popupSettings['jet-popup-id'], 584 popupsLocalStorageData = {}, 585 //editMode = Boolean( window.elementorFrontend.isEditMode() ), 586 isAnimation = false, 587 isOpen = false, 588 ajaxGetContentHanler = null, 589 ajaxContentLoaded = false, 590 focusedBeforeOpen = null, 591 $lastTrigger = $(); 592 593 self.getAccessibilityConfig = function() { 594 return window.jetPopupData && window.jetPopupData.accessibility ? window.jetPopupData.accessibility : {}; 595 }; 596 597 self.getPopupLabel = function() { 598 return self.getAccessibilityConfig().popupLabel || 'Popup dialog'; 599 }; 600 601 self.getCloseButtonLabel = function() { 602 return self.getAccessibilityConfig().closeButtonLabel || 'Close popup'; 603 }; 604 605 self.isFocusableElement = function( element ) { 606 let $element = $( element ), 607 tabIndex = $element.attr( 'tabindex' ); 608 609 if ( ! element || ! $element.length ) { 610 return false; 611 } 612 613 if ( $element.is( '[disabled], [hidden], [aria-hidden="true"]' ) || $element.hasClass( 'elementor-hidden' ) ) { 614 return false; 615 } 616 617 if ( undefined !== tabIndex && 0 > parseInt( tabIndex, 10 ) ) { 618 return false; 619 } 620 621 return !! ( element.offsetWidth || element.offsetHeight || element.getClientRects().length ); 622 }; 623 624 self.getFocusableElements = function() { 625 return $popup.find( 'a[href], area[href], input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [contenteditable="true"], [tabindex], .elementor-swiper-button, .jet-listing-dynamic-link__link' ).filter( function() { 626 return self.isFocusableElement( this ); 627 } ); 628 }; 629 630 self.ensureDialogLabel = function() { 631 let $heading = $popup.find( '.jet-popup__container-content :header:visible:first, .jet-popup__container-content [role="heading"]:visible:first' ).first(), 632 generatedId = popupId + '-title'; 633 634 $popup.removeAttr( 'aria-labelledby' ); 635 636 if ( $heading.length ) { 637 if ( ! $heading.attr( 'id' ) ) { 638 $heading.attr( 'id', generatedId ); 639 } 640 641 $popup.attr( 'aria-labelledby', $heading.attr( 'id' ) ); 642 $popup.removeAttr( 'aria-label' ); 643 } else { 644 $popup.attr( 'aria-label', self.getPopupLabel() ); 645 } 646 }; 647 648 self.preparePopupAccessibility = function() { 649 let $closeButton = $( '.jet-popup__close-button', $popup ).first(); 650 651 $popup.attr( { 652 'role': 'dialog',
653 'aria-modal': 'true', 654 'aria-hidden': isOpen ? 'false' : 'true', 655 'tabindex': '-1', 656 } ); 657 658 $( '.jet-popup__overlay, .jet-popup__container-overlay', $popup ).attr( 'aria-hidden', 'true' ); 659 660 if ( $closeButton.length ) { 661 $closeButton.attr( { 662 'aria-label': self.getCloseButtonLabel(), 663 } ); 664 665 if ( ! JetPopupFrontend.isNativeInteractiveElement( $closeButton[0] ) && ! $closeButton.is( '[tabindex]' ) ) { 666 $closeButton.attr( 'tabindex', '0' ); 667 } 668 669 $closeButton.find( 'svg, i' ).attr( { 670 'aria-hidden': 'true', 671 'focusable': 'false', 672 } ); 673 674 } 675 676 $popup.find( '.elementor-swiper-button' ).each( function() { 677 let $button = $( this ); 678 679 if ( ! $button.is( '[tabindex]' ) ) { 680 $button.attr( 'tabindex', '0' ); 681 } 682 683 if ( ! $button.is( '[role]' ) ) { 684 $button.attr( 'role', 'button' ); 685 } 686 } ); 687 688 self.ensureDialogLabel(); 689 }; 690 691 self.storeFocusContext = function( $trigger ) { 692 let activeElement = document.activeElement; 693 694 if ( $trigger && $trigger.length ) { 695 $lastTrigger = $trigger.first(); 696 focusedBeforeOpen = $lastTrigger[0]; 697 } else { 698 $lastTrigger = $(); 699 focusedBeforeOpen = activeElement && document.body !== activeElement ? activeElement : null; 700 } 701 702 if ( $lastTrigger.length ) { 703 $lastTrigger.attr( 'aria-expanded', 'true' ); 704 } 705 }; 706 707 self.focusDefaultElement = function() { 708 let $closeButton = $( '.jet-popup__close-button', $popup ).first(), 709 $focusable = self.getFocusableElements(), 710 $target = $closeButton.length ? $closeButton : $focusable.first(); 711 712 if ( ! $target.length ) { 713 $target = $( '.jet-popup__container', $popup ).first(); 714 } 715 716 if ( $target.length && $target[0].focus ) { 717 window.setTimeout( function() { 718 try { 719 $target[0].focus( { preventScroll: true } ); 720 } catch ( error ) { 721 $target[0].focus(); 722 } 723 }, 0 ); 724 } 725 }; 726 727 self.restoreFocus = function() { 728 if ( $lastTrigger.length ) { 729 $lastTrigger.attr( 'aria-expanded', 'false' ); 730 } 731 732 if ( focusedBeforeOpen && document.contains( focusedBeforeOpen ) && focusedBeforeOpen.focus ) { 733 try { 734 focusedBeforeOpen.focus( { preventScroll: true } ); 735 } catch ( error ) { 736 focusedBeforeOpen.focus(); 737 } 738 } 739 740 focusedBeforeOpen = null; 741 $lastTrigger = $(); 742 }; 743 744 self.moveFocusByOffset = function( offset ) { 745 let $focusable = self.getFocusableElements(), 746 activeIndex = $focusable.index( document.activeElement ); 747 748 if ( ! $focusable.length ) { 749 return; 750 } 751 752 if ( -1 === activeIndex ) { 753 activeIndex = 0; 754 } else { 755 activeIndex = ( activeIndex + offset + $focusable.length ) % $focusable.length; 756 } 757 758 if ( $focusable.eq( activeIndex )[0] && $focusable.eq( activeIndex )[0].focus ) { 759 $focusable.eq( activeIndex )[0].focus(); 760 } 761 }; 762 763 self.handlePopupTabKey = function( event ) { 764 let $focusable = self.getFocusableElements(), 765 $firstElement = $focusable.first(), 766 $lastElement = $focusable.last(); 767 768 if ( ! $focusable.length ) { 769 event.preventDefault(); 770 $popup.trigger( 'focus' ); 771 772 return; 773 } 774 775 if ( event.shiftKey && document.activeElement === $firstElement[0] ) { 776 event.preventDefault(); 777 $lastElement[0].focus(); 778 } else if ( ! event.shiftKey && document.activeElement === $lastElement[0] ) { 779 event.preventDefault(); 780 $firstElement[0].focus(); 781 } 782 }; 783 784 self.handlePopupKeydown = function( event ) { 785 let key = event.key || '', 786 $target = $( event.target ), 787 isTypingControl = $target.is( 'input, textarea, select, [contenteditable="true"]' ); 788 789 if ( ! isOpen ) { 790 return; 791 } 792 793 if ( 'Tab' === key || 9 === event.keyCode ) { 794 self.handlePopupTabKey( event ); 795 796 return; 797 } 798 799 if ( ! isTypingControl && ( 'ArrowDown' === key || 40 === event.keyCode ) ) { 800 event.preventDefault(); 801 self.moveFocusByOffset( 1 ); 802 803 return; 804 } 805 806 if ( ! isTypingControl && ( 'ArrowUp' === key || 38 === event.keyCode ) ) { 807 event.preventDefault(); 808 self.moveFocusByOffset( -1 ); 809 810 return; 811 } 812 813 if ( 'Escape' === key || 27 === event.keyCode ) { 814 event.preventDefault(); 815 self.hidePopup( { 816 constantly: popupSettings['show-once'], 817 popupId: popupSettings['jet-popup-id'] 818 } ); 819 } 820 }; 821 822 self.onPopupShown = function() { 823 isOpen = true; 824 $popup.attr( 'aria-hidden', 'false' ); 825 self.preparePopupAccessibility(); 826 self.focusDefaultElement(); 827 }; 828 829 self.onPopupHidden = function() { 830 isOpen = false;
831 $popup.attr( 'aria-hidden', 'true' ); 832 self.restoreFocus(); 833 }; 834 835 self.init = function() { 836 var popupAvailable = self.popupAvailableCheck(); 837 838 if ( ! popupAvailable ) { 839 return false; 840 } 841 842 self.setLocalStorageData( popupId, 'enable' ); 843 844 self.initCompatibilityHandler(); 845 846 self.initOpenEvent(); 847 848 self.initCloseEvent(); 849 self.preparePopupAccessibility(); 850 $popup.on( 'keydown.jetPopupA11y', self.handlePopupKeydown ); 851 852 $window.trigger( 'jet-popup/init/after', { 853 self: self, 854 settings: popupSettings 855 } ); 856 }; 857 858 /** 859 * [popupAvailableCheck description] 860 * @return {[type]} [description] 861 */ 862 self.popupAvailableCheck = function() { 863 var storageData = self.getLocalStorageData() || {}; 864 865 if ( ! storageData.hasOwnProperty( popupId ) ) { 866 return true; 867 } 868 869 var popupData = storageData[ popupId ], 870 status = 'enable', 871 showAgainDate = 'none'; 872 873 if ( 'disable' === popupData ) { 874 return false; 875 } 876 877 if ( 'enable' === popupData ) { 878 return true; 879 } 880 881 if ( popupData.hasOwnProperty( 'status' ) ) { 882 status = popupData['status']; 883 } 884 885 if ( 'enable' === status ) { 886 return true; 887 } 888 889 if ( popupData.hasOwnProperty( 'show-again-date' ) ) { 890 showAgainDate = popupData['show-again-date']; 891 } 892 893 if ( 'none' === showAgainDate && 'disable' === status ) { 894 return false; 895 } 896 897 if ( showAgainDate < Date.now() ) { 898 return true; 899 } else { 900 return false; 901 } 902 }; 903 904 /** 905 * [initOpenEvent description] 906 * @return {[type]} [description] 907 */ 908 self.initOpenEvent = function() { 909 910 $window.trigger( 'jet-popup/init-events/before', { 911 self: self, 912 settings: popupSettings 913 } ); 914 915 switch ( popupSettings['open-trigger'] ) { 916 case 'page-load': 917 self.pageLoadEvent( popupSettings['page-load-delay'] ); 918 break; 919 920 case 'user-inactive': 921 self.userInactiveEvent( popupSettings['user-inactivity-time'] ); 922 break; 923 924 case 'scroll-trigger': 925 self.scrollPageEvent( popupSettings['scrolled-to'] ); 926 break; 927 928 case 'try-exit-trigger': 929 self.tryExitEvent(); 930 break; 931 932 case 'on-date': 933 self.onDateEvent( popupSettings['on-date'] ); 934 break; 935 936 case 'on-time': 937 self.onTimeEvent( popupSettings['on-time-start'], popupSettings['on-time-end'] ); 938 break; 939 940 case 'on-date-and-time': 941 self.onTimeAndDateEvent( popupSettings['start-date-and-time'], popupSettings['end-date-and-time'] ); 942 break; 943 944 case 'weekly-schedule': 945 self.onWeekdaysAndTimeEvent( 946 popupSettings['on-weekdays'], 947 popupSettings['on-week-time-start'], 948 popupSettings['on-week-time-end'] 949 ); 950 break; 951 952 case 'custom-selector': 953 self.onCustomSelector( popupSettings['custom-selector'] ); 954 break;$scope 955 } 956 957 $window.on('jet-popup-open-trigger', function( event ) { 958 var popupData = event.popupData || {}, 959 triggeredBy = event.triggeredBy || false, 960 popupUniqId = popupData.popupId || false, 961 constantly = popupData.constantly; 962 963 if ( popupUniqId == popupId ) { 964 if ( $popup.hasClass( 'jet-popup--hide-state' )) { 965 self.showPopup( popupData, triggeredBy ); 966 } else { 967 self.hidePopup( { 968 constantly: constantly, 969 popupId: popupUniqId, 970 } ); 971 } 972 } 973 }); 974 975 $window.on( 'jet-popup-close-trigger', function( event ) { 976 var popupData = event.popupData || {}, 977 popupUniqId = popupData.popupId, 978 constantly = popupData.constantly; 979 980 if ( popupUniqId == popupId ) { 981 self.hidePopup( { 982 popupId: popupUniqId, 983 constantly: constantly, 984 } ); 985 } 986 }); 987 988 $window.trigger( 'jet-popup/init-events/after', { 989 self: self, 990 settings: popupSettings 991 } ); 992 }; 993 994 /** 995 * [initOnCloseEvent description] 996 * @return {[type]} [description] 997 */ 998 self.initOnCloseEvent = function() { 999 1000 var $htmlBody = $( 'html, body' ); 1001 1002 if ( 'scroll-to-top' === popupSettings['close-event'] ) { 1003 $htmlBody.animate( { scrollTop: 0 }, 'slow' ); 1004 } 1005 1006 if ( 'scroll-to-anchor' === popupSettings['close-event'] ) { 1007 var anchor = $( '#' + popupSettings['Ñlose-event-anchor'] ); 1008 1009 if ( anchor.length ) { 1010 $htmlBody.animate( { scrollTop: anchor.offset().top }, 'slow' ); 1011 } 1012 } 1013 } 1014 1015 /** 1016 * [initCloseEvent description] 1017 * @return {[type]} [description] 1018 */ 1019 self.initCloseEvent = function() { 1020 1021 $popup.on( 'click', '.jet-popup__close-button', function( event ) { 1022 var target = event.currentTarget; 1023 1024 self.hidePopup( { 1025 constantly: popupSettings['show-once'], 1026 popupId: popupSettings['jet-popup-id'] 1027 } ); 1028 self.initOnCloseEvent(); 1029 } ); 1030 1031 if ( popupSettings['close-on-overlay-click'] ) { 1032 $popup.on( 'click', '.jet-popup__overlay', function( event ) { 1033 var target = event.currentTarget; 1034 1035 self.hidePopup( { 1036 constantly: popupSettings['show-once'], 1037 popupId: popupSettings['jet-popup-id'] 1038 } ); 1039 self.initOnCloseEvent(); 1040 } ); 1041 } 1042 1043 $document.on( 'keyup.jetPopup', function( event ) { 1044 var key = event.keyCode; 1045 1046 if ( 27 === key && isOpen ) { 1047 self.hidePopup( { 1048 constantly: popupSettings['show-once'], 1049 popupId: popupSettings['jet-popup-id'] 1050 } ); 1051 } 1052 } ); 1053 }; 1054 1055 /** 1056 * [initCompatibilityHandler description] 1057 * @return {[type]} [description] 1058 */ 1059 self.initCompatibilityHandler = function() { 1060 var $elementorProFormWidget = $( '.elementor-widget-form', $popup ); 1061 1062 if ( $elementorProFormWidget[0] ) { 1063 $elementorProFormWidget.each( function() { 1064 var $this = $( this ), 1065 $form = $( '.elementor-form', $this ); 1066 1067 $form.on( 'submit_success', function() { 1068 1069 if ( true !== popupSettings['close-after-form-submit'] ) { 1070 return; 1071 } 1072 1073 let delay = parseInt( popupSettings['close-after-form-delay'] || 0 );
1074 delay = delay * 1000; 1075 1076 setTimeout( function() { 1077 $window.trigger( { 1078 type: 'jet-popup-close-trigger', 1079 popupData: { 1080 popupId: popupId, 1081 constantly: false 1082 } 1083 } ); 1084 }, delay ); 1085 1086 }); 1087 } ); 1088 } 1089 1090 $( document ).on( 'jet-form-builder/ajax/on-success', function( event ) { 1091 1092 if ( true !== popupSettings['close-after-form-submit'] ) { 1093 return; 1094 } 1095 1096 let delay = parseInt( popupSettings['close-after-form-delay'] || 0 ); 1097 delay = delay * 1000; 1098 1099 setTimeout( function() { 1100 $window.trigger({ 1101 type: 'jet-popup-close-trigger', 1102 popupData: { 1103 popupId: popupId, 1104 constantly: false 1105 } 1106 }); 1107 }, delay ); 1108 1109 }); 1110 }; 1111 1112 /** 1113 * Handle popup opening on page load event. 1114 * 1115 * @param {number} openDelay Delay before opening the popup (in seconds). 1116 * @return {void} 1117 */ 1118 self.autoClosePopup = function() { 1119 1120 if ( ! popupSettings['automatically-close'] ) { 1121 return; 1122 } 1123 1124 let delay = parseInt( popupSettings['automatically-close'], 10 ); 1125 1126 if ( ! delay ) { 1127 return; 1128 } 1129 1130 setTimeout( function() { 1131 1132 if ( isOpen ) { 1133 self.hidePopup( { 1134 popupId: popupId, 1135 constantly: false 1136 } ); 1137 } 1138 1139 }, delay * 1000 ); 1140 1141 }; 1142 1143 /** 1144 * Page on load event 1145 * 1146 * @param {int} openDelay Open delay time. 1147 * @return {void} 1148 */ 1149 self.pageLoadEvent = function( openDelay ) { 1150 var delay = +openDelay || 0; 1151 1152 delay = delay * 1000; 1153 1154 $( function() { 1155 setTimeout( function() { 1156 self.showPopup(); 1157 }, delay ); 1158 } ); 1159 }; 1160 1161 /** 1162 * User Inactivity event 1163 * 1164 * @param {int} inactiveDelay [description] 1165 * @return {void} 1166 */ 1167 self.userInactiveEvent = function( inactiveDelay ) { 1168 var delay = +inactiveDelay || 0, 1169 isInactive = true; 1170 1171 delay = delay * 1000; 1172 1173 setTimeout( function() { 1174 if ( isInactive ) { 1175 self.showPopup(); 1176 } 1177 }, delay ); 1178 1179 $( document ).on( 'click focus resize keyup scroll', function() { 1180 isInactive = false; 1181 } ); 1182 }; 1183 1184 /** 1185 * Scrolling Page Event 1186 * 1187 * @param {int} scrollingValue Scrolling porgress value 1188 * @return {void} 1189 */ 1190 self.scrollPageEvent = function( scrollingValue ) { 1191 var scrolledValue = +scrollingValue || 0; 1192 1193 $window.on( 'scroll.cherryJetScrollEvent resize.cherryJetResizeEvent', function() { 1194 var $window = $( window ), 1195 windowHeight = $window.height(), 1196 documentHeight = $( document ).height(), 1197 scrolledHeight = documentHeight - windowHeight, 1198 scrolledProgress = Math.max( 0, Math.min( 1, $window.scrollTop() / scrolledHeight ) ) * 100; 1199 1200 if ( scrolledProgress >= scrolledValue ) { 1201 $window.off( 'scroll.cherryJetScrollEvent resize.cherryJetResizeEvent' ); 1202 self.showPopup(); 1203 } 1204 } ).trigger( 'scroll.cherryJetResizeEvent' ); 1205 }; 1206 1207 /** 1208 * Viewport leave event 1209 * 1210 * @return {void} 1211 */ 1212 self.tryExitEvent = function() { 1213 var pageY = 0; 1214 1215 $( document ).on( 'mouseleave', 'body', function( event ) { 1216 1217 pageY = event.pageY - $window.scrollTop(); 1218 1219 if ( 0 > pageY && $popup.hasClass( 'jet-popup--hide-state' ) ) { 1220 self.showPopup(); 1221 } 1222 } ); 1223 }; 1224 1225 /** 1226 * onDateEvent Event 1227 * 1228 * @return {void} 1229 */ 1230 self.onDateEvent = function( date ) { 1231 var nowDate = Date.now(), 1232 startDate = Date.parse( date ); 1233 1234 if ( startDate < nowDate ) { 1235 1236 setTimeout( function() { 1237 self.showPopup(); 1238 }, 500 ); 1239 } 1240 } 1241 1242 self.onWeekdaysAndTimeEvent = function( days = [], startTime = '00:00', endTime = '23:59' ) { 1243 1244 if ( ! days || ! days.length ) { 1245 return; 1246 } 1247 1248 var nowTimeStamp = Date.now(), 1249 nowDate = new Date(), 1250 currentDay = nowDate.toLocaleString('en-US', { weekday: 'short' }).toLowerCase(); 1251 1252 1253 days = days.map( day => day.toLowerCase() ); 1254 1255 if ( ! days.includes( currentDay ) ) { 1256 return; 1257 } 1258 1259 startTime = '' !== startTime ? startTime : '00:00'; 1260 endTime = '' !== endTime ? endTime : '23:59'; 1261 1262 var dateTimeFormat = new Intl.DateTimeFormat( 'en', { year: 'numeric', month: 'short', day: '2-digit' } ), 1263 [ { value: month },,{ value: day },,{ value: year } ] = dateTimeFormat.formatToParts( nowTimeStamp ); 1264 1265 var startDateTime = `${ month }. ${ day }, ${ year } ${ startTime }`, 1266 endDateTime = `${ month }. ${ day }, ${ year } ${ endTime }`; 1267 1268 var startTimeStamp = Date.parse( startDateTime ), 1269 endTimeStamp = Date.parse( endDateTime ); 1270 1271 if ( startTimeStamp < nowTimeStamp && nowTimeStamp < endTimeStamp ) { 1272 setTimeout( function() { 1273 self.showPopup(); 1274 }, 500 ); 1275 } 1276 }; 1277 1278 self.onTimeEvent = function( startTime = '00:00', endTime = '23:59' ) { 1279 var startTime = '' !== startTime ? startTime : '00:00', 1280 endTime = '' !== endTime ? endTime : '23:59', 1281 nowTimeStamp = Date.now(), 1282 dateTimeFormat = new Intl.DateTimeFormat( 'en', { year: 'numeric', month: 'short', day: '2-digit' } ), 1283 [ { value: month },,{ value: day },,{ value: year } ] = dateTimeFormat.formatToParts( nowTimeStamp ), 1284 startTime = `${ month }. ${ day }, ${ year } ${ startTime }`, 1285 endTime = `${ month }. ${ day }, ${ year } ${ endTime }`, 1286 startTimeStamp = Date.parse( startTime ), 1287 endTimeStamp = Date.parse( endTime ); 1288 1289 if ( ( startTimeStamp < nowTimeStamp ) && ( nowTimeStamp < endTimeStamp ) ) { 1290 setTimeout( function() { 1291 self.showPopup(); 1292 }, 500 ); 1293 } 1294 } 1295 1296 1297 self.onTimeAndDateEvent = function( start, end ) { 1298 1299 var nowDateStamp = Date.now(), 1300 startDateStamp = Date.parse( start ), 1301 endDateStamp = Date.parse( end ); 1302 1303 if ( ( startDateStamp < nowDateStamp ) && ( nowDateStamp < endDateStamp ) ) { 1304 setTimeout( function() { 1305 self.showPopup(); 1306 }, 500 ); 1307 } 1308 1309 } 1310 1311 /** 1312 * Check DOM Loaded Selector 1313 * @param {[type]} selector [description] 1314 * @return {[type]} [description] 1315 */ 1316 1317 self.checkLoadedSelector = function( selector ) { 1318 1319 //Check Listing Grid Lazy Load 1320 $( document ).on( 'jet-engine/listing-grid/after-lazy-load', function() { 1321 self.onCustomSelector ( selector ); 1322 }); 1323 1324 //Check Open Mobile Menu 1325 $( '.jet-mobile-menu__toggle' ).closest( '.jet-mobile-menu__instance--slide-out-layout' ).on( 'click', function() { 1326 self.onCustomSelector ( selector ); 1327 }); 1328 1329 } 1330 1331 /** 1332 * [onCustomSelector description] 1333 * @param {[type]} selector [description] 1334 * @return {[type]} [description] 1335 */ 1336 self.onCustomSelector = function( selector ) { 1337 1338 let $selector = $( selector ); 1339 1340 if ( $selector[0] ) { 1341 $( 'body' ).off( 'click.jetPopup', selector ).on( 'click.jetPopup', selector, function( event ) { 1342 event.preventDefault(); 1343 1344 let $this = $( this ); 1345 let popupId = $this.data( 'popup' ); 1346 let $popup = $( '#jet-popup-' + popupId ); 1347 1348 if ( $popup.length && $popup.hasClass( 'jet-popup--show-state' ) ) { 1349 self.hidePopup( popupId, false ); 1350 } else { 1351 self.showPopup( popupId, $this ); 1352 } 1353 } ); 1354 } else { 1355 self.checkLoadedSelector( selector ); 1356 } 1357 } 1358 1359 /** 1360 * Show Popup 1361 * 1362 * @return {void} 1363 */ 1364 self.showPopup = function( data, $trigger ) { 1365 var popupData = data || {}, 1366 animeOverlay = null,
1367 animeContainer = null, 1368 animeOverlaySettings = jQuery.extend( 1369 { 1370 targets: $( '.jet-popup__overlay', $popup )[0] 1371 }, 1372 self.avaliableEffects[ 'fade' ][ 'show' ] 1373 ); 1374 1375 $trigger = $trigger || false; 1376 1377 if ( ! self.popupAvailableCheck() ) { 1378 return false; 1379 } 1380 1381 self.storeFocusContext( $trigger ); 1382 1383 animeOverlay = anime( animeOverlaySettings ); 1384 1385 $popup.toggleClass( 'jet-popup--hide-state jet-popup--show-state' ); 1386 1387 if ( popupSettings['prevent-scrolling'] ) { 1388 $( 'body' ).addClass( 'jet-popup-prevent-scroll' ); 1389 } 1390 1391 popupData = JetPopupFrontend.maybeExtendPopupData( popupData, $trigger ); 1392 popupData = window.JetPlugins.hooks.applyFilters( 'jet-popup.show-popup.data', popupData, $popup, $trigger ); 1393 popupData = JetPopupFrontend.getTooltipPopupData( popupData, $trigger ); 1394 1395 self.showContainer( popupData ); 1396 }; 1397 1398 /** 1399 * [showContainer description] 1400 * @return {[type]} [description] 1401 */ 1402 self.showContainer = function( data ) { 1403 var popupData = data || {}, 1404 popupDefaultData = { 1405 forceLoad: popupSettings['force-ajax'] || false, // Trigger Ajax Every Time 1406 customContent: '' // Show Popup with Custom Content 1407 }, 1408 animeContainerInstance = null, 1409 $popupContainer = $( '.jet-popup__container', $popup ), 1410 $content = $( '.jet-popup__container-content', $popup ), 1411 animeContainer = jQuery.extend( 1412 { 1413 targets: $( '.jet-popup__container', $popup )[0], 1414 begin: function( anime ) { 1415 isAnimation = true; 1416 1417 $window.trigger( 'jet-popup/show-event/before-show', { 1418 self: self, 1419 data: popupData, 1420 anime: anime 1421 } ); 1422 }, 1423 complete: function( anime ) { 1424 isAnimation = false; 1425 1426 self.autoClosePopup(); 1427 self.onPopupShown(); 1428 1429 $window.trigger( 'jet-popup/show-event/after-show', { 1430 self: self, 1431 data: popupData, 1432 anime: anime 1433 } ); 1434 } 1435 }, 1436 self.avaliableEffects[ popupSettings['animation'] ][ 'show' ] 1437 1438 ); 1439 1440 popupData = jQuery.extend( popupDefaultData, popupData ); 1441 1442 // init Custom popup content 1443 if ( '' !== popupData.customContent ) { 1444 $content.html( popupData.customContent ); 1445 self.elementorFrontendInit(); 1446 1447 // Show Popup Container
1448 animeContainerInstance = anime( animeContainer ); 1449 1450 $window.trigger( 'jet-popup/render-content/render-custom-content', { 1451 self: self, 1452 popup_id: id, 1453 data: popupData, 1454 } ); 1455 1456 return false; 1457 } 1458 1459 // Dynamic listing popups share one pre-rendered DOM node. Load the 1460 // selected listing item through the existing content endpoint. 1461 let hasDynamicContext = popupData.postId && ( popupData.isJetEngine || popupData.loopDynamicPopup ); 1462 1463 if ( hasDynamicContext ) { 1464 popupData.forceLoad = true; 1465 ajaxContentLoaded = false; 1466 } 1467 1468 if ( ! popupSettings['use-ajax'] && ! hasDynamicContext ) { 1469 // Show Popup Container 1470 animeContainerInstance = anime( animeContainer ); 1471 1472 $window.trigger( 'jet-popup/render-content/render-custom-content', { 1473 self: self, 1474 popup_id: id, 1475 data: popupData, 1476 } ); 1477 1478 return false; 1479 } 1480 1481 if ( popupData.forceLoad ) { 1482 ajaxContentLoaded = false; 1483 } 1484 1485 if ( ajaxContentLoaded ) { 1486 // Show Popup Container 1487 animeContainerInstance = anime( animeContainer ); 1488 1489 $window.trigger( 'jet-popup/render-content/show-content', { 1490 self: self, 1491 popup_id: id, 1492 data: popupData, 1493 } ); 1494 1495 return false; 1496 } 1497 1498 popupData = jQuery.extend( popupData, { 1499 'popup_id': id, 1500 'page_url': window.location.href 1501 } ); 1502 1503 ajaxGetContentHanler = jQuery.ajax( { 1504 type: 'POST', 1505 url: window.jetPopupData.ajax_url, 1506 data: { 1507 'action': 'jet_popup_get_content', 1508 'data': popupData 1509 }, 1510 beforeSend: function( jqXHR, ajaxSettings ) { 1511 1512 if ( null !== ajaxGetContentHanler ) { 1513 ajaxGetContentHanler.abort(); 1514 } 1515 1516 // Before ajax send Trigger 1517 $window.trigger( 'jet-popup/render-content/ajax/before-send', { 1518 self: self, 1519 popup_id: id, 1520 data: popupData 1521 } ); 1522 1523 $popup.addClass( 'jet-popup--loading-state' ); 1524 }, 1525 error: function( jqXHR, ajaxSettings ) {}, 1526 success: function( data, textStatus, jqXHR ) { 1527 var successType = data.type, 1528 contentData = data.content || false, 1529 $popupContainer = $( '.jet-popup__container-content', $popup ); 1530 1531 $popup.removeClass( 'jet-popup--loading-state' ); 1532 1533 if ( 'error' === successType ) { 1534 var message = data.message; 1535 1536 $content.html( '<h3>' + message + '</h3>' ); 1537 1538 // Show Popup Container 1539 animeContainerInstance = anime( animeContainer ); 1540 } 1541 1542 if ( 'success' === successType ) { 1543 let popupContent = contentData['content'], 1544 popupContentElements = contentData['contentElements'], 1545 popupScripts = contentData['scripts'], 1546 popupStyles = contentData['styles'], 1547 popupAfterScripts = contentData['afterScripts']; 1548 1549 for ( let { handle: scriptHandler, src: scriptSrc } of popupScripts ) { 1550 JetPopupFrontend.addedAssetsPromises.push( JetPopupFrontend.loadScriptAsync( scriptHandler, scriptSrc ) ); 1551 } 1552 1553 if ( popupStyles && Object.keys( popupStyles ).length > 0 ) { 1554 for ( let styleHandler in popupStyles ) { 1555 JetPopupFrontend.addedAssetsPromises.push( JetPopupFrontend.loadStyle( styleHandler, popupStyles[ styleHandler ] ) ); 1556 } 1557 } 1558 1559 JetPopupFrontend.assetsLoaderPromise().then( async function( value ) { 1560 ajaxContentLoaded = true; 1561 1562 // Ajax Success Trigger 1563 $window.trigger( 'jet-popup/render-content/ajax/success', { 1564 self: self, 1565 popup_id: id, 1566 data: popupData, 1567 request: data 1568 } ); 1569 1570 // Render content 1571 if ( popupContent ) { 1572 $popupContainer.html( popupContent ); 1573 } 1574 1575 if ( popupAfterScripts.length ) { 1576 await Promise.all( popupAfterScripts.map( 1577 ( { handle, src } ) => JetPopupFrontend.loadScriptAsync( handle, src ) 1578 ) ); 1579 } 1580 1581 // Before ajax frontend init 1582 $( window ).trigger( 'jet-popup/ajax/frontend-init/before', { 1583 $container: $popupContainer, 1584 content: popupContent, 1585 contentElements: popupContentElements, 1586 contentType: popupSettings['content-type'], 1587 } ); 1588 1589 // Frontend init 1590 $( window ).trigger( 'jet-popup/ajax/frontend-init', { 1591 $container: $popupContainer, 1592 content: popupContent, 1593 contentElements: popupContentElements, 1594 contentType: popupSettings['content-type'], 1595 } ); 1596
1597 // after ajax frontend init 1598 $( window ).trigger( 'jet-popup/ajax/frontend-init/after', { 1599 $container: $popupContainer, 1600 content: popupContent, 1601 contentElements: popupContentElements, 1602 contentType: popupSettings['content-type'], 1603 } ); 1604 1605 // Show Popup Container 1606 animeContainerInstance = anime( animeContainer ); 1607 1608 }, function( reason ) { 1609 console.log( 'Assets Loaded Error' ); 1610 } ); 1611 } 1612 } 1613 } ); 1614 }; 1615 1616 /** 1617 * Hide Popup 1618 * 1619 * @return {void} 1620 */ 1621 self.hidePopup = function ( data ) { 1622 var popupData = data || {}, 1623 $content = $( '.jet-popup__container-content', $popup ), 1624 constantly = popupData.constantly || false, 1625 animeOverlay = null, 1626 animeContainer = null, 1627 animeOverlaySettings = jQuery.extend( { targets: $( '.jet-popup__overlay', $popup )[0] }, self.avaliableEffects[ 'fade' ][ 'hide' ] ), 1628 animeContainerSettings = jQuery.extend( 1629 { 1630 targets: $( '.jet-popup__container', $popup )[0], 1631 begin: function( anime ) { 1632 isAnimation = true; 1633 1634 $window.trigger( 'jet-popup/hide-event/before-hide', { 1635 self: self, 1636 data: popupData, 1637 anime: anime 1638 } ); 1639 }, 1640 complete: function( anime ) { 1641 isAnimation = false; 1642 $popup.toggleClass( 'jet-popup--show-state jet-popup--hide-state' ); 1643 1644 if ( popupSettings['use-ajax'] && popupSettings['force-ajax'] ) { 1645 $content.html( '' ); 1646 } 1647 1648 if ( popupSettings['prevent-scrolling'] && !$( '.jet-popup--show-state' )[0] ) { 1649 $( 'body' ).removeClass( 'jet-popup-prevent-scroll' ); 1650 } 1651 1652 self.onPopupHidden(); 1653 1654 // After Popup Hide Action 1655 $window.trigger( 'jet-popup/hide-event/after-hide', { 1656 self: self, 1657 data: popupData, 1658 anime: anime 1659 } ); 1660 } 1661 }, 1662 self.avaliableEffects[ popupSettings['animation'] ][ 'hide' ] 1663 ); 1664 1665 if ( constantly ) { 1666 self.setLocalStorageData( popupId, 'disable' ); 1667 } 1668 1669 if ( isAnimation ){ 1670 return false; 1671 } 1672 1673 if ( $popup.hasClass('jet-popup--show-state') ) { 1674 animeOverlay = anime( animeOverlaySettings );
1675 animeContainer = anime( animeContainerSettings ); 1676 } 1677 1678 // On Hide Handler 1679 self.onHidePopupAction(); 1680 1681 // Before Popup Hide Action 1682 $window.trigger( 'jet-popup/close-hide-event/before-hide', { 1683 self: self, 1684 data: popupData 1685 } ); 1686 }; 1687 1688 /** 1689 * [elementorFrontendInit description] 1690 * @return {[type]} [description] 1691 */ 1692 self.elementorFrontendInit = function() { 1693 var $content = $( '.jet-popup__container-content', $popup ); 1694 1695 $content.find( 'div[data-element_type]' ).each( function() { 1696 var $this = $( this ), 1697 elementType = $this.data( 'element_type' ); 1698 1699 if (!elementType) { 1700 return; 1701 } 1702 1703 try { 1704 if( 'widget' === elementType ){ 1705 elementType = $this.data( 'widget_type' ); 1706 window.elementorFrontend.hooks.doAction( 'frontend/element_ready/widget', $this, $ ); 1707 } 1708 window.elementorFrontend.hooks.doAction( 'frontend/element_ready/' + elementType, $this, $ ); 1709 1710 } catch( err ) { 1711 console.log(err); 1712 1713 $this.remove(); 1714 1715 return false; 1716 } 1717 1718 }); 1719 1720 // On Show Handler 1721 self.onShowPopupAction(); 1722 } 1723 1724 /** 1725 * [onShowPopupAction description] 1726 * @return {[type]} [description] 1727 */ 1728 self.onShowPopupAction = function() {}; 1729 1730 /** 1731 * [onHidePopupAction description] 1732 * @return {[type]} [description] 1733 */ 1734 self.onHidePopupAction = function() {}; 1735 1736 /** 1737 * Avaliable Effects 1738 */ 1739 1740 const useCustomDuration = popupSettings['animation_custom_duration'] === true; 1741 1742 let inDuration = false; 1743 let outDuration = false; 1744 1745 if ( useCustomDuration ) { 1746 inDuration = popupSettings['animation_in_duration']; 1747 outDuration = popupSettings['animation_out_duration']; 1748 } 1749 1750 self.avaliableEffects = { 1751 'none': { 1752 'show': { 1753 duration: inDuration || 0, 1754 opacity: { value: [1, 1] } 1755 }, 1756 'hide': { 1757 duration: outDuration || 0, 1758 opacity: { value: [1, 1] } 1759 } 1760 }, 1761 1762 'fade': { 1763 'show': { 1764 opacity: { value: [0, 1], duration: inDuration || 600, easing: 'easeOutQuart' } 1765 }, 1766 'hide': { 1767 opacity: { value: [1, 0], duration: outDuration || 400, easing: 'easeOutQuart' } 1768 } 1769 }, 1770 1771 'zoom-in': { 1772 'show': { 1773 duration: inDuration || 500, 1774 easing: 'easeOutQuart', 1775 opacity: { value: [0, 1] }, 1776 scale: { value: [0.75, 1] } 1777 }, 1778 'hide': { 1779 duration: outDuration || 400, 1780 easing: 'easeOutQuart', 1781 opacity: { value: [1, 0] }, 1782 scale: { value: [1, 0.75] } 1783 } 1784 }, 1785 1786 'zoom-out': { 1787 'show': { 1788 duration: inDuration || 500, 1789 easing: 'easeOutQuart', 1790 opacity: { value: [0, 1] }, 1791 scale: { value: [1.25, 1] } 1792 }, 1793 'hide': { 1794 duration: outDuration || 400, 1795 easing: 'easeOutQuart', 1796 opacity: { value: [1, 0] }, 1797 scale: { value: [1, 1.25] } 1798 } 1799 }, 1800 1801 'rotate': { 1802 'show': { 1803 duration: inDuration || 500, 1804 easing: 'easeOutQuart', 1805 opacity: { value: [0, 1] }, 1806 scale: { value: [0.75, 1] }, 1807 rotate: { value: [-65, 0] } 1808 }, 1809 'hide': { 1810 duration: outDuration || 400, 1811 easing: 'easeOutQuart', 1812 opacity: { value: [1, 0] }, 1813 scale: { value: [1, 0.9] } 1814 } 1815 }, 1816 1817 'move-up': { 1818 'show': { 1819 duration: inDuration || 500, 1820 easing: 'easeOutExpo', 1821 opacity: { value: [0, 1] }, 1822 translateY: { value: [50, 1] } 1823 }, 1824 'hide': { 1825 duration: outDuration || 400, 1826 easing: 'easeOutQuart', 1827 opacity: { value: [1, 0] }, 1828 translateY: { value: [1, 50] } 1829 } 1830 }, 1831 1832 'flip-x': { 1833 'show': { 1834 duration: inDuration || 500, 1835 easing: 'easeOutExpo', 1836 opacity: { value: [0, 1] }, 1837 rotateX: { value: [65, 0] } 1838 }, 1839 'hide': { 1840 duration: outDuration || 400, 1841 easing: 'easeOutQuart', 1842 opacity: { value: [1, 0] } 1843 } 1844 }, 1845 1846 'flip-y': { 1847 'show': { 1848 duration: inDuration || 500, 1849 easing: 'easeOutExpo', 1850 opacity: { value: [0, 1] }, 1851 rotateY: { value: [65, 0] } 1852 }, 1853 'hide': { 1854 duration: outDuration || 400, 1855 easing: 'easeOutQuart', 1856 opacity: { value: [1, 0] } 1857 } 1858 }, 1859 1860 'bounce-in': { 1861 'show': { 1862 opacity: { value: [0, 1], duration: inDuration || 500, easing: 'easeOutQuart' }, 1863 scale: { 1864 value: [0.2, 1], 1865 duration: inDuration || 800, 1866 elasticity: function(el, i, l) { return (400 + i * 200); } 1867 } 1868 }, 1869 'hide': { 1870 duration: outDuration || 400, 1871 easing: 'easeOutQuart', 1872 opacity: { value: [1, 0] }, 1873 scale: { value: [1, 0.8] } 1874 } 1875 }, 1876 1877 'bounce-out': { 1878 'show': { 1879 opacity: { value: [0, 1], duration: inDuration || 500, easing: 'easeOutQuart' }, 1880 scale: { 1881 value: [1.8, 1], 1882 duration: inDuration || 800, 1883 elasticity: function(el, i, l) { return (400 + i * 200); } 1884 } 1885 }, 1886 'hide': { 1887 duration: outDuration || 400, 1888 easing: 'easeOutQuart', 1889 opacity: { value: [1, 0] }, 1890 scale: { value: [1, 1.5] } 1891 } 1892 }, 1893 1894 'slide-in-up': { 1895 'show': { 1896 opacity: { value: [0, 1], duration: inDuration || 400, easing: 'easeOutQuart' }, 1897 translateY: { value: ['100vh', 0], duration: inDuration || 750, easing: 'easeOutQuart' } 1898 }, 1899 'hide': { 1900 duration: outDuration || 400, 1901 easing: 'easeInQuart', 1902 opacity: { value: [1, 0] }, 1903 translateY: { value: [0, '100vh'] } 1904 } 1905 }, 1906 1907 'slide-in-right': { 1908 'show': { 1909 opacity: { value: [0, 1], duration: inDuration || 400, easing: 'easeOutQuart' }, 1910 translateX: { value: ['100vw', 0], duration: inDuration || 750, easing: 'easeOutQuart' } 1911 }, 1912 'hide': { 1913 duration: outDuration || 400, 1914 easing: 'easeInQuart', 1915 opacity: { value: [1, 0] }, 1916 translateX: { value: [0, '100vw'] } 1917 } 1918 }, 1919 1920 'slide-in-down': { 1921 'show': { 1922 opacity: { value: [0, 1], duration: inDuration || 400, easing: 'easeOutQuart' }, 1923 translateY: { value: ['-100vh', 0], duration: inDuration || 750, easing: 'easeOutQuart' } 1924 }, 1925 'hide': { 1926 duration: outDuration || 400, 1927 easing: 'easeInQuart', 1928 opacity: { value: [1, 0] }, 1929 translateY: { value: [0, '-100vh'] } 1930 } 1931 }, 1932 1933 'slide-in-left': { 1934 'show': { 1935 opacity: { value: [0, 1], duration: inDuration || 400, easing: 'easeOutQuart' }, 1936 translateX: { value: ['-100vw', 0], duration: inDuration || 750, easing: 'easeOutQuart' } 1937 }, 1938 'hide': { 1939 duration: outDuration || 400, 1940 easing: 'easeInQuart', 1941 opacity: { value: [1, 0] }, 1942 translateX: { value: [0, '-100vw'] } 1943 } 1944 } 1945 }; 1946 1947 1948 /** 1949 * Get localStorage data. 1950 * 1951 * @return {object|boolean} 1952 */ 1953 self.getLocalStorageData = function() { 1954 1955 try { 1956 return JSON.parse( localStorage.getItem( 'jetPopupData' ) ); 1957 } catch ( e ) { 1958 return false;
1959 } 1960 }; 1961 1962 /** 1963 * Set localStorage data. 1964 * 1965 * @return {object|boolean} 1966 */ 1967 self.setLocalStorageData = function( id, status ) { 1968 1969 var jetPopupData = self.getLocalStorageData() || {}, 1970 newData = {}; 1971 1972 newData['status'] = status; 1973 1974 if ( 'disable' === status ) { 1975 1976 var nowDate = Date.now(), 1977 showAgainDelay = popupSettings['show-again-delay'], 1978 showAgainDate = 'none' !== showAgainDelay ? ( nowDate + showAgainDelay ) : 'none'; 1979 1980 newData['show-again-date'] = showAgainDate; 1981 } 1982 1983 jetPopupData[ id ] = newData; 1984 1985 localStorage.setItem( 'jetPopupData', JSON.stringify( jetPopupData ) ); 1986 } 1987 1988 } 1989 1990 window.JetPopupFrontend.init(); 1991 1992}( jQuery ) );
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.