1(function( $ ) { 2 3 'use strict'; 4 5 var JetSearch = { 6 7 addedScripts: [], 8 addedStyles: [], 9 addedPostCSS: [], 10 assetsPromises: [], 11 popupEventsInited: false, 12 chosenSearchInputId: 0, 13 14 initElementor: function() { 15 JetSearch.initPopupEvents(); 16 17 var widgets = { 18 'jet-ajax-search.default': JetSearch.widgetAjaxSearch, 19 'jet-search-suggestions.default': JetSearch.widgetSearchSuggestions 20 }; 21 22 $.each( widgets, function( widget, callback ) { 23 window.elementorFrontend.hooks.addAction( 'frontend/element_ready/' + widget, callback ); 24 } ); 25 26 // Re-init widgets in nested tabs 27 window.elementorFrontend.elements.$window.on( 28 'elementor/nested-tabs/activate', 29 ( event, content ) => { 30 31 const $content = $( content ); 32 JetSearch.reinitSlickSlider( $content ); 33 JetSearch.initElementsHandlers( $content ); 34 } 35 ); 36 37 window.addEventListener( 'elementor/popup/show', ( event ) => { 38 const instance = event.detail.instance; 39 40 const interval = setInterval( () => { 41 42 if ( ! instance.keyboardHandler ) return; 43 44 const handler = instance.keyboardHandler; 45 const config = handler.config; 46 47 if ( ! config || ! config.$modalElements ) return; 48 49 if ( handler.changeFocusAfterAnimation !== true ) { 50 clearInterval( interval ); 51 return; 52 } 53 54 const $input = instance.$element.find('.jet-ajax-search__field'); 55 56 if ( $input.length ) { 57 handler.firstFocusableElement = $input[0]; 58 } 59 60 clearInterval( interval ); 61 62 }, 50) ; 63 64 setTimeout( () => clearInterval( interval ), 1000 ); 65 66 }); 67 68 /* 69 // Example of usage AJAX success trigger 70 $( document ).on( 'jet-ajax-search/show-results', function( event, searchResults ) { 71 searchResults.find( '.jet-ajax-search__results-item' ).css( 'border', '2px solid red' ); 72 } ); 73 */ 74 75 /* 76 * Example of usage `jet-ajax-search/results-area/listing-add-suggestion` trigger 77 * 78 * Parameters: 79 * - itemWrapper: A CSS selector that points to the element containing the wrapper of the search result item. 80 * - itemLink: Represents the element that contains the link of the search result item. 81 * - itemTitle: A CSS selector that points to the element containing the title of the search result item. 82 * - itemUrlAttr: Specifies the attribute used to extract the URL from the itemLink. 83 $( document ).on( "jet-ajax-search/results-area/listing-add-suggestion", function( event, itemWrapper, itemLink, itemTitle, itemUrlAttr ) { 84 itemWrapper = '.jet-ajax-search__results-item', 85 itemLink = $( '.jet-listing-dynamic-image__link', itemWrapper ); 86 itemTitle = '.jet-ajax-search-item-title .jet-listing-dynamic-field__content'; 87 itemUrlAttr = 'href'; 88 89 window.JetSearch.addSuggestionFromResultAreaItem( itemWrapper, itemLink, itemTitle, itemUrlAttr ); 90 } ); 91 */ 92 }, 93 94 initBricks: function( $scope ) { 95 96 if ( window.bricksIsFrontend ) { 97 return; 98 } 99 100 $scope = $scope || $( 'body' ); 101 102 JetSearch.initPopupEvents(); 103 JetSearch.initBlocks( $scope ); 104 105 }, 106 107 initBlocks: function( $scope ) { 108 109 $scope = $scope || $( 'body' ); 110 JetSearch.initPopupEvents(); 111 112 window.JetPlugins.init( $scope, [ 113 { 114 block: 'jet-search/ajax-search', 115 callback: JetSearch.widgetAjaxSearch 116 }, 117 { 118 block: 'jet-search/search-suggestions', 119 callback: JetSearch.widgetSearchSuggestions 120 } 121 ] ); 122 }, 123 124 setChosenSearchInputLabel: function( $select ) { 125 $select.each( function( index ) { 126 var $currentSelect = $( this ), 127 label = $currentSelect.attr( 'data-placeholder' ) || $currentSelect.find( 'option:first' ).text() || 'Search category', 128 selectId = $currentSelect.attr( 'id' ), 129 $chosenInput = $currentSelect 130 .next( '.chosen-container' ) 131 .find( '.chosen-search-input' ); 132 133 if ( ! $chosenInput.attr( 'id' ) ) { 134 if ( ! selectId ) { 135 JetSearch.chosenSearchInputId++; 136 selectId = 'jet-search-categories-select-' + JetSearch.chosenSearchInputId + '-' + index; 137 } 138 139 $chosenInput.attr( 'id', selectId + '__chosen_search' ); 140 } 141 142 if ( ! $chosenInput.attr( 'aria-label' ) && ! $chosenInput.attr( 'aria-labelledby' ) ) { 143 $chosenInput.attr( 'aria-label', label ); 144 } 145 } ); 146 }, 147 148 closeAjaxPopup: function( $widget, restoreFocus = false ) { 149 150 if ( ! $widget || ! $widget.length ) { 151 return; 152 } 153 154 const activeClass = 'jet-ajax-search-popup-active', 155 transitionOutClass = 'jet-ajax-search-transition-out', 156 $trigger = $widget.find( '.jet-ajax-search__popup-trigger' ), 157 $popup = $widget.find( '.jet-ajax-search__popup' ), 158 $input = $widget.find( '.jet-ajax-search__field' ), 159 $form = $widget.find( '.jet-ajax-search__form' ), 160 $resultsArea = $widget.find( '.jet-ajax-search__results-area' ); 161 162 if ( ! $widget.hasClass( activeClass ) ) { 163 return; 164 } 165 166 $widget.removeClass( activeClass ).addClass( transitionOutClass ); 167 $trigger.attr( 'aria-expanded', 'false' ); 168 $popup.attr( 'aria-hidden', 'true' ); 169 $form.removeClass( 'jet-ajax-search__form--focus' ); 170 $resultsArea.removeClass( 'show' ); 171 $widget.find( '.chosen-single' ).removeClass( 'focused' ); 172 $input.trigger( 'blur' ); 173 174 setTimeout( function() { 175 $widget.removeClass( transitionOutClass ); 176 }, 300 ); 177 178 if ( restoreFocus ) { 179 $trigger.trigger( 'focus' ); 180 } 181 }, 182 183 markPopupDropdownInteraction: function( $widget, timeout = 300 ) { 184 185 if ( ! $widget || ! $widget.length ) { 186 return; 187 } 188 189 const timer = $widget.data( 'jetSearchPopupDropdownTimer' ); 190 191 if ( timer ) { 192 clearTimeout( timer ); 193 } 194 195 $widget.data( 'jetSearchPopupDropdownInteraction', true ); 196 $widget.data( 'jetSearchPopupDropdownTimer', setTimeout( function() { 197 $widget.removeData( 'jetSearchPopupDropdownInteraction' ); 198 $widget.removeData( 'jetSearchPopupDropdownTimer' ); 199 }, timeout ) ); 200 }, 201 202 syncAjaxPopupWidth: function( $widget ) { 203 204 if ( ! $widget || ! $widget.length ) { 205 return; 206 } 207 208 const $popupContent = $widget.find( '.jet-ajax-search__popup-content' ); 209 210 if ( $popupContent.length ) { 211 $popupContent.css( 'min-width', '' ); 212 } 213 }, 214 215 openAjaxPopup: function( $widget ) { 216 217 if ( ! $widget || ! $widget.length ) { 218 return; 219 } 220 221 const activeClass = 'jet-ajax-search-popup-active', 222 transitionInClass = 'jet-ajax-search-transition-in', 223 $trigger = $widget.find( '.jet-ajax-search__popup-trigger' ), 224 $popup = $widget.find( '.jet-ajax-search__popup' ), 225 $input = $widget.find( '.jet-ajax-search__field' ); 226 227 if ( $widget.hasClass( activeClass ) ) { 228 return; 229 } 230 231 $( '.jet-ajax-search.' + activeClass ).each( function() { 232 JetSearch.closeAjaxPopup( $( this ) ); 233 } ); 234 235 $widget.addClass( transitionInClass ); 236 $trigger.attr( 'aria-expanded', 'true' ); 237 $popup.attr( 'aria-hidden', 'false' ); 238 JetSearch.syncAjaxPopupWidth( $widget ); 239 240 setTimeout( function() { 241 JetSearch.syncAjaxPopupWidth( $widget ); 242 $widget.removeClass( transitionInClass ).addClass( activeClass ); 243 $input.trigger( 'focus' ); 244 }, 300 ); 245 }, 246 247 toggleAjaxPopup: function( event ) { 248 event.preventDefault(); 249 event.stopPropagation(); 250 251 const $trigger = $( event.currentTarget ), 252 $widget = $trigger.closest( '.jet-ajax-search' ); 253 254 if ( $widget.hasClass( 'jet-ajax-search-popup-active' ) ) { 255 JetSearch.closeAjaxPopup( $widget, true ); 256 } else { 257 JetSearch.openAjaxPopup( $widget ); 258 } 259 }, 260 261 initPopupEvents: function() { 262 263 if ( JetSearch.popupEventsInited ) { 264 return; 265 } 266 267 JetSearch.popupEventsInited = true; 268 269 $( document ) 270 .on( 'click.jetSearchPopup', '.jet-ajax-search__popup-trigger, .jet-ajax-search__popup-close', JetSearch.toggleAjaxPopup ) 271 .on( 'click.jetSearchPopup', function( event ) { 272 const $target = $( event.target ), 273 $activePopupWithDropdownInteraction = $( '.jet-ajax-search.jet-ajax-search-popup-active' ).filter( function() { 274 return !! $( this ).data( 'jetSearchPopupDropdownInteraction' ); 275 } ); 276 277 if ( $target.closest( '.jet-ajax-search__popup-trigger, .jet-ajax-search__popup-content, .chosen-container, .chosen-drop' ).length ) { 278 return; 279 } 280 281 if ( $activePopupWithDropdownInteraction.length ) { 282 return; 283 } 284 285 if ( 286 $( '.jet-ajax-search.jet-ajax-search-popup-active .chosen-container.chosen-with-drop' ).length && 287 ! $target.closest( '.jet-ajax-search__popup-trigger, .jet-ajax-search__popup-close' ).length 288 ) { 289 return; 290 } 291 292 $( '.jet-ajax-search.jet-ajax-search-popup-active' ).each( function() { 293 JetSearch.closeAjaxPopup( $( this ) ); 294 } ); 295 } ) 296 .on( 'keydown.jetSearchPopup', function( event ) { 297 if ( 'Escape' !== event.key && 27 !== event.keyCode ) { 298 return; 299 } 300 301 $( '.jet-ajax-search.jet-ajax-search-popup-active' ).each( function() { 302 JetSearch.closeAjaxPopup( $( this ), true ); 303 } ); 304 } ); 305 }, 306 307 widgetAjaxSearch: function( $scope ) { 308 309 var settings = { 310 searchClass: '.jet-ajax-search', 311 searchFormClass: '.jet-ajax-search__form', 312 fieldsHolderClass: '.jet-ajax-search__fields-holder', 313 inputClass: '.jet-ajax-search__field', 314 settingsInput: 'input[name="jet_ajax_search_settings"]', 315 submitClass: '.jet-ajax-search__submit', 316 chosenClass: '.jet-ajax-search__categories select[name="jet_ajax_search_categories"]', 317 resultsAreaClass: '.jet-ajax-search__results-area', 318 resultsHeaderClass: '.jet-ajax-search__results-header', 319 resultsFooterClass: '.jet-ajax-search__results-footer', 320 listHolderClass: '.jet-ajax-search__results-holder', 321 listClass: '.jet-ajax-search__results-list', 322 listInnerClass: '.jet-ajax-search__results-list-inner', 323 listSlideClass: '.jet-ajax-search__results-slide', 324 itemClass: '.jet-ajax-search__results-item', 325 inlineSuggestionsAreaClass: '.jet-ajax-search__suggestions-inline-area', 326 inlineSuggestionsItemClass: '.jet-ajax-search__suggestions-inline-area-item', 327 resultsSuggestionsAreaClass: '.jet-ajax-search__results-suggestions-area', 328 resultsSuggestionItemClass: '.jet-ajax-search__results-suggestions-area-item', 329 countClass: '.jet-ajax-search__results-count', 330 messageHolderClass: '.jet-ajax-search__message', 331 fullResultsClass: '.jet-ajax-search__full-results', 332 navigationClass: '.jet-ajax-search__navigation-holder', 333 navButtonClass: '.jet-ajax-search__navigate-button', 334 bulletClass: '.jet-ajax-search__bullet-button', 335 numberClass: '.jet-ajax-search__number-button', 336 prevClass: '.jet-ajax-search__prev-button', 337 nextClass: '.jet-ajax-search__next-button', 338 activeNavClass: '.jet-ajax-search__active-button', 339 disableNavClass: '.jet-ajax-search__navigate-button-disable', 340 spinnerClass: '.jet-ajax-search__spinner-holder', 341 handlerId: 'jetSearchSettings', 342 isRtl: ( window.elementorFrontend && window.elementorFrontend.config.is_rtl ) ? window.elementorFrontend.config.is_rtl : $( 'body' ).hasClass( 'rtl' ) 343 }; 344 345 if ( $scope.hasClass('jet-ajax-search-block') ) { 346 var resultAreaWidthBy = $scope.find( settings.searchClass ).data('settings')['results_area_width_by'], 347 resultAreaCustomWidth = $scope.find( settings.searchClass ).data('settings')['results_area_custom_width'], 348 resultAreaCustomWidthPosition = $scope.find( settings.searchClass ).data('settings')['results_area_custom_position'], 349 resultAreaContainer = $( '.jet-ajax-search__results-area', $scope ); 350 351 if ( "custom" === resultAreaWidthBy ) { 352 if ( "" !== resultAreaCustomWidth ) { 353 resultAreaContainer.width( resultAreaCustomWidth ); 354 } 355 356 switch( resultAreaCustomWidthPosition ) { 357 case 'left': 358 resultAreaContainer.css( "left", 0 ); 359 resultAreaContainer.css( "right", "auto" ); 360 break; 361 case 'center': 362 resultAreaContainer.css( "left", "50%" ); 363 resultAreaContainer.css( "right", "auto" ); 364 resultAreaContainer.css( "-webkit-transform", "translateX(-55%)" ); 365 resultAreaContainer.css( "transform", "translateX(-50%)" ); 366 break; 367 case 'right': 368 resultAreaContainer.css( "left", "auto" ); 369 resultAreaContainer.css( "right", 0 ); 370 break; 371 } 372 } 373 } 374 375 $scope.find( settings.searchClass ).jetAjaxSearch( settings ); 376 377 $scope.find( settings.inputClass ) 378 .on( 'focus.jetSearchSlick input.jetSearchSlick', function() { 379 window.JetSearch.pauseAllSlick( $( document ) ); 380 }) 381 .on( 'blur.jetSearchSlick', function() { 382 window.JetSearch.playAllSlick( $( document ) ); 383 }); 384 385 var $chosenSelect = $scope.find( settings.chosenClass ); 386 387 if ( $chosenSelect[0] ) { 388 $chosenSelect.chosen( { 389 disable_search: true, 390 placeholder_text: '', 391 placeholder_text_single: '' 392 } ); 393 394 JetSearch.setChosenSearchInputLabel( $chosenSelect ); 395 } 396 }, 397 398 widgetSearchSuggestions: function( $scope ) { 399 400 let $target = $scope.find( '.jet-search-suggestions' ), 401 settings = { 402 searchClass: '.jet-search-suggestions', 403 searchFormClass: '.jet-search-suggestions__form', 404 fieldsHolderClass: '.jet-search-suggestions__fields-holder', 405 inputClass: '.jet-search-suggestions__field', 406 spinnerClass: '.jet-search-suggestions__spinner-holder', 407 messageHolderClass: '.jet-search-suggestions__message', 408 settingsInput: 'input[name="jet_search_suggestions_settings"]', 409 submitClass: '.jet-search-suggestions__submit', 410 chosenClass: '.jet-search-suggestions__categories select[name="jet_search_suggestions_categories"]', 411 inlineClass: '.jet-search-suggestions__inline-area', 412 inlineItemClass: '.jet-search-suggestions__inline-area-item', 413 focusClass: '.jet-search-suggestions__focus-area', 414 focusHolderClass: '.jet-search-suggestions__focus-results-holder', 415 focusItemClass: '.jet-search-suggestions__focus-area-item', 416 handlerId: 'jetSearchSettings', 417 isRtl: ( window.elementorFrontend && window.elementorFrontend.config.is_rtl ) ? window.elementorFrontend.config.is_rtl : $( 'body' ).hasClass( 'rtl' ) 418 }, 419 $chosenSelect = $scope.find( settings.chosenClass ); 420 421 $target.jetAjaxSearchSuggestions( settings ); 422 423 if ( $chosenSelect[0] ) { 424 $chosenSelect.chosen( { 425 disable_search: true, 426 placeholder_text: '', 427 placeholder_text_single: '' 428 } ); 429 430 JetSearch.setChosenSearchInputLabel( $chosenSelect ); 431 } 432 }, 433 434 setFormSuggestion: function( name, form, url = '' ) { 435 const ajaxSettings = window['jetSearchSettings']['searchSuggestions'] || {}, 436 sendData = { 437 name: name 438 }, 439 nonce = ajaxSettings.nonce_rest; 440 441 const ajaxData = { 442 action: ajaxSettings.add_action, 443 data: sendData || {}, 444 nonce: ajaxSettings.nonce 445 }; 446 447 $.ajax( { 448 type: 'POST', 449 url: ajaxSettings.add_suggestions_rest_api_url, 450 data: ajaxData, 451 dataType: 'json', 452 beforeSend: function( jqXHR ) { 453 jqXHR.setRequestHeader( 'X-WP-Nonce', nonce ); 454 }, 455 complete: function() { 456 if ( false != form ) {
457 if ( '' != url ) { 458 url = JetSearch.getResultsUrl( form, url ); 459 460 window.location.href = url; 461 } else { 462 form.submit(); 463 } 464 } else { 465 window.location.href = url; 466 } 467 } 468 } ); 469 }, 470 getResultsUrl: function( form, url = '' ) { 471 let redirectUrl = ''; 472 473 if ( '' != url ) { 474 redirectUrl = url; 475 } else { 476 redirectUrl = form.attr( 'action' ); 477 } 478 479 if ( redirectUrl && ! redirectUrl.startsWith( 'http' ) && ! redirectUrl.startsWith( '/' ) ) { 480 const actionBase = ( form.attr( 'action' ) || '/' ).replace( /\/+$/, '' ); 481 482 redirectUrl = actionBase + '/' + redirectUrl.replace( /^\/+/, '' ); 483 } 484 485 let formData = {}, 486 result = ''; 487 488 formData = form.serializeArray().reduce( function( obj, item ) { 489 if ( item.name === 's' ) { 490 item.value = item.value.replace(/\u3000/g, ' '); 491 } 492 493 obj[item.name] = item.value; 494 495 return obj; 496 }, {} ); 497 498 if ( Object.keys( formData ).length > 0 ) { 499 const queryString = $.param( formData ).replace(/=&/g, '&').replace(/=$/, '' ); 500 const separator = redirectUrl.indexOf( '?' ) === -1 ? '?' : '&'; 501 502 result = redirectUrl + separator + queryString; 503 } else { 504 result = redirectUrl; 505 } 506 507 return result; 508 }, 509 suggestionsPreloader: function( is_active, state, preloader ) { 510 if ( ! is_active ) { 511 return; 512 } 513 514 if ( '' != preloader ) { 515 if ( 'show' === state ) { 516 preloader.addClass( 'show' ); 517 } else if ( 'hide' === state ) { 518 preloader.removeClass( 'show' ); 519 } 520 } 521 }, 522 getUrlParams: function() { 523 let params = {}, 524 queryString = window.location.search.slice(1); 525 526 if ( queryString ) { 527 let pairs = queryString.split( '&' ); 528 529 for ( let i = 0; i < pairs.length; i++ ) { 530 let pair = pairs[i].split( '=' ); 531 532 params[pair[0]] = decodeURIComponent( pair[1] || '' ); 533 } 534 } 535 536 return params; 537 }, 538 md5: function(str) { 539 let hash = ''; 540 541 for (let i = 0; i < str.length; i++) { 542 let char = str.charCodeAt(i); 543 hash += char; 544 } 545 return hash; 546 }, 547 generateHash: function( string, length = 6 ) { 548 let md5Hash = JetSearch.md5( string ), 549 hash = ''; 550 551 for ( let i = 0; i < length; i++ ) { 552 hash += md5Hash.charAt( Math.floor( Math.random() * md5Hash.length ) ); 553 } 554 555 hash = hash.toLowerCase(); 556 557 return hash; 558 }, 559 generateRandomId: function() { 560 let hash = JetSearch.generateHash( Math.random().toString() ); 561 562 return hash; 563 }, 564 initElementsHandlers: function( $selector ) { 565 // Actual init 566 window.JetPlugins.init( $selector ); 567 568 // Legacy Elementor-only init 569 $selector.find( '[data-element_type]' ).each( function() { 570 var excludeWidgets = [ 571 'jet-form-builder-form.default', 572 'nav-menu.default', 573 'jet-woo-product-gallery-slider.default', 574 'accordion.default' 575 ]; 576 577 var $this = $( this ), 578 elementType = $this.data( 'element_type' ); 579 580 if ( !elementType ) { 581 return; 582 } 583 584 if ( 'widget' === elementType ) { 585 elementType = $this.data( 'widget_type' ); 586 587 if ( excludeWidgets.includes( elementType ) ) { 588 return; 589 } 590 591 window.elementorFrontend.hooks.doAction( 'frontend/element_ready/widget', $this, $ ); 592 } 593 594 window.elementorFrontend.hooks.doAction( 'frontend/element_ready/global', $this, $ ); 595 window.elementorFrontend.hooks.doAction( 'frontend/element_ready/' + elementType, $this, $ ); 596 } ); 597 598 if ( window.elementorFrontend ) { 599 const elementorLazyLoad = new Event( "elementor/lazyload/observe" ); 600 document.dispatchEvent( elementorLazyLoad ); 601 } 602 603 if ( window.JetPopupFrontend && window.JetPopupFrontend.initAttachedPopups ) { 604 window.JetPopupFrontend.initAttachedPopups( $selector ); 605 } 606 }, 607 reinitSlickSlider: function( $scope ) { 608 var $slider = $scope.find('.slick-initialized'); 609 610 if ( $slider.length ) { 611 612 $slider.each( function() { 613 $( this ).slick('unslick'); 614 } ); 615 } 616 }, 617 618 toggleSlickAutoplay: function( $root, shouldPlay ) { 619 const $slicks = $root ? $root.find( '.slick-initialized' ) : $( '.slick-initialized' ); 620 621 $slicks.each( function(){
622 try { 623 $( this ).slick( shouldPlay ? 'slickPlay' : 'slickPause' ); 624 } catch(e) {} 625 }); 626 }, 627 628 pauseAllSlick: function( $root ) { 629 this.toggleSlickAutoplay( $root || $( document ), false ); 630 }, 631 632 playAllSlick: function( $root ) { 633 setTimeout( () => this.toggleSlickAutoplay( $root || $( document ), true ), 60 ); 634 }, 635 636 enqueueAssetsFromResponse: function( response ) { 637 if ( response.data.scripts ) { 638 JetSearch.enqueueScripts( response.data.scripts ); 639 } 640 641 if ( response.data.styles ) { 642 JetSearch.enqueueStyles( response.data.styles ); 643 } 644 }, 645 646 enqueueScripts: function( scripts ) { 647 $.each( scripts, function( handle, scriptHtml ) { 648 JetSearch.enqueueScript( handle, scriptHtml ) 649 } ); 650 }, 651 652 enqueueStyles: function( styles ) { 653 $.each( styles, function( handle, styleHtml ) { 654 JetSearch.enqueueStyle( handle, styleHtml ) 655 } ); 656 }, 657 658 enqueueScript: function( handle, scriptHtml ) { 659 660 if ( -1 !== JetSearch.addedScripts.indexOf( handle ) ) { 661 return; 662 } 663 664 if ( ! scriptHtml ) { 665 return; 666 } 667 668 var selector = 'script[id="' + handle + '-js"]'; 669 670 if ( $( selector ).length ) { 671 return; 672 } 673 674 var scriptsTags = scriptHtml.match( /<script[\s\S]*?<\/script>/gm ); 675 676 if ( scriptsTags.length ) { 677 678 for ( var i = 0; i < scriptsTags.length; i++ ) { 679 680 JetSearch.assetsPromises.push( 681 new Promise( function( resolve, reject ) { 682 683 var $tag = $( scriptsTags[i] ); 684 685 if ( $tag[0].src ) { 686 687 var tag = document.createElement( 'script' ); 688 689 tag.type = $tag[0].type; 690 tag.src = $tag[0].src; 691 tag.id = $tag[0].id; 692 tag.async = false; 693 tag.onload = function() { 694 resolve(); 695 }; 696 697 document.body.append( tag ); 698 } else { 699 $( 'body' ).append( scriptsTags[i] ); 700 resolve(); 701 } 702 } ) 703 ); 704 } 705 } 706 707 JetSearch.addedScripts.push( handle ); 708 }, 709 710 enqueueStyle: function( handle, styleHtml ) { 711 712 if ( -1 !== handle.indexOf( 'google-fonts' ) ) { 713 JetSearch.enqueueGoogleFonts( handle, styleHtml ); 714 return; 715 } 716 717 if ( -1 !== JetSearch.addedStyles.indexOf( handle ) ) { 718 return; 719 } 720 721 var selector = 'link[id="' + handle + '-css"],style[id="' + handle + '"]'; 722 723 if ( $( selector ).length ) { 724 return; 725 } 726 727 $( 'head' ).append( styleHtml ); 728 729 JetSearch.addedStyles.push( handle ); 730 731 if ( -1 !== handle.indexOf( 'elementor-post' ) ) { 732 var postID = handle.replace( 'elementor-post-', '' ); 733 JetSearch.addedPostCSS.push( postID ); 734 } 735 }, 736 737 enqueueGoogleFonts: function( handle, styleHtml ) { 738 739 var selector = 'link[id="' + handle + '-css"]'; 740 741 if ( $( selector ).length ) {} 742 743 $( 'head' ).append( styleHtml ); 744 }, 745 746 reinitBricksScripts: function( _this ) { 747 748 if ( !$( 'body' ).hasClass( 'theme-bricks' ) && !$( 'body' ).hasClass( 'bricks-is-frontend') ) { 749 return; 750 } 751 752 const resultsArea = $( '.jet-ajax-search__results-list', _this ); 753 const sourcesHolder = $( '.jet-ajax-search__source-results-holder', _this ); 754 755 //Results Area 756 resultsArea.find( '[data-script-id]' ).each( function() { 757 const newId = JetSearch.generateRandomId(); 758 759 $( this ).attr( 'data-script-id', newId ); 760 } ); 761 762 resultsArea.find( '[id^="brxe-"]' ).each( function() { 763 var id = $( this ).attr( 'id' ); 764 765 $( this ).addClass( id ); 766 } ); 767 768 const bricksScripts = { 769 ".bricks-lightbox": 'bricksPhotoswipe', 770 ".brxe-accordion, .brxe-accordion-nested": 'bricksAccordion', 771 ".brxe-animated-typing": 'bricksAnimatedTyping', 772 ".brxe-audio": 'bricksAudio', 773 ".brxe-countdown": 'bricksCountdown', 774 ".brxe-counter": 'bricksCounter', 775 ".brxe-video": 'bricksVideo', 776 ".bricks-lazy-hidden": 'bricksLazyLoad', 777 ".brx-animated": 'bricksAnimation', 778 ".brxe-pie-chart": 'bricksPieChart', 779 ".brxe-progress-bar .bar span": 'bricksProgressBar', 780 ".brxe-form": 'bricksForm', 781 ".brx-query-trail": 'bricksInitQueryLoopInstances', 782 "[data-interactions]": 'bricksInteractions', 783 ".brxe-alert svg": 'bricksAlertDismiss', 784 ".brxe-tabs, .brxe-tabs-nested": 'bricksTabs', 785 ".bricks-video-overlay, .bricks-video-overlay-icon, .bricks-video-preview-image": 'bricksVideoOverlayClickDetector',
786 ".bricks-background-video-wrapper": 'bricksBackgroundVideoInit', 787 ".brxe-toggle": 'bricksToggle', 788 ".brxe-offcanvas": 'bricksOffcanvas', 789 '.brxe-slider': 'bricksSwiper', 790 '.brxe-slider-nested': 'bricksSplide', 791 '.brxe-image': 'bricksSwiper' 792 }; 793 794 const contentWrapper = resultsArea[0]; 795 796 //Result Area 797 for ( const key in bricksScripts ) { 798 const widget = contentWrapper.querySelector(key); 799 800 if ( widget && typeof window[bricksScripts[key]] === "function" && bricksScripts[key] ) { 801 window[bricksScripts[key]](); 802 } 803 } 804 805 //Sources Holder 806 if ( sourcesHolder.length ) { 807 sourcesHolder.find( '[data-script-id]' ).each( function() { 808 const newId = JetSearch.generateRandomId(); 809 810 $( this ).attr( 'data-script-id', newId ); 811 } ); 812 813 sourcesHolder.find( '[id^="brxe-"]' ).each( function() { 814 var id = $( this ).attr( 'id' ); 815 816 $( this ).addClass( id ); 817 } ); 818 819 const sourcesWrapper = sourcesHolder[0]; 820 821 for ( const key in bricksScripts ) { 822 const widget = sourcesWrapper.querySelector( key ); 823 824 if ( widget && typeof window[bricksScripts[key]] === "function" && bricksScripts[key] ) { 825 window[bricksScripts[key]](); 826 } 827 } 828 } 829 }, 830 831 getCurrentDeviceMode: function() { 832 const width = window.innerWidth; 833 834 if ( width > 1024 ) { 835 return 'desktop'; 836 } else if ( width <= 1024 && width > 767 ) { 837 return 'tablet'; 838 } else { 839 return 'mobile'; 840 } 841 }, 842 843 trimString: function( str, numWords ) { 844 if ( typeof str !== 'string' ) { 845 return str; 846 } 847 848 let wordsArray = str.split( ' ' ); 849 850 if ( wordsArray.length <= numWords ) { 851 return str; 852 } 853 854 let truncatedString = wordsArray.slice( 0, numWords ).join( ' ' ); 855 856 return truncatedString + '...'; 857 }, 858 859 escapeHTML: function( str ) { 860 return str.replace(/[&<>"']/g, function ( match ) { 861 const escapeMap = { 862 '&': '&', 863 '<': '<', 864 '>': '>', 865 '"': '"', 866 "'": ''' 867 }; 868 869 return escapeMap[match]; 870 } ); 871 }, 872 873 addSuggestionFromResultAreaItem: function( itemWrapper, itemLink, itemTitle, itemUrlAttr ) { 874 itemLink.on( 'click', function( e ) { 875 e.stopImmediatePropagation(); 876 e.preventDefault(); 877 878 let item = $( this ).closest( itemWrapper ), 879 value = $( itemTitle, item ).text(), 880 url = $( this ).attr( itemUrlAttr ); 881 882 JetSearch.setFormSuggestion( value, false, url ); 883 } ); 884 } 885 }; 886 887 $.fn.getSuggestionsList = function( options, settings, showSpinner, hightlightText = false, callback = () => {} ) { 888 let self = this[0], 889 outputHtml = '', 890 listPosition = options.list_position, 891 inlineItemTemplate = wp.template( 'jet-search-inline-suggestion-item' ), 892 focusItemTemplate = wp.template( 'jet-search-focus-suggestion-item' ), 893 spinner = $( settings.spinnerClass, self ), 894 manualList = []; 895 896 const ajaxSettings = window['jetSearchSettings']['searchSuggestions'] || {}; 897 898 function highlightMatches( item ) { 899 let searched = options.value.trim(); 900 901 if ( searched !== "" ) { 902 let reg = new RegExp("[\>][^\<]*"+searched+"[^\<]*[\<]","gi"), 903 reg2 = new RegExp( searched, "gi" ), 904 regHtml = new RegExp("<\/?[a-z](.*?)[\s\S]*>", "gi"); 905 906 if ( reg.test( item ) ) { 907 item = item.replace( reg, function( item ) { 908 let subRegex = new RegExp( searched, "gi" ); 909 return item.replace( subRegex,`<mark>${searched}</mark>` ); 910 } ); 911 } 912 913 if ( regHtml.test( item ) ) { 914 return item; 915 } else { 916 item = item.replace( reg2, str => `<mark>${str}</mark>` ); 917 } 918 } 919 920 return item; 921 } 922 923 if ( 'manual' === options.list_type ) { 924 925 if ( options['manual_list'].length ) { 926 let list = options['manual_list'].split( "," ); 927 928 list.map( function( suggestion, i ) { 929 manualList[i] = { name: suggestion }; 930 } ); 931 932 if ( 'inline' === listPosition ) { 933 manualList.map( function( suggestion ) { 934 outputHtml += inlineItemTemplate( suggestion ); 935 } ); 936 937 $( self ).html( outputHtml ); 938 } else if ( 'focus' === listPosition ) { 939 manualList.map( function( suggestion ) { 940 outputHtml += focusItemTemplate( suggestion ); 941 } ); 942 943 $( settings.focusHolderClass ,self ).html( outputHtml ); 944 945 if ( typeof callback === 'function' ) { 946 callback(); 947 } 948 949 JetSearch.suggestionsPreloader( showSpinner, 'hide', spinner ); 950 } 951 } 952 953 return; 954 } 955 956 let sendData = { 957 list_type: options.list_type || '', 958 value: options.value || '', 959 limit: options.limit 960 }, 961 ajaxData = { 962 action: ajaxSettings.get_action, 963 data: sendData || {}, 964 }; 965 966 jQuery.ajax( { 967 type: 'GET', 968 url: ajaxSettings.get_suggestions_rest_api_url, 969 data: ajaxData, 970 dataType: 'json', 971 cache: false, 972 processData: true, 973 error: function( jqXHR, textStatus, errorThrown ) { 974 errorCallback( jqXHR ); 975 }, 976 success: function( response, textStatus, jqXHR ) { 977 successCallback( response ); 978 if ( typeof callback === 'function' ) { 979 callback(); 980 } 981 } 982 } ); 983 984 const successCallback = function( response ) { 985 986 if ( response ) { 987 JetSearch.suggestionsPreloader( showSpinner, 'hide', spinner ); 988 989 if ( 'inline' === listPosition ) { 990 response.map( function( suggestion ) { 991 suggestion['name'] = JetSearch.escapeHTML( suggestion['name'] ); 992 suggestion['fullName'] = JetSearch.escapeHTML( suggestion['name'] ); 993 994 if ( 0 < options.maxLength ) { 995 suggestion['name'] = JetSearch.trimString( suggestion['name'], options.maxLength ); 996 } 997 998 outputHtml += inlineItemTemplate( suggestion ); 999 } ); 1000 1001 $( self ).html( outputHtml ); 1002 } else if ( 'focus' === listPosition ) { 1003 1004 response.map( function( suggestion ) { 1005 suggestion['name'] = JetSearch.escapeHTML( suggestion['name'] ); 1006 suggestion['fullName'] = JetSearch.escapeHTML( suggestion['name'] ); 1007 1008 if ( 0 < options.maxLength ) { 1009 suggestion['name'] = JetSearch.trimString( suggestion['name'], options.maxLength ); 1010 } 1011 1012 if ( options.value && ( "yes" === hightlightText || true === hightlightText ) ) {
1013 suggestion['name'] = highlightMatches( suggestion['name'] ); 1014 } 1015 1016 outputHtml += focusItemTemplate( suggestion ); 1017 } ); 1018 1019 $( settings.focusHolderClass, self ).html( outputHtml ); 1020 } 1021 } 1022 } 1023 1024 const errorCallback = function( jqXHR ) { 1025 if ( 'abort' !== jqXHR.statusText ) { 1026 JetSearch.suggestionsPreloader( showSpinner, 'hide', spinner ); 1027 } 1028 }; 1029 }; 1030 1031 /** 1032 * jetAjaxSearchSuggestions jQuery Plugin 1033 * 1034 * @param args 1035 */ 1036 $.fn.jetAjaxSearchSuggestions = function( args ) { 1037 let self = this[0], 1038 settings = args, 1039 options = $( self ).data( 'settings' ) || {}, 1040 timer = null, 1041 showformList = options['show_search_suggestions_list_inline'] || false, 1042 showfocusList = options['show_search_suggestions_list_on_focus'] || false, 1043 formListType = options['search_suggestions_list_inline'] || false, 1044 focusListType = options['search_suggestions_list_on_focus'] || false, 1045 searchSuggestionsLimit = options['search_suggestions_quantity_limit'] || 10, 1046 inlineLimit = options['search_suggestions_list_inline_quantity'] || 5, 1047 focusLimit = options['search_suggestions_list_on_focus_quantity'] || 5, 1048 showSpinner = options['show_search_suggestions_list_on_focus_preloader'] || '', 1049 hightlightText = options['highlight_searched_text'] || '', 1050 spinner = $( settings.spinnerClass, self ), 1051 formFocusClass = settings.searchFormClass.replace( '.', '' ) + '--focus', 1052 form = $( settings.searchFormClass, self ), 1053 focusTarget = $( settings.focusHolderClass, self ), 1054 disableInputs = false, 1055 customResultUrl = options['search_results_url'] || '', 1056 useSession = 'false', 1057 focusItem; 1058 1059 if ( window.elementorFrontend ) { 1060 var editMode = Boolean( window.elementorFrontend.isEditMode() ) 1061 } else { 1062 var editMode = false; 1063 } 1064 1065 if ( !self.isInit ) { 1066 self.isInit = true; 1067 1068 /** 1069 * Ajax settings from localized global variable 1070 */ 1071 self.ajaxSettings = window[ settings.handlerId ]['searchSuggestions'] || {}; 1072 1073 customResultUrl = $.trim( customResultUrl ); 1074 useSession = self.ajaxSettings.use_session; 1075 1076 self.selectSuggestion = function( event ) { 1077 const keyCode = event.keyCode || event.which; 1078 const $target = $( event.currentTarget ); 1079 1080 let value = $target.attr( 'aria-label' ); 1081 1082 if ( ! value ) { 1083 return; 1084 } 1085 1086 value = value.trim(); 1087 1088 if ( false === disableInputs && !editMode ) { 1089 1090 if ( 'keydown' === event.type ) { 1091 if ( 13 === keyCode ) { 1092 disableInputs = true; 1093 1094 $( settings.inputClass, self )[0].value = value; 1095 1096 JetSearch.setFormSuggestion( value, form, customResultUrl ); 1097 } 1098 } else if ( 'click' === event.type ) { 1099 disableInputs = true; 1100 1101 $( settings.inputClass, self )[0].value = value; 1102 JetSearch.setFormSuggestion( value, form, customResultUrl ); 1103 } 1104 } 1105 } 1106 1107 self.focusItemsNav = function() { 1108 focusItem = $( '.jet-search-suggestions__focus-area-item', self ); 1109 1110 if ( 0 < focusItem.length ) { 1111 focusItem.on( 'keydown', function( e ) { 1112 const keyCode = e.keyCode || e.which; 1113 1114 switch ( keyCode ) { 1115 case 40: // Down arrow 1116 e.preventDefault(); 1117 1118 var next = $( this ).next(); 1119 1120 if ( next.length > 0 ) { 1121 focusItem.removeClass( 'focused' ); 1122 next.addClass( 'focused' ); 1123 next.focus(); 1124 } 1125 break; 1126 1127 case 38: // Up arrow 1128 e.preventDefault(); 1129 1130 var prev = $( this ).prev(); 1131 1132 if ( prev.length > 0 ) { 1133 focusItem.removeClass( 'focused' ); 1134 prev.addClass( 'focused' ); 1135 prev.focus(); 1136 } else { 1137 focusItem.removeClass( 'focused' ); 1138 $( settings.inputClass, self ).focus(); 1139 } 1140 break; 1141 case 13: 1142 e.preventDefault(); 1143 let value = e.target.innerText.trim(); 1144 $( settings.inputClass, self )[0].value = value; 1145 1146 JetSearch.setFormSuggestion( value, form, customResultUrl ); 1147 break; 1148 } 1149 1150 if ( $( this ).is( ':focus-visible' ) ) { 1151 focusItem.removeClass( 'focused' ); 1152 } 1153 } ); 1154 } 1155 } 1156 1157 if ( formListType || focusListType ) { 1158
1159 if ( '' != formListType && ( "yes" === showformList || true === showformList ) ) { 1160 let listOptions = { 1161 list_position: 'inline', 1162 list_type: formListType, 1163 limit: inlineLimit, 1164 maxLength: options.search_suggestions_list_inline_item_title_length, 1165 }; 1166 1167 if ( 'manual' === formListType ) { 1168 listOptions.manual_list = options['search_suggestions_list_inline_manual']; 1169 } 1170 1171 $( settings.inlineClass, self ).getSuggestionsList( listOptions, settings, showSpinner, false, () => { 1172 let inlineItem = $( '.jet-search-suggestions__inline-area-item', self ); 1173 1174 if ( 0 < inlineItem.length ) { 1175 inlineItem.on( 'focus', function () { 1176 if ( $( this ).is( ':focus-visible' ) ) { 1177 self.hideList(); 1178 } 1179 } ); 1180 } 1181 1182 inlineItem.on( 'keydown', function( e ) { 1183 const keyCode = e.keyCode || e.which; 1184 1185 let value = $( this ).attr( 'aria-label' ); 1186 1187 if ( ! value ) { 1188 return; 1189 } 1190 1191 value = value.trim(); 1192 1193 if ( 13 === keyCode ) { 1194 $( settings.inputClass, self )[0].value = value; 1195 1196 JetSearch.setFormSuggestion( value, form, customResultUrl ); 1197 } 1198 } ); 1199 } ); 1200 } 1201 1202 if ( '' != focusListType && ( "yes" === showfocusList || true === showfocusList ) ) { 1203 let listOptions = { 1204 list_position: 'focus', 1205 list_type: focusListType, 1206 limit: focusLimit, 1207 maxLength: options.search_suggestions_list_on_focus_item_title_length || 0, 1208 }; 1209 1210 if ( 'manual' === focusListType ) { 1211 listOptions.manual_list = options['search_suggestions_list_on_focus_manual']; 1212 } 1213 1214 $( settings.focusClass, self ).getSuggestionsList( listOptions, settings, showSpinner, false, () => { 1215 self.focusItemsNav(); 1216 } ); 1217 } 1218 } 1219 1220 self.inputChangeHandler = function( event ) { 1221 1222 let value = $( event.target ).val(), 1223 listOptions = { 1224 list_position: 'focus', 1225 value: value, 1226 limit: searchSuggestionsLimit, 1227 maxLength: options.search_suggestions_list_on_focus_item_title_length || 0, 1228 }; 1229 1230 if ( '' != value ) { 1231 focusTarget.empty(); 1232 self.showList(); 1233 JetSearch.suggestionsPreloader( showSpinner, 'show', spinner ); 1234 1235 clearTimeout( timer ); 1236 timer = setTimeout( function() { 1237 $( settings.focusClass, self ).getSuggestionsList( listOptions, settings, showSpinner, hightlightText, () => { 1238 self.focusItemsNav(); 1239 } ); 1240 }, 450 ); 1241 } else { 1242 clearTimeout( timer ); 1243 focusTarget.empty(); 1244 JetSearch.suggestionsPreloader( showSpinner, 'hide', spinner ); 1245 1246 if ( false != focusListType && ( "yes" === showfocusList || true === showfocusList ) ) { 1247 JetSearch.suggestionsPreloader( showSpinner, 'show', spinner ); 1248 1249 listOptions.limit = focusLimit; 1250 1251 if ( 'manual' === focusListType ) { 1252 listOptions.list_type = focusListType; 1253 listOptions.manual_list = options['search_suggestions_list_on_focus_manual']; 1254 } 1255 1256 $( settings.focusClass, self ).getSuggestionsList( listOptions, settings, showSpinner, false, () => { 1257 self.focusItemsNav(); 1258 } ); 1259 } 1260 } 1261 }; 1262 1263 self.hideList = function(event) { 1264 $( settings.focusClass, self ).removeClass( 'show' ); 1265 $( '.chosen-single', self ).removeClass( 'focused' ); 1266 1267 if ( focusItem && 0 < focusItem.length ) { 1268 focusItem.removeClass( 'focused' ); 1269 } 1270 }; 1271 1272 self.showList = function() { 1273 $( settings.focusClass, self ).addClass( 'show' ); 1274 }; 1275 1276 self.focusHandler = function( event ) { 1277 $( settings.searchFormClass, self ).addClass( formFocusClass ); 1278 self.showList(); 1279 }; 1280 1281 self.chosenFocusHandler = function() { 1282 JetSearch.markPopupDropdownInteraction( $( self ) ); 1283 self.hideList(); 1284 }; 1285 1286 self.formClick = function( event ) { 1287 if ( $( event.target ).closest( '.jet-ajax-search__popup-trigger, .jet-ajax-search__popup-close' ).length ) { 1288 return; 1289 } 1290 1291 if ( $( event.target ).closest( '.chosen-container, .chosen-drop' ).length ) { 1292 return; 1293 } 1294 1295 if ( $( event.target ).closest( '.jet-ajax-search__popup' ).length && ! $( event.target ).closest( '.jet-ajax-search__popup-content' ).length ) { 1296 return; 1297 } 1298 1299 event.stopPropagation(); 1300 }; 1301 1302 self.changeHandler = function( event ) { 1303 let target = $( event.target ), 1304 settingsInput = $( settings.settingsInput, self ), 1305 querySettings = JSON.parse( settingsInput.val() ), 1306 globalQuerySettings = $( self ).data( 'settings' ); 1307 1308 querySettings.category__in = target.val(); 1309 globalQuerySettings.category__in = target.val(); 1310 1311 settingsInput.val( JSON.stringify( querySettings ) ); 1312 $( self ).data( 'settings', globalQuerySettings ); 1313 1314 self.inputChangeHandler( { target: $( settings.inputClass, self ) } ) 1315 }; 1316 1317 self.formSubmit = function( event ) { 1318 let keyCode = event.keyCode || event.which; 1319 1320 if ( false === disableInputs ) { 1321 let value = event.target.value; 1322 1323 if ( 13 === keyCode && value.length != 0 ) { 1324 disableInputs = true; 1325 event.preventDefault(); 1326 1327 JetSearch.setFormSuggestion( value, form, customResultUrl ); 1328 } 1329 } 1330 1331 if ( 40 === keyCode ) {
1332 if ( focusItem && 0 < focusItem.length ) { 1333 event.preventDefault(); 1334 focusItem.removeClass( 'focused' ); 1335 focusItem.first().addClass( 'focused' ); 1336 focusItem.first().focus(); 1337 } 1338 } 1339 } 1340 1341 self.blurHandler = function( event ) { 1342 $( settings.searchFormClass, self ).removeClass( formFocusClass ); 1343 }; 1344 1345 self.clickFullResults = function( event ) { 1346 if ( false === disableInputs ) { 1347 disableInputs = true; 1348 1349 var searchInput = $( settings.inputClass, self ), 1350 value = searchInput.val(); 1351 1352 event.preventDefault(); 1353 1354 JetSearch.setFormSuggestion( value, form, customResultUrl ); 1355 } 1356 }; 1357 1358 $( settings.inputClass, self ) 1359 .on( 'input' + settings.searchClass, self.inputChangeHandler ) 1360 .on( 'focus' + settings.searchClass, self.focusHandler ) 1361 .on( 'blur' + settings.searchClass, self.blurHandler ) 1362 .on( 'keydown' + settings.searchClass, self.formSubmit ); 1363 1364 $( settings.submitClass, self ).on( 'click' + settings.searchClass, self.clickFullResults ); 1365 1366 $( self ) 1367 .on( 'click' + settings.searchClass, settings.focusItemClass, self.selectSuggestion ) 1368 .on( 'click keydown' + settings.searchClass, settings.inlineItemClass, self.selectSuggestion ) 1369 .on( 'mousedown' + settings.searchClass, self.formClick ) 1370 .on( 'click' + settings.searchClass, self.formClick ) 1371 .on( 'touchstart' + settings.searchClass, self.formClick ) 1372 .on( 'mousedown' + settings.searchClass + ' touchstart' + settings.searchClass, '.chosen-container, .chosen-drop', function() { 1373 JetSearch.markPopupDropdownInteraction( $( self ), 500 ); 1374 } ) 1375 .on( 'change', settings.chosenClass, self.changeHandler ) 1376 .on( 'touchend' + settings.searchClass, self.formClick ) 1377 .on( 'chosen:showing_dropdown', settings.chosenClass, self.chosenFocusHandler ); 1378 1379 $( self ).on( 'keydown', function( e ) { 1380 const keyCode = e.keyCode || e.which; 1381 1382 if ( 9 === keyCode ) { 1383 setTimeout( () => { 1384 const focusedElement = document.activeElement; 1385 1386 if ( $( focusedElement ).is( '.chosen-search-input' ) ) { 1387 $( '.chosen-single', self ).addClass( 'focused' ); 1388 } else { 1389 $( '.chosen-single', self ).removeClass( 'focused' ); 1390 } 1391 1392 if ( $( focusedElement ).is( '.jet-search-suggestions__inline-area-item' ) ) { 1393 self.hideList(); 1394 } 1395 }, 50 ); 1396 } 1397 } ); 1398 1399 $( settings.inputClass, self ).on( 'click' + settings.searchClass, () => { 1400 $( '.chosen-single', self ).removeClass( 'focused' ); 1401 } ); 1402 1403 $( 'body' ) 1404 .on( 'click' + settings.searchClass, self.hideList ) 1405 .on( 'touchend' + settings.searchClass, self.hideList ); 1406 1407 // If after reloading the page the value of the select is not '0'. 1408 if ( '0' !== $( settings.chosenClass, self ).val() ) { 1409 $( settings.chosenClass, self ).trigger( 'change' ); 1410 } 1411 } 1412 }; 1413 1414 /** 1415 * JetAjaxSearch jQuery Plugin 1416 * 1417 * @param args 1418 */ 1419 $.fn.jetAjaxSearch = function( args ) { 1420 1421 var self = this[0], 1422 settings = args, 1423 timer = null, 1424 itemTemplate = null, 1425 resultsArea = $( settings.resultsAreaClass, self ), 1426 resultsHolder = $( settings.listHolderClass, resultsArea ), 1427 resultsHeader = $( settings.resultsHeaderClass, resultsArea ), 1428 resultsFooter = $( settings.resultsFooterClass, resultsArea ), 1429 countHolder = $( settings.countClass, resultsArea ), 1430 fullResults = $( settings.fullResultsClass, resultsArea ), 1431 resultsList = $( settings.listClass, resultsArea ), 1432 resultsListInner = $( settings.listInnerClass, resultsArea ), 1433 resultsHeaderNav = $( settings.navigationClass, resultsHeader ), 1434 resultsFooterNav = $( settings.navigationClass, resultsFooter ), 1435 messageHolder = $( settings.messageHolderClass, resultsArea ), 1436 spinner = $( settings.spinnerClass, resultsArea ), 1437 form = $( settings.searchFormClass, self ), 1438 resultsSuggestions = $( settings.resultsSuggestionsAreaClass, self ), 1439 inlineSuggestions = $( settings.inlineSuggestionsAreaClass, self ), 1440 data = $( self ).data( 'settings' ) || [], 1441 customResultUrl = data['search_results_url'] || '', 1442 hightlightText = data['highlight_searched_text'] || '', 1443 formFocusClass = settings.searchFormClass.replace( '.', '' ) + '--focus', 1444 searchLogging = data['search_logging'] || '', 1445 currentPosition = 1, 1446 lang = '', 1447 disableInputs = false, 1448 allowEmptyString = false, 1449 allowSubmitOnEnter = 1,
1450 urlParams = JetSearch.getUrlParams(), 1451 listingID = data['listing_id'] || '', 1452 categoryIndex = urlParams.jet_ajax_search_categories || '', 1453 getResultsOnFocus = true, 1454 maxUserSearches = 20, 1455 showSearchSuggestions = data['show_search_suggestions'] || false, 1456 showAddToCartQuantity = data['show_add_to_cart_quantity'] || false, 1457 suggestionsTitle = '', 1458 suggestionsType = data['search_suggestions_source'] || false, 1459 suggestionsPosition = data['search_suggestions_position'] || false, 1460 searchSuggestionsLimits = data['search_suggestions_limits'] || 20, 1461 storedUserSearches = JSON.parse( localStorage.getItem('jetUserSearches') ) || [], 1462 suggestionsList = []; 1463 1464 if ( 'yes' === data.search_by_empty_value || true === data.search_by_empty_value ) { 1465 allowEmptyString = true; 1466 } 1467 1468 if ( !self.isInit ) { 1469 self.isInit = true; 1470 1471 /** 1472 * Ajax request instance 1473 */ 1474 self.ajaxRequest = null; 1475 1476 self.suggestionsListLoaded = false; 1477 1478 if ( data.hasOwnProperty('lang') ) { 1479 lang = data.lang; 1480 delete data.lang; 1481 } 1482 1483 /** 1484 * Ajax settings from localized global variable 1485 */ 1486 self.ajaxSettings = window[ settings.handlerId ] || {}; 1487 self.suggestionsSettings = window['jetSearchSettings']['searchSuggestions'] || {}; 1488 1489 if ( self.ajaxSettings['ajaxSearchSuggestionsLimits'] ) { 1490 maxUserSearches = self.ajaxSettings['ajaxSearchSuggestionsLimits']; 1491 } 1492 1493 if ( 'yes' === data.submit_on_enter || true === data.submit_on_enter ) { 1494 allowSubmitOnEnter = false; 1495 } else { 1496 allowSubmitOnEnter = true; 1497 } 1498 1499 if ( '' === self.ajaxSettings.sumbitOnEnter ) { 1500 allowSubmitOnEnter = false; 1501 } 1502 1503 if ( window.elementorFrontend ) { 1504 var editMode = Boolean( window.elementorFrontend.isEditMode() ) 1505 } else { 1506 var editMode = false; 1507 } 1508 1509 self.suggestionsListHTML = function( suggestionsList ) { 1510 1511 let resultsSuggestionsTemplate = wp.template('jet-ajax-search-results-suggestion-item'), 1512 inlineSuggestionsTemplate = wp.template('jet-ajax-search-inline-suggestion-item'), 1513 inlineOutputHtml = '', 1514 resultsOutputHtml = ''; 1515 1516 1517 suggestionsList.forEach( item => { 1518 let inlineListItemHtml = '', 1519 resultsListItemHtml = '', 1520 maxLength = data.search_suggestions_item_title_length || 0, 1521 suggestionItem = {}; 1522 1523 suggestionItem['fullName'] = JetSearch.escapeHTML( item ); 1524 suggestionItem['name'] = JetSearch.escapeHTML( item ); 1525 1526 if ( 0 < maxLength ) { 1527 suggestionItem['name'] = JetSearch.trimString( suggestionItem['name'], maxLength ); 1528 } 1529 1530 if ( 'under_form' === suggestionsPosition ) { 1531 inlineListItemHtml = inlineSuggestionsTemplate( suggestionItem ); 1532 } else if ( 'inside_results_area' === suggestionsPosition ) { 1533 resultsListItemHtml = resultsSuggestionsTemplate( suggestionItem ); 1534 } 1535 1536 inlineOutputHtml += inlineListItemHtml; 1537 resultsOutputHtml += resultsListItemHtml; 1538 } ); 1539 1540 if ( 'under_form' === suggestionsPosition ) { 1541 suggestionsTitle = inlineSuggestions.html(); 1542 1543 inlineSuggestions.html( inlineOutputHtml ).prepend( suggestionsTitle ); 1544 } else if ( 'inside_results_area' === suggestionsPosition ) { 1545 suggestionsTitle = resultsSuggestions.html(); 1546 1547 resultsSuggestions.html( resultsOutputHtml ).prepend( suggestionsTitle ); 1548 } 1549 }; 1550 1551 self.showSuggestions = function() { 1552 1553 if ( suggestionsType ) { 1554 if ( 'popular' === suggestionsType ) { 1555 1556 if ( false === window.bricksIsFrontend ) { 1557 1558 let sendData = { 1559 list_type: 'popular', 1560 value: '', 1561 limit: searchSuggestionsLimits 1562 }, 1563 ajaxData = { 1564 action: self.ajaxSettings['searchSuggestions'].get_action, 1565 data: sendData || {}, 1566 }; 1567 1568 $.ajax( { 1569 type: 'GET', 1570 url: self.ajaxSettings['searchSuggestions'].get_suggestions_rest_api_url, 1571 data: ajaxData, 1572 dataType: 'json', 1573 cache: false, 1574 processData: true, 1575 error: function( jqXHR, textStatus, errorThrown ) { 1576 errorCallback( jqXHR ); 1577 }, 1578 success: function( response, textStatus, jqXHR ) { 1579 if ( response.length ) { 1580 suggestionsList = $.map( response, function( obj ) { 1581 return obj.name; 1582 } ); 1583 1584 self.suggestionsListLoaded = true; 1585 1586 if ( suggestionsList.length ) { 1587 suggestionsList = suggestionsList.slice( 0, searchSuggestionsLimits ); 1588 1589 self.suggestionsListHTML( suggestionsList ); 1590 } else { 1591 resultsSuggestions.hide(); 1592 inlineSuggestions.hide(); 1593 } 1594 } 1595 } 1596 } ); 1597 } else { 1598 suggestionsList = self.ajaxSettings['ajaxSearchPopularSuggestions'] || []; 1599 1600 if ( suggestionsList.length ) { 1601 suggestionsList = suggestionsList.slice( 0, searchSuggestionsLimits ); 1602 1603 self.suggestionsListHTML( suggestionsList ); 1604 } else { 1605 resultsSuggestions.hide(); 1606 inlineSuggestions.hide(); 1607 } 1608 } 1609 } else if ( 'user' === suggestionsType ) { 1610 let userSearches = localStorage.getItem('jetUserSearches'); 1611 1612 if ( userSearches ) { 1613 suggestionsList = JSON.parse( userSearches ) || []; 1614 1615 suggestionsList.reverse(); 1616 1617 suggestionsList = suggestionsList.slice( 0, searchSuggestionsLimits ); 1618 1619 self.suggestionsListHTML( suggestionsList ); 1620 } else { 1621 resultsSuggestions.hide(); 1622 inlineSuggestions.hide(); 1623 } 1624 } 1625 } 1626 }; 1627 1628 if ( 'yes' === showSearchSuggestions || true === showSearchSuggestions ) { 1629 self.showSuggestions(); 1630 } 1631 1632 self.inputChangeHandler = function( event ) { 1633 var value = $( event.target ).val(), 1634 symbolNumberForStart = 'number' === $.type( data.symbols_for_start_searching ) ? data.symbols_for_start_searching : 2; 1635 1636 value = value.replace(/\u3000/g, ' '); 1637 1638 if ( 'number' === $.type( symbolNumberForStart ) && symbolNumberForStart > value.length ) { 1639 if ( 'inside_results_area' === suggestionsPosition && suggestionsList.length ) { 1640 resultsHeader.hide(); 1641 resultsFooter.hide(); 1642 resultsList.hide(); 1643 resultsSuggestions.show(); 1644 resultsSuggestions.addClass( 'active' ); 1645 resultsHolder.addClass( 'show' ); 1646 self.showList(); 1647 } else { 1648 self.hideList(); 1649 } 1650 1651 return false;
1652 } 1653 1654 if ( 'inside_results_area' === suggestionsPosition && suggestionsList.length ) { 1655 resultsSuggestions.removeClass( 'active' ); 1656 resultsHeader.show(); 1657 resultsFooter.show(); 1658 resultsList.show(); 1659 } 1660 1661 resultsHolder.removeClass( 'show' ); 1662 self.outputMessage( '', '' ); 1663 resultsListInner.css( 'transform', 'translateX(0)' ); 1664 resultsList.css( 'height', 'auto' ); 1665 1666 if ( value ) { 1667 self.showList(); 1668 spinner.addClass( 'show' ); 1669 1670 clearTimeout( timer ); 1671 timer = setTimeout( function() { 1672 data.value = value; 1673 data.deviceMode = window.elementorFrontend && window.elementorFrontend.getCurrentDeviceMode() ? window.elementorFrontend.getCurrentDeviceMode() : JetSearch.getCurrentDeviceMode(); 1674 self.ajaxSendData( data, lang ); 1675 }, 450 ); 1676 } else { 1677 self.hideList(); 1678 } 1679 }; 1680 1681 self.successCallback = function( response ) { 1682 1683 if ( response.error ) { 1684 spinner.removeClass( 'show' ); 1685 self.outputMessage( data.server_error, 'error show' ); 1686 return; 1687 } 1688 1689 JetSearch.enqueueAssetsFromResponse( response ); 1690 1691 var responseData = response.data, 1692 error = responseData.error, 1693 message = responseData.message, 1694 posts = responseData.posts, 1695 listingItems = responseData.listing_items, 1696 post = null, 1697 outputHtml = '', 1698 listItemHtml = '', 1699 listHtml = '<div class="' + settings.listSlideClass.replace( '.', '' ) + '">%s</div>', 1700 searchSources = responseData.sources, 1701 searchSourcesBeforePosts = null, 1702 searchSourcesAfterPosts = null, 1703 countAllResults = null, 1704 searchSourcesHolder = $( '.jet-ajax-search__source-results-holder', self ); 1705 1706 resultsHolder.removeClass( 'show' ); 1707 spinner.removeClass( 'show' ); 1708 currentPosition = 1; 1709 1710 searchSourcesHolder.remove(); 1711 1712 resultsListInner.html( '' ); 1713 resultsHeaderNav.html( '' ); 1714 resultsFooterNav.html( '' ); 1715 1716 searchSourcesBeforePosts = searchSources 1717 .filter( item => item.priority < 0 && '' != item.content ) 1718 .sort( ( a, b ) => a.priority - b.priority ); 1719 1720 searchSourcesAfterPosts = searchSources 1721 .filter( item => item.priority > 0 && '' != item.content ) 1722 .sort( ( a, b ) => a.priority - b.priority ); 1723 1724 if ( '' != listingID && 0 !== responseData.post_count && !error ) { 1725 var outputHtml = '', 1726 listItemHtml = '', 1727 listHtml = '<div class="jet-listing-grid__items jet-listing-base ' + settings.listSlideClass.replace( '.', '' ) + '">%s</div>'; 1728 1729 if ( listingItems.length ) { 1730 $.each( listingItems, ( i, item ) => { 1731 listItemHtml += item; 1732 1733 if ( ( parseInt( i ) + 1 ) % responseData.limit_query == 0 || parseInt( i ) === listingItems.length - 1 ) { 1734 outputHtml += listHtml.replace( '%s', listItemHtml ); 1735 listItemHtml = ''; 1736 } 1737 } ); 1738 } 1739 1740 messageHolder.removeClass( 'show' ); 1741 1742 countAllResults = responseData.post_count; 1743 1744 if ( responseData.sources_results_count && 0 < responseData.sources_results_count ) { 1745 countAllResults += responseData.sources_results_count; 1746 } 1747 1748 $( 'span', countHolder ).html( countAllResults ); 1749 resultsListInner 1750 .html( outputHtml ) 1751 .data( 'columns', responseData.columns ); 1752 1753 Promise.all( JetSearch.assetsPromises ).then( function() { 1754 JetSearch.initElementsHandlers( resultsListInner ); 1755 JetSearch.reinitBricksScripts( self ); 1756 JetSearch.assetsPromises = []; 1757 } ); 1758 1759 resultsHeaderNav.html( responseData.results_navigation.in_header ); 1760 resultsFooterNav.html( responseData.results_navigation.in_footer ); 1761 1762 if ( !countHolder[0] && !responseData.results_navigation.in_header ) { 1763 resultsHeader.addClass( 'is-empty' ); 1764 } else { 1765 resultsHeader.removeClass( 'is-empty' ); 1766 } 1767 1768 if ( !fullResults[0] && !responseData.results_navigation.in_footer ) { 1769 resultsFooter.addClass( 'is-empty' ); 1770 } else { 1771 resultsFooter.removeClass( 'is-empty' ); 1772 } 1773 1774 resultsList.css( 'height', 'auto' ); 1775 1776 $( document ).trigger( 'jet-ajax-search/show-results/listing', [ resultsListInner ] ); 1777 1778 resultsHolder.addClass( 'show' ); 1779 self.syncResultsListHeightOnImagesLoaded(); 1780 1781 if ( 'yes' === searchLogging || true === searchLogging ) { 1782 let itemWrapper = settings.itemClass, 1783 itemLink = $( '.jet-engine-listing-overlay-wrap', itemWrapper ), 1784 itemTitle = '.jet-ajax-search-item-title .jet-listing-dynamic-field__content', 1785 itemUrlAttr = 'data-url'; 1786 1787 $( document ).trigger( 'jet-ajax-search/results-area/listing-ad
1787d-suggestion', [ self, itemWrapper, itemLink, itemTitle, itemUrlAttr ] ); 1788 1789 JetSearch.addSuggestionFromResultAreaItem( itemWrapper, itemLink, itemTitle, itemUrlAttr ); 1790 } 1791 } 1792 1793 const allowedHighlightFields = [ 'title', 'after_content', 'after_title', 'before_content', 'before_title', 'content', 'price' ]; 1794 1795 function highlightMatches( item ) { 1796 let searched = responseData.search_value.trim(); 1797 1798 if ( searched !== "" ) { 1799 let reg = new RegExp("[\>][^\<]*"+searched+"[^\<]*[\<]","gi"), 1800 reg2 = new RegExp( searched, "gi" ), 1801 regHtml = new RegExp("<\/?[a-z](.*?)[\s\S]*>", "gi"); 1802 1803 if ( reg.test( item ) ) { 1804 item = item.replace( reg, function( item ) { 1805 let subRegex = new RegExp( searched, "gi" ); 1806 return item.replace( subRegex,`<mark>${searched}</mark>` ); 1807 } ); 1808 } 1809 1810 if ( regHtml.test( item ) ) { 1811 return item; 1812 } else { 1813 item = item.replace( reg2, str => `<mark>${str}</mark>` ); 1814 } 1815 } 1816 1817 return item; 1818 } 1819 1820 function highlightFields( fields, allowHighlightFields ) { 1821 1822 $.each( fields, function( key, value ) { 1823 if ( -1 != $.inArray( key, allowHighlightFields ) && ( null != value && '' != value ) ) { 1824 fields[key] = highlightMatches( value ); 1825 } 1826 } ); 1827 1828 return fields; 1829 } 1830 1831 if ( 0 !== responseData.post_count && !error && '' === listingID) { 1832 1833 messageHolder.removeClass( 'show' ); 1834 itemTemplate = wp.template( 'jet-ajax-search-results-item' ); 1835 1836 for ( post in posts ) { 1837 if ( responseData.search_highlight && true === responseData.search_highlight ) { 1838 if ( '' != hightlightText && ( "yes" === hightlightText || true === hightlightText ) ) { 1839 highlightFields( posts[post], allowedHighlightFields ); 1840 } 1841 } 1842 1843 if ( posts[post].is_product ) { 1844 let productSupportsAjax = !! posts[post].product_supports_ajax_add_to_cart, 1845 productSoldIndividually = !! posts[post].product_sold_individually, 1846 showQuantity = ( 'yes' === showAddToCartQuantity || true === showAddToCartQuantity ) && productSupportsAjax && ! productSoldIndividually, 1847 productQtyMin = posts[post].product_qty_min || 1, 1848 productQtyMax = posts[post].product_qty_max || '', 1849 productQtyStep = posts[post].product_qty_step || 1, 1850 productQtyValue = posts[post].product_qty_value || productQtyMin, 1851 quantityInput = '', 1852 productTypeClass = productSupportsAjax ? 'add-to-cart-button add_to_cart_button ajax_add_to_cart' : 'select-options-button'; 1853 1854 if ( showQuantity ) { 1855 const maxAttr = productQtyMax ? ' max="' + productQtyMax + '"' : ''; 1856 quantityInput = '<input type="number" class="jet-ajax-search__results-item-quantity-input qty" min="' + productQtyMin + '"' + maxAttr + ' step="' + productQtyStep + '" value="' + productQtyValue + '" inputmode="numeric" aria-label="Quantity">'; 1857 } 1858 1859 posts[post].add_to_cart = '<div class="jet-ajax-search__item-add-to-cart">' + quantityInput + '<button type="button" data-quantity="' + productQtyValue + '" class="jet-ajax-search__results-item-cart-button ' + productTypeClass + '" data-product_id="' + posts[post].product_id + '" data-product_sku="' + posts[post].product_sku + '" aria-label="' + posts[post].product_label + '" data-product_url="' + posts[post].product_url + '" rel="nofollow" target="_blank">' + posts[post].product_add_text + '</button></div>'; 1860 } 1861 1862 let templateResult = itemTemplate( posts[post] ); 1863 1864 listItemHtml += templateResult; 1865 1866 if ( (parseInt( post ) + 1) % responseData.limit_query == 0 || parseInt( post ) === posts.length - 1 ) { 1867 outputHtml += listHtml.replace( '%s', listItemHtml ); 1868 listItemHtml = ''; 1869 } 1870 } 1871 1872 countAllResults = responseData.post_count; 1873 1874 if ( responseData.sources_results_count && 0 < responseData.sources_results_count ) { 1875 countAllResults += responseData.sources_results_count; 1876 } 1877 1878 $( 'span', countHolder ).html( countAllResults ); 1879 resultsListInner 1880 .html( outputHtml ) 1881 .data( 'columns', responseData.columns ); 1882 1883 $( '.jet-ajax-search__results-item-cart-button.select-options-button', self ).on( 'click', function( e ) { 1884 e.preventDefault(); 1885 1886 const productUrl = $( this ).data( 'product_url' ); 1887 1888 window.open( productUrl, '_blank' ); 1889 } ); 1890 1891 resultsHeaderNav.html( responseData.results_navigation.in_header ); 1892 resultsFooterNav.html( responseData.results_navigation.in_footer ); 1893 1894 if ( !countHolder[0] && !responseData.results_navigation.in_header ) { 1895 resultsHeader.addClass( 'is-empty' ); 1896 } else { 1897 resultsHeader.removeClass( 'is-empty' ); 1898 } 1899 1900 if ( !fullResults[0] && !responseData.results_navigation.in_footer ) { 1901 resultsFooter.addClass( 'is-empty' ); 1902 } else { 1903 resultsFooter.removeClass( 'is-empty' ); 1904 } 1905 1906 resultsHolder.addClass( 'show' ); 1907 self.syncResultsListHeightOnImagesLoaded(); 1908 1909 $( document ).trigger( 'jet-ajax-search/show-results', [ resultsHolder ] ); 1910 1911 var inputField = $( '.jet-ajax-search__field', self ), 1912 resultsItem = $( '.jet-ajax-search__item-link', self ), 1913 focusedItem = resultsItem.filter( ':focus' ); 1914 1915 inputField.on( 'keydown', function( e ) {
1916 const keyCode = e.keyCode || e.which; 1917 1918 if ( 40 === keyCode ) { // Down arrow 1919 e.preventDefault(); 1920 1921 var position = currentPosition - 1, 1922 activeSlide = $( settings.listSlideClass, resultsListInner ).eq( position ), 1923 next = activeSlide.find( '.jet-ajax-search__item-link' ).first(); 1924 1925 if ( focusedItem.length === 0 ) { 1926 setTimeout( () => { 1927 resultsItem.removeClass( 'focused' ); 1928 next.addClass( 'focused' ); 1929 next.focus(); 1930 }, 0 ); 1931 } 1932 } 1933 } ); 1934 1935 resultsItem.on( 'keydown', function( e ) { 1936 const keyCode = e.keyCode || e.which; 1937 1938 switch ( keyCode ) { 1939 case 40: // Down arrow 1940 e.preventDefault(); 1941 1942 var next = $( this ).parent().next().find( '.jet-ajax-search__item-link' ).first(); 1943 1944 if ( 0 < next.length ) { 1945 resultsItem.removeClass( 'focused' ); 1946 next.addClass( 'focused' ); 1947 next.focus(); 1948 } 1949 break; 1950 1951 case 38: // Up arrow 1952 e.preventDefault(); 1953 1954 var prev = $( this ).parent().prev().find( '.jet-ajax-search__item-link' ).first(); 1955 1956 if ( 0 < prev.length ) { 1957 resultsItem.removeClass( 'focused' ); 1958 prev.addClass( 'focused' ); 1959 prev.focus(); 1960 } else { 1961 resultsItem.removeClass( 'focused' ); 1962 inputField.focus(); 1963 } 1964 break; 1965 1966 case 37: // Left arrow 1967 var prevSlide = $( this ).closest( '.jet-ajax-search__results-slide' ).prev(); 1968 1969 if ( 0 < prevSlide.length ) { 1970 1971 $( settings.prevClass + ':not( ' + settings.disableNavClass + ' )' ).click(); 1972 1973 resultsItem.removeClass( 'focused' ); 1974 1975 setTimeout( () => { 1976 $( settings.listSlideClass, resultsListInner ).eq( currentPosition - 1 ).find( '.jet-ajax-search__item-link' ).first().focus().addClass( 'focused' ); 1977 }, 350 ); 1978 } 1979 break; 1980 1981 case 39: // Right arrow 1982 var nextSlide = $( this ).closest( '.jet-ajax-search__results-slide' ).next(); 1983 1984 if ( 0 < nextSlide.length ) { 1985 1986 $( settings.nextClass + ':not( ' + settings.disableNavClass + ' )' ).click(); 1987 1988 resultsItem.removeClass( 'focused' ); 1989 1990 setTimeout( () => { 1991 $( settings.listSlideClass, resultsListInner ).eq( currentPosition - 1 ).find( '.jet-ajax-search__item-link' ).first().focus().addClass( 'focused' ); 1992 }, 350 ); 1993 } 1994 break; 1995 case 9: 1996 resultsItem.removeClass( 'focused' ); 1997 break; 1998 } 1999 } ); 2000 2001 if ( 'yes' === searchLogging || true === searchLogging ) { 2002 let itemWrapper = settings.itemClass, 2003 resultAreaItemLink = $( '.jet-ajax-search__item-link', itemWrapper ), 2004 resultAreaItemTitle = '.jet-ajax-search__item-title', 2005 resultAreaItemUrlAttr = 'href'; 2006 2007 JetSearch.addSuggestionFromResultAreaItem( itemWrapper, resultAreaItemLink, resultAreaItemTitle, resultAreaItemUrlAttr ); 2008 } 2009 2010 searchSourcesBeforePosts.forEach( function( item ) { 2011 self.maybeHasListing( item ); 2012 2013 resultsListInner.before( item.content ); 2014 resultsHolder.addClass( 'show' ); 2015 } ); 2016 2017 searchSourcesAfterPosts.forEach( function( item ) { 2018 self.maybeHasListing( item ); 2019 2020 resultsListInner.after( item.content ); 2021 resultsHolder.addClass( 'show' ); 2022 } ); 2023 } else { 2024 2025 if ( searchSourcesBeforePosts.length || searchSourcesAfterPosts.length ) { 2026 searchSourcesBeforePosts.forEach( function( item ) { 2027 self.maybeHasListing( item ); 2028 2029 resultsListInner.before( item.content ); 2030 resultsHolder.addClass( 'show' ); 2031 } ); 2032 2033 searchSourcesAfterPosts.forEach( function( item ) { 2034 self.maybeHasListing( item ); 2035 2036 resultsListInner.after( item.content ); 2037 resultsHolder.addClass( 'show' ); 2038 } ); 2039 2040 countAllResults = responseData.post_count; 2041 2042 if ( responseData.sources_results_count && 0 < responseData.sources_results_count ) { 2043 countAllResults += responseData.sources_results_count; 2044 } 2045 2046 $( 'span', countHolder ).html( countAllResults ); 2047 2048 } else { 2049 self.outputMessage( message, 'show' ); 2050 } 2051 } 2052 }; 2053 2054 self.maybeHasListing = function( item ) { 2055 if ( typeof item.listing_template !== 'undefined' && true === item.listing_template ) { 2056 Promise.all( JetSearch.assetsPromises ).then( function() { 2057 JetSearch.initElementsHandlers( resultsListInner ); 2058 JetSearch.reinitBricksScripts( self ); 2059 JetSearch.assetsPromises = []; 2060 } ); 2061 } 2062 } 2063 2064 self.errorCallback = function( jqXHR ) { 2065 if ( 'abort' !== jqXHR.statusText ) { 2066 spinner.removeClass( 'show' ); 2067 self.outputMessage( data.server_error, 'error show' ); 2068 } 2069 }; 2070 2071 self.ajaxSendData = function( sendData, lang = '' ) { 2072 let filteredData = {}; 2073 2074 Object.keys( sendData ).forEach( key => { 2075 if ( 2076 sendData[key] !== '' && 2077 sendData[key] !== null && 2078 sendData[key] !== undefined && 2079 !( Array.isArray( sendData[key] ) && sendData[key].length === 0 ) 2080 ) { 2081 filteredData[key] = sendData[key]; 2082 } 2083 } ); 2084 2085 var ajaxData = { 2086 action: self.ajaxSettings.action, 2087 nonce: self.ajaxSettings.nonce, 2088 data: filteredData || {} 2089 }; 2090
2091 if ( '' != lang ) { 2092 ajaxData.lang = lang; 2093 } 2094 2095 const isRestAPI = self.ajaxSettings.rest_api_url && self.ajaxSettings.rest_api_url.includes( '/wp-json/' ); 2096 2097 self.ajaxRequest = jQuery.ajax( { 2098 type: 'GET', 2099 url: self.ajaxSettings.rest_api_url, 2100 data: ajaxData, 2101 dataType: 'json', 2102 cache: false, 2103 processData: true, 2104 beforeSend: function( jqXHR, ajaxSettings ) { 2105 2106 if ( null !== self.ajaxRequest ) { 2107 self.ajaxRequest.abort(); 2108 } 2109 2110 if ( isRestAPI ) { 2111 jqXHR.setRequestHeader( 'X-WP-Nonce', self.ajaxSettings.nonce ); 2112 } 2113 2114 }, 2115 error: function( jqXHR, textStatus, errorThrown ) { 2116 self.errorCallback( jqXHR ); 2117 }, 2118 success: function( response, textStatus, jqXHR ) { 2119 self.successCallback( response ); 2120 } 2121 } ); 2122 }; 2123 2124 self.hideList = function() { 2125 resultsArea.removeClass( 'show' ); 2126 $( '.chosen-single', self ).removeClass( 'focused' ); 2127 }; 2128 2129 self.showList = function() { 2130 resultsArea.addClass( 'show' ); 2131 }; 2132 2133 self.focusHandler = function( event ) { 2134 var value = event.target.value, 2135 symbolNumberForStart = 'number' === $.type( data.symbols_for_start_searching ) ? data.symbols_for_start_searching : 2; 2136 2137 $( settings.searchFormClass, self ).addClass( formFocusClass ); 2138 2139 if ( 'inside_results_area' === suggestionsPosition && suggestionsList.length ) { 2140 if ( value && getResultsOnFocus ) { 2141 spinner.addClass( 'show' ); 2142 2143 data.value = value; 2144 data.deviceMode = window.elementorFrontend && window.elementorFrontend.getCurrentDeviceMode() ? window.elementorFrontend.getCurrentDeviceMode() : JetSearch.getCurrentDeviceMode(); 2145 2146 self.ajaxSendData( data, lang ); 2147 2148 getResultsOnFocus = false; 2149 } 2150 2151 if ( '' === value ) { 2152 resultsHeader.hide(); 2153 resultsFooter.hide(); 2154 resultsList.hide(); 2155 resultsSuggestions.addClass( 'active' ); 2156 resultsHolder.addClass( 'show' ); 2157 self.showList(); 2158 } 2159 } 2160 2161 if ( 'number' === $.type( symbolNumberForStart ) && symbolNumberForStart > value.length ) { 2162 return; 2163 } 2164 2165 self.showList(); 2166 }; 2167 2168 self.blurHandler = function( event ) { 2169 $( settings.searchFormClass, self ).removeClass( formFocusClass ); 2170 }; 2171 2172 self.outputMessage = function( message, messageClass ) { 2173 message = message.replace( /\\/g, '' ); // remove slashes 2174 //message = $( "<div/>" ).html( message ).text(); 2175 message = message.replace( /\\*"/g, '' ); 2176 messageHolder.removeClass( 'error show' ).addClass( messageClass ).html( message ); 2177 }; 2178 2179 self.formClick = function( event ) { 2180 if ( $( event.target ).closest( '.jet-ajax-search__popup-trigger, .jet-ajax-search__popup-close' ).length ) { 2181 return; 2182 } 2183 2184 if ( $( event.target ).closest( '.chosen-container, .chosen-drop' ).length ) { 2185 return; 2186 } 2187 2188 if ( $( event.target ).closest( '.jet-ajax-search__popup' ).length && ! $( event.target ).closest( '.jet-ajax-search__popup-content' ).length ) { 2189 return; 2190 } 2191 2192 event.stopPropagation(); 2193 }; 2194 2195 self.clickFullResults = function( event ) { 2196 2197 var searchInput = $( settings.inputClass, self ), 2198 value = searchInput.val(), 2199 url = JetSearch.getResultsUrl( form ); 2200 2201 event.preventDefault(); 2202 2203 if ( value.length != 0 || true === allowEmptyString ) { 2204 if ( false === disableInputs ) { 2205 disableInputs = true; 2206 2207 value = value.replace(/\u3000/g, ' '); 2208 2209 searchInput.val( value ); 2210 2211 if ( '' != customResultUrl ) { 2212 customResultUrl = $.trim( customResultUrl ); 2213 2214 url = JetSearch.getResultsUrl( form, customResultUrl ); 2215 } 2216 2217 if ( 'yes' === showSearchSuggestions || true === showSearchSuggestions ) { 2218 self.addUserSearch( value ); 2219 } 2220 2221 if ( 'yes' === searchLogging || true === searchLogging ) { 2222 JetSearch.setFormSuggestion( value, form, url ); 2223 } else { 2224 window.location.href = url; 2225 } 2226 } 2227 } 2228 }; 2229 2230 self.syncResultsListHeight = function() { 2231 if ( 'yes' === data.show_search_in_popup || true === data.show_search_in_popup || 'true' === data.show_search_in_popup ) {
2232 var viewportHeight = Math.max( window.innerHeight || 0, document.documentElement ? document.documentElement.clientHeight : 0 ), 2233 holderHeight = Math.max( Math.min( Math.round( viewportHeight * 0.65 ), 720 ), 320 ), 2234 headerHeight = resultsHeader.is( ':visible' ) ? resultsHeader.outerHeight( true ) : 0, 2235 footerHeight = resultsFooter.is( ':visible' ) ? resultsFooter.outerHeight( true ) : 0, 2236 listHeight = Math.max( holderHeight - headerHeight - footerHeight, 160 ); 2237 2238 resultsHolder.css( { 2239 'height': '', 2240 'max-height': holderHeight + 'px' 2241 } ); 2242 resultsList.css( { 2243 'height': 'auto', 2244 'max-height': listHeight + 'px' 2245 } ); 2246 resultsList.scrollTop( 0 ); 2247 2248 return; 2249 } 2250 2251 var activeSlide = $( settings.listSlideClass, resultsListInner ).eq( Math.max( currentPosition - 1, 0 ) ), 2252 slideHeight = activeSlide.length ? activeSlide.outerHeight() : 0; 2253 2254 resultsHolder.css( { 2255 'height': '', 2256 'max-height': '' 2257 } ); 2258 resultsList.css( { 2259 'height': slideHeight > 0 ? slideHeight + 'px' : 'auto', 2260 'max-height': '' 2261 } ); 2262 }; 2263 2264 self.syncResultsListHeightOnImagesLoaded = function() { 2265 resultsListInner.imagesLoaded( function() { 2266 self.syncResultsListHeight(); 2267 } ); 2268 }; 2269 2270 self.changeSlide = function( number ) { 2271 var currentSlide = $( settings.listSlideClass, resultsListInner ).eq( number ), 2272 direction = settings.isRtl ? 1 : -1, 2273 position = number * 100 * direction; 2274 2275 currentSlide.scrollTop( 0 ); 2276 resultsList.scrollTop( 0 ); 2277 resultsListInner.css( 'transform', 'translateX(' + position + '%)' ); 2278 self.syncResultsListHeight(); 2279 }; 2280 2281 self.clickBulletHandler = function( event ) { 2282 var target = $( event.target ); 2283 2284 currentPosition = target.data( 'number' ); 2285 self.syncNavigation(); 2286 2287 self.changeSlide( currentPosition - 1 ); 2288 }; 2289 2290 self.clickNavigationButtonHandler = function( event ) { 2291 var target = $( event.target ), 2292 direction = target.data( 'direction' ); 2293 2294 currentPosition = currentPosition + direction; 2295 self.syncNavigation(); 2296 2297 self.changeSlide( currentPosition - 1 ); 2298 }; 2299 2300 self.syncNavigation = function() { 2301 var lastPosition = resultsListInner.data( 'columns' ), 2302 disableClass = settings.disableNavClass.replace( '.', '' ), 2303 activeClass = settings.activeNavClass.replace( '.', '' ); 2304 2305 $( settings.activeNavClass, self ).removeClass( activeClass ); 2306 $( settings.disableNavClass, self ).removeClass( disableClass ); 2307 2308 $( settings.navButtonClass + '[data-number="' + currentPosition +'"]', self ).addClass( activeClass ); 2309 2310 if ( 1 === currentPosition ) { 2311 $( settings.prevClass, self ).addClass( disableClass ); 2312 } 2313 2314 if ( lastPosition === currentPosition ) { 2315 $( settings.nextClass, self ).addClass( disableClass ); 2316 } 2317 }; 2318 2319 self.formSubmit = function( event ) { 2320 var value = event.target.value, 2321 url = JetSearch.getResultsUrl( form ); 2322 2323 if ( ( 1 > value.length && false === allowEmptyString ) && ( 13 === event.keyCode || 'click' === event.type ) ) { 2324 return false; 2325 } else { 2326 if ( 13 === event.keyCode && allowSubmitOnEnter ) { 2327 if ( false === disableInputs ) { 2328 disableInputs = true; 2329 2330 event.preventDefault(); 2331 2332 if ( '' != customResultUrl ) { 2333 customResultUrl = $.trim( customResultUrl ); 2334 2335 url = JetSearch.getResultsUrl( form, customResultUrl ); 2336 } 2337 2338 self.addUserSearch( value ); 2339 2340 if ( 'yes' === searchLogging || true === searchLogging ) { 2341 JetSearch.setFormSuggestion( value, form, url ); 2342 } else { 2343 window.location.href = url; 2344 } 2345 } 2346 } 2347 } 2348 }; 2349 2350 self.changeHandler = function( event ) { 2351 var target = $( event.target ), 2352 globalQuerySettings = $( self ).data( 'settings' ); 2353 2354 globalQuerySettings.category__in = target.val(); 2355 data.category__in = target.val(); 2356 2357 $( self ).data( 'settings', globalQuerySettings ); 2358 2359 self.inputChangeHandler( { target: $( settings.inputClass, self ) } ) 2360 }; 2361 2362 self.chosenFocusHandler = function() { 2363 JetSearch.markPopupDropdownInteraction( $( self ) ); 2364 self.hideList(); 2365 }; 2366 2367 self.setResultsAreaWidth = function() { 2368 2369 JetSearch.syncAjaxPopupWidth( $( self ) ); 2370 2371 if ( 'fields_holder' !== data.results_area_width_by ) { 2372 return; 2373 } 2374 2375 resultsArea.css( 'width', $( settings.fieldsHolderClass, self ).outerWidth() ); 2376 }; 2377 2378 self.addUserSearch = function( newSearchRequest ) { 2379 if ( 'user' === suggestionsType ) { 2380 newSearchRequest = newSearchRequest.trim(); 2381 2382 if ( ! storedUserSearches.some( search => search === newSearchRequest ) ) { 2383 if ( storedUserSearches.length >= maxUserSearches ) { 2384 storedUserSearches.shift(); 2385 } 2386 2387 storedUserSearches.push( newSearchRequest ); 2388 2389 localStorage.setItem( 'jetUserSearches', JSON.stringify( storedUserSearches ) ); 2390 } 2391 } 2392 } 2393 2394 self.selectSuggestion = function( event ) {
2395 const keyCode = event.keyCode || event.which; 2396 const $target = $( event.currentTarget ); 2397 2398 let value = $target.attr( 'aria-label' ); 2399 2400 if ( ! value ) { 2401 return; 2402 } 2403 2404 value = value.trim(); 2405 2406 let url = null; 2407 2408 if ( false === disableInputs && !editMode ) { 2409 2410 if ( 'keydown' === event.type ) { 2411 if ( 13 === keyCode ) { 2412 disableInputs = true; 2413 2414 $( settings.inputClass, self )[0].value = value; 2415 2416 self.addUserSearch( value ); 2417 2418 url = JetSearch.getResultsUrl( form ); 2419 2420 if ( '' != customResultUrl ) { 2421 customResultUrl = $.trim( customResultUrl ); 2422 2423 url = JetSearch.getResultsUrl( form, customResultUrl ); 2424 } 2425 2426 if ( 'yes' === searchLogging || true === searchLogging ) { 2427 JetSearch.setFormSuggestion( value, false, url ); 2428 } else { 2429 window.location.href = url; 2430 } 2431 } 2432 } else if ( 'click' === event.type ) { 2433 disableInputs = true; 2434 2435 $( settings.inputClass, self )[0].value = value; 2436 2437 self.addUserSearch( value ); 2438 2439 url = JetSearch.getResultsUrl( form ); 2440 2441 if ( '' != customResultUrl ) { 2442 customResultUrl = $.trim( customResultUrl ); 2443 2444 url = JetSearch.getResultsUrl( form, customResultUrl ); 2445 } 2446 2447 if ( 'yes' === searchLogging || true === searchLogging ) { 2448 JetSearch.setFormSuggestion( value, false, url ); 2449 } else { 2450 window.location.href = url; 2451 } 2452 } 2453 } 2454 } 2455 2456 self.customUrlActions = { 2457 selectorOnClick: 'a[href^="#jet-engine-action"][href*="event=click"]', 2458 selectorOnHover: 'a[href^="#jet-engine-action"][href*="event=hover"], [data-url^="#jet-engine-action"][data-url*="event=hover"]', 2459 2460 init: function() { 2461 var timeout = null; 2462 2463 $( document ).on( 'click.JetSearch', this.selectorOnClick, function( event ) { 2464 event.preventDefault(); 2465 self.customUrlActions.actionHandler( event ) 2466 } ); 2467 2468 $( document ).on( 'click.JetSearch', this.selectorOnHover, function( event ) { 2469 if ( 'A' === event.currentTarget.nodeName ) { 2470 event.preventDefault(); 2471 } 2472 } ); 2473 2474 $( document ).on( { 2475 'mouseenter.JetSearch': function( event ) { 2476 2477 if ( timeout ) { 2478 clearTimeout( timeout ); 2479 } 2480 2481 timeout = setTimeout( function() { 2482 self.customUrlActions.actionHandler( event ) 2483 }, window.JetEngineSettings.hoverActionTimeout ); 2484 }, 2485 'mouseleave.JetSearch': function() { 2486 if ( timeout ) { 2487 clearTimeout( timeout ); 2488 timeout = null; 2489 } 2490 }, 2491 }, this.selectorOnHover ); 2492 }, 2493 2494 actions: {}, 2495 2496 addAction: function( name, callback ) { 2497 this.actions[ name ] = callback; 2498 }, 2499 2500 actionHandler: function( event ) { 2501 var url = $( event.currentTarget ).attr( 'href' ) || $( event.currentTarget ).attr( 'data-url' ); 2502 2503 this.runAction( url ); 2504 }, 2505 2506 runAction: function( url ) { 2507 var queryParts = url.split( '&' ), 2508 settings = {}; 2509 2510 queryParts.forEach( function( item ) { 2511 if ( -1 !== item.indexOf( '=' ) ) { 2512 var pair = item.split( '=' ); 2513 2514 settings[ pair[0] ] = decodeURIComponent( pair[1] ); 2515 } 2516 } ); 2517 2518 if ( ! settings.action ) { 2519 return; 2520 } 2521 2522 var actionCb = this.actions[ settings.action ]; 2523 2524 if ( ! actionCb ) { 2525 return; 2526 } 2527 2528 actionCb( settings ); 2529 } 2530 }; 2531 2532 self.handleListingItemClick = function( event ) { 2533 var url = $( this ).data( 'url' ), 2534 target = $( this ).data( 'target' ) || false; 2535 2536 if ( url ) { 2537 2538 event.preventDefault(); 2539 2540 if ( window.elementorFrontend && window.elementorFrontend.isEditMode() ) { 2541 return; 2542 } 2543 2544 if ( -1 !== url.indexOf( '#jet-engine-action' ) ) { 2545 2546 self.customUrlActions.runAction( url ); 2547 2548 } else { 2549 2550 if ( '_blank' === target ) { 2551 window.open( url ); 2552 return; 2553 } 2554 2555 window.location = url; 2556 } 2557 } 2558 }; 2559 2560 self.isWooAddToCartTrigger = function( $target ) { 2561 2562 if ( $target.data( 'product_id' ) || $target.attr( 'data-product_id' ) ) { 2563 return true; 2564 } 2565 2566 const href = $target.attr( 'href' ) || ''; 2567 2568 if ( href && href.includes( 'add-to-cart=' ) ) { 2569 return true; 2570 } 2571 2572 if ( $target.closest( 'form.cart' ).length ) { 2573 return true; 2574 } 2575 2576 if ( $target.is( '.add_to_cart_button, .ajax_add_to_cart, .single_add_to_cart_button' ) ) { 2577 return true; 2578 } 2579 2580 return false;
2581 }; 2582 2583 self.getWooAddToCartData = function( $trigger ) { 2584 let addToCartData = {}, 2585 href = $trigger.attr( 'href' ) || '', 2586 form = $trigger.closest( 'form.cart' ), 2587 productId = $trigger.attr( 'data-product_id' ) || $trigger.data( 'product_id' ) || '', 2588 quantityInput = $trigger.closest( '.jet-ajax-search__item-add-to-cart' ).find( '.jet-ajax-search__results-item-quantity-input' ), 2589 quantity = $trigger.attr( 'data-quantity' ) || $trigger.data( 'quantity' ) || 1; 2590 2591 if ( quantityInput.length && '' !== quantityInput.val() ) { 2592 quantity = quantityInput.val(); 2593 } 2594 2595 $.each( $trigger[0].dataset || {}, function( key, value ) { 2596 addToCartData[ key ] = value; 2597 } ); 2598 2599 if ( form.length ) { 2600 $.each( form.serializeArray(), function( index, field ) { 2601 if ( '' !== field.value ) { 2602 addToCartData[ field.name ] = field.value; 2603 } 2604 } ); 2605 } 2606 2607 if ( href && -1 !== href.indexOf( 'add-to-cart=' ) && ! productId ) { 2608 try { 2609 let parsedUrl = new URL( href, window.location.origin ), 2610 hrefProduct = parsedUrl.searchParams.get( 'add-to-cart' ); 2611 2612 if ( hrefProduct ) { 2613 productId = hrefProduct; 2614 } 2615 } catch ( e ) {} 2616 } 2617 2618 if ( ! productId && addToCartData.product_id ) { 2619 productId = addToCartData.product_id; 2620 } 2621 2622 if ( ! productId && addToCartData['add-to-cart'] ) { 2623 productId = addToCartData['add-to-cart']; 2624 } 2625 2626 if ( productId ) { 2627 addToCartData.product_id = productId; 2628 } 2629 2630 if ( quantity && ! addToCartData.quantity ) { 2631 addToCartData.quantity = quantity; 2632 } 2633 2634 $( document ).trigger( 'jet-ajax-search/resolve-add-to-cart-data', [ addToCartData, $trigger, self ] ); 2635 2636 return addToCartData; 2637 }; 2638 2639 self.normalizeWooAddToCartData = function( addToCartData ) { 2640 let normalizedData = {}; 2641 2642 if ( addToCartData.product_id ) { 2643 normalizedData.product_id = addToCartData.product_id; 2644 } 2645 2646 if ( addToCartData.quantity ) { 2647 normalizedData.quantity = addToCartData.quantity; 2648 } else { 2649 normalizedData.quantity = 1; 2650 } 2651 2652 if ( addToCartData.variation_id ) { 2653 normalizedData.variation_id = addToCartData.variation_id; 2654 } 2655 2656 $.each( addToCartData, function( key, value ) { 2657 if ( 0 === key.indexOf( 'attribute_' ) ) { 2658 normalizedData[ key ] = value; 2659 } 2660 } ); 2661 2662 return normalizedData; 2663 }; 2664 2665 self.handleWooAddToCartInResults = function( event ) { 2666 const $trigger = $( event.target ).closest( 2667 '.add_to_cart_button, .ajax_add_to_cart, .single_add_to_cart_button, [data-product_id], a[href*="add-to-cart="], form.cart button' 2668 ); 2669 2670 if ( ! $trigger.length || ! self.isWooAddToCartTrigger( $trigger ) ) { 2671 return; 2672 } 2673 2674 if ( 'undefined' === typeof wc_add_to_cart_params || ! wc_add_to_cart_params.wc_ajax_url ) { 2675 return; 2676 } 2677 2678 event.preventDefault(); 2679 event.stopImmediatePropagation(); 2680 2681 if ( $trigger.prop( 'disabled' ) || $trigger.hasClass( 'loading' ) ) { 2682 return; 2683 } 2684 2685 let addToCartData = self.getWooAddToCartData( $trigger ); 2686 2687 addToCartData = self.normalizeWooAddToCartData( addToCartData ); 2688 2689 if ( ! addToCartData.product_id ) { 2690 return; 2691 } 2692 2693 $trigger 2694 .removeClass( 'added is-added-to-cart' ) 2695 .addClass( 'loading' ) 2696 .prop( 'disabled', true ); 2697 2698 $( document.body ).trigger( 'adding_to_cart', [ $trigger, addToCartData ] ); 2699 2700 $.ajax( { 2701 type: 'POST', 2702 url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' ), 2703 dataType: 'json', 2704 data: addToCartData, 2705 success: function( response ) { 2706 if ( response && response.error && response.product_url ) { 2707 window.location = response.product_url; 2708 return; 2709 } 2710 2711 if ( response && response.fragments ) { 2712 $.each( response.fragments, function( key, value ) { 2713 $( key ).replaceWith( value ); 2714 } ); 2715 } 2716 2717 $( document.body ).trigger( 'added_to_cart', [ response.fragments || {}, response.cart_hash || '', $trigger ] ); 2718 }, 2719 complete: function() { 2720 $trigger.removeClass( 'loading' ).prop( 'disabled', false ); 2721 } 2722 } ); 2723 }; 2724 2725 self.syncResultsItemQuantity = function( event ) { 2726 const $input = $( event.target ), 2727 value = $input.val() || $input.attr( 'min' ) || 1; 2728 2729 $input 2730 .closest( '.jet-ajax-search__item-add-to-cart' ) 2731 .find( '.jet-ajax-search__results-item-cart-button' ) 2732 .removeClass( 'is-added-to-cart' ) 2733 .attr( 'data-quantity', value ) 2734 .data( 'quantity', value ); 2735 }; 2736 2737 $( settings.inputClass, self ) 2738 .on( 'input' + settings.searchClass, self.inputChangeHandler ) 2739 .on( 'focus' + settings.searchClass, self.focusHandler ) 2740 .on( 'blur' + settings.searchClass, self.blurHandler ) 2741 .on( 'keydown' + settings.searchClass, self.formSubmit ); 2742 2743 $( settings.submitClass, self ).on( 'click' + settings.searchClass, self.clickFullResults ); 2744 2745 $( self ) 2746 .on( 'mousedown' + settings.searchClass, self.formClick ) 2747 .on( 'click' + settings.searchClass, self.formClick ) 2748 .on( 'touchstart' + settings.searchClass, self.formClick ) 2749 .on( 'touchend' + settings.searchClass, self.formClick ) 2750 .on( 'mousedown' + settings.searchClass + ' touchstart' + settings.searchClass, '.chosen-container, .chosen-drop', function() { 2751 JetSearch.markPopupDropdownInteraction( $( self ), 500 ); 2752 } ) 2753 .on( 'click' + settings.searchClass, settings.fullResultsClass, self.clickFullResults ) 2754 .on( 'click' + settings.searchClass, settings.countClass, self.clickFullResults ) 2755 .on( 'click' + settings.searchClass, settings.bulletClass, self.clickBulletHandler ) 2756 .on( 'click' + settings.searchClass, settings.numberClass, self.clickBulletHandler ) 2757 .on( 'click' + settings.searchClass, settings.prevClass + ':not( ' + settings.disableNavClass + ' )', self.clickNavigationButtonHandler ) 2758 .on( 'click' + settings.searchClass, settings.nextClass + ':not( ' + settings.disableNavClass + ' )', self.clickNavigationButtonHandler ) 2759 .on( 'click keydown' + settings.searchClass, settings.inlineSuggestionsItemClass, self.selectSuggestion ) 2760 .on( 'click keydown' + settings.searchClass, settings.resultsSuggestionItemClass, self.selectSuggestion ) 2761 .on( 'input change' + settings.searchClass, '.jet-ajax-search__results-item-quantity-input', self.syncResultsItemQuantity ) 2762 .on( 'change', settings.chosenClass, self.changeHandler ) 2763 .on( 'chosen:showing_dropdown', settings.chosenClass, self.chosenFocusHandler ) 2764 .on( 'click' + settings.searchClass, '.jet-engine-listing-overlay-wrap:not([data-url*="event=hover"])', self.handleListingItemClick ) 2765 .on( 'click' + settings.searchClass, 2766 settings.resultsAreaClass + ' .add_to_cart_button, ' + 2767 settings.resultsAreaClass + ' .ajax_add_to_cart, ' + 2768 settings.resultsAreaClass + ' form.cart .single_add_to_cart_button', 2769 self.handleWooAddToCartInResults 2770 ); 2771 2772 $( document.body ) 2773 .on( 'adding_to_cart' + settings.searchClass, function( event, $trigger ) { 2774 if ( ! $trigger || ! $trigger.closest( settings.resultsAreaClass ).length ) { 2775 return; 2776 } 2777 2778 $trigger 2779 .removeClass( 'added is-added-to-cart' ) 2780 .siblings( '.added_to_cart, .wc-forward' ) 2781 .remove(); 2782 } ) 2783 .on( 'added_to_cart' + settings.searchClass, function( event, fragments, cartHash, $trigger ) { 2784 if ( ! $trigger || ! $trigger.closest( settings.resultsAreaClass ).length ) { 2785 return; 2786 } 2787 2788 $trigger 2789 .addClass( 'is-added-to-cart' ) 2790 .siblings( '.added_to_cart, .wc-forward' ) 2791 .remove(); 2792 } ); 2793 2794 if ( ! allowSubmitOnEnter ){ 2795 $( window ).keydown( function( event ) { 2796 if ( 13 === event.keyCode && event.target.className.includes( 'jet-ajax-search' ) ) { 2797 event.preventDefault(); 2798 return false;
2799 } 2800 }); 2801 } 2802 2803 $( self ).on( 'keydown', function( e ) { 2804 const keyCode = e.keyCode || e.which; 2805 2806 if ( 9 === keyCode ) { 2807 setTimeout( () => { 2808 const focusedElement = document.activeElement; 2809 2810 if ( $( focusedElement ).is( '.chosen-search-input' ) ) { 2811 $( '.chosen-single', self ).addClass( 'focused' ); 2812 } else { 2813 $( '.chosen-single', self ).removeClass( 'focused' ); 2814 } 2815 }, 50 ); 2816 } 2817 } ); 2818 2819 $( settings.inputClass, self ).on( 'click' + settings.searchClass, () => { 2820 $( '.chosen-single', self ).removeClass( 'focused' ); 2821 } ); 2822 2823 if ( '' != categoryIndex ) { 2824 let target = $( settings.chosenClass, self ), 2825 globalQuerySettings = $( self ).data( 'settings' ), 2826 categorySelect = $( '.jet-ajax-search__categories-select', self ), 2827 currentCategory = ''; 2828 2829 categorySelect.find( 'option' ).each( function() { 2830 var value = $( this ).val(); 2831 2832 if ( value === categoryIndex ) { 2833 currentCategory = $( this ).text(); 2834 } 2835 } ); 2836 2837 categorySelect.find( 'option:contains("' + currentCategory + '")' ).attr( 'selected', 'selected' ); 2838 2839 globalQuerySettings.category__in = target.val(); 2840 data.category__in = target.val(); 2841 2842 $( self ).data( 'settings', globalQuerySettings ); 2843 } else { 2844 // If after reloading the page the value of the select is not '0'. 2845 2846 if ( '0' !== $( settings.chosenClass, self ).val() ) { 2847 $( settings.chosenClass, self ).trigger( 'change' ); 2848 } 2849 } 2850 2851 $( 'body' ) 2852 .on( 'click' + settings.searchClass, self.hideList ) 2853 .on( 'touchend' + settings.searchClass, self.hideList ); 2854 2855 self.setResultsAreaWidth(); 2856 $( window ).on( 'resize' + settings.searchClass, self.setResultsAreaWidth ); 2857 2858 $( window ).on( 'orientationchange resize', function () { 2859 self.syncResultsListHeightOnImagesLoaded(); 2860 } ); 2861 2862 } else { 2863 return 'is init: true'; 2864 } 2865 }; 2866 2867 // initialize after all is defined 2868 $( window ).on( 'elementor/frontend/init', JetSearch.initElementor ); 2869 JetSearch.initBlocks(); 2870 2871 window.jetSearchBricks = function() { 2872 JetSearch.initBricks(); 2873 } 2874 2875 window.JetSearch = JetSearch; 2876 2877}( 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.