PageSourceSearch

https://r22er.com/wp-content/plugins/advanced-woo-search/assets/js/common.js?ver=3.26

js r22er.com collected 2026-10-02 11:21:05 UTC 37,158 bytes, 930 lines download raw bytes

1// Hooks
2var AwsHooks = AwsHooks || {};
3AwsHooks.filters = AwsHooks.filters || {};
4
5(function($){
6    "use strict";
7
8    var selector = '.aws-container';
9    var instance = 0;
10    var pluginPfx = 'aws_opts';
11    var translate = {
12        sale      : aws_vars.sale,
13        sku       : aws_vars.sku,
14        showmore  : aws_vars.showmore,
15        noresults : aws_vars.noresults
16    };
17
18    AwsHooks.add_filter = function( tag, callback, priority ) {
19
20        if( typeof priority === "undefined" ) {
21            priority = 10;
22        }
23
24        AwsHooks.filters[ tag ] = AwsHooks.filters[ tag ] || [];
25        AwsHooks.filters[ tag ].push( { priority: priority, callback: callback } );
26
27    };
28
29    AwsHooks.apply_filters = function( tag, value, options ) {
30
31        var filters = [];
32
33        if( typeof AwsHooks.filters[ tag ] !== "undefined" && AwsHooks.filters[ tag ].length > 0 ) {
34
35            AwsHooks.filters[ tag ].forEach( function( hook ) {
36
37                filters[ hook.priority ] = filters[ hook.priority ] || [];
38                filters[ hook.priority ].push( hook.callback );
39            } );
40
41            filters.forEach( function( AwsHooks ) {
42
43                AwsHooks.forEach( function( callback ) {
44                    value = callback( value, options );
45                } );
46
47            } );
48        }
49
50        return value;
51
52    };
53
54    $.fn.aws_search = function( options ) {
55
56        var methods = {
57
58            init: function() {
59
60                // @since 2.16
61                var appendResultsTo = AwsHooks.apply_filters( 'aws_results_append_to', 'body', { instance: instance, form: self, data: d } );
62
63                $(appendResultsTo).append('<div id="aws-search-result-' + instance + '" class="aws-search-result" style="display: none;"></div>');
64
65                methods.addClasses();
66
67                setTimeout(function() { methods.resultLayout(); }, 500);
68
69            },
70
71            onKeyup: function(e) {
72
73                searchFor = $searchField.val();
74                searchFor = searchFor.trim();
75                searchFor = searchFor.replace( /<>\{\}\[\]\\\/]/gi, '' );
76                searchFor = searchFor.replace( /\s\s+/g, ' ' );
77
78                for ( var i = 0; i < requests.length; i++ ) {
79                    requests[i].abort();
80                }
81
82                methods.searchRequest();
83
84            },
85
86            searchRequest: function() {
87
88                if ( ! d.ajaxSearch ) {
89                    if ( searchFor !== '' ) {
90                        methods.showResultsBlock();
91                    }
92                    return;
93                }
94
95                if ( searchFor === '' ) {
96                    $(d.resultBlock).html('').hide();
97                    methods.hideLoader();
98                    methods.resultsHide();
99                    return;
100                }
101
102                if ( cachedResponse.hasOwnProperty( searchFor ) ) {
103                    methods.showResults( cachedResponse[searchFor] );
104                    return;
105                }
106
107                if ( searchFor.length < d.minChars ) {
108                    $(d.resultBlock).html('');
109                    methods.hideLoader();
110                    return;
111                }
112
113                if ( d.showLoader ) {
114                    methods.showLoader();
115                }
116
117                var searchTimeout = d.searchTimeout > 100 ? d.searchTimeout : 300;
118
119                clearTimeout( keyupTimeout );
120                keyupTimeout = setTimeout( function() {
121                    methods.ajaxRequest();
122                }, searchTimeout );
123
124            },
125
126            ajaxRequest: function() {
127
128                var data = {
129                    action: 'aws_action',
130                    keyword : searchFor,
131                    aws_page: d.pageId,
132                    aws_tax: d.tax,
133                    lang: d.lang,
134                    pageurl: window.location.href,
135                    typedata: 'json'
136                };
137
138                data = AwsHooks.apply_filters( 'aws_ajax_request_params', data, { instance: instance, form: self, data: d } );
139
140                requests.push(
141
142                    $.ajax({
143                        type: 'POST',
144                        url: ajaxUrl,
145                        data: data,
146                        dataType: 'json',
147                        success: function( response ) {
148
149                            methods.analytics( searchFor, false );
150
151                            cachedResponse[searchFor] = response;
152
153                            methods.showResults( response );
154
155                            methods.showResultsBlock();
156
157                        },
158                        error: function (jqXHR, textStatus, errorThrown) {
159                            console.log( "Request failed: " + textStatus );
160                            methods.hideLoader();
161                        }
162                    })
163
164                );
165
166            },
167
168            showResults: function( response ) {
169
170                var resultNum = 0;
171                var taxName = '';
172
173                var html = '<ul>';
174
175                if ( typeof response.data !== 'undefined' ) {
176
177                    if ( typeof response.data.top_text !== 'undefined' && response.data.top_text ) {
178                        html += '<div class="aws_top_text">
178' + response.data.top_text + '</div>';
179                    }
180
181                    if ( typeof response.data.notices !== 'undefined' ) {
182                        $.each(response.data.notices, function (i, notice) {
183                            html += '<div class="aws_top_text">' + notice + '</div>';
184                        });
185                    }
186
187                    if ( typeof response.data.top_results !== 'undefined' ) {
188
189                        $.each(response.data.top_results, function (i, topResults) {
190
191                            var topResultsName = i;
192
193                            if ( ( typeof topResults !== 'undefined' ) && topResults.length > 0 ) {
194
195                                $.each(topResults, function (i, topResult) {
196
197                                    var linkData = ( typeof topResult.link_data !== 'undefined' ) ? topResult.link_data : '';
198
199                                    html += '<li class="aws_result_item aws_result_top_custom_item aws_result_top_custom_item_' + topResultsName + '" style="position:relative;">';
200                                        html += '<div class="aws_result_link">';
201                                            html += '<a class="aws_result_link_top" ' + linkData + ' href="' + topResult.link + '">' + topResult.name + '</a>';
202                                            html += '<span class="aws_result_content">';
203                                                html += '<span class="aws_result_title">';
204                                                    html += topResult.name;
205                                                html += '</span>';
206                                                if ( ( typeof topResult.content !== 'undefined' ) && topResult.content ) {
207                                                    html += '<span class="aws_result_excerpt">' + topResult.content + '</span>';
208                                                }
209                                            html += '</span>';
210                                        html += '</div>';
211                                    html += '</li>';
212
213                                });
214
215                            }
216
217                        });
218
219                    }
220
221                }
222
223                if ( typeof response.tax !== 'undefined' ) {
224
225                    $.each(response.tax, function (i, taxes) {
226
227                        taxName = i;
228
229                        if ( ( typeof taxes !== 'undefined' ) && taxes.length > 0 ) {
230                            $.each(taxes, function (i, taxitem) {
231
232                                resultNum++;
233
234                                html += '<li class="aws_result_item aws_result_tag aws_result_tax_' + taxName + '" style="position:relative;">';
235                                    html += '<div class="aws_result_link">';
236                                        html += '<a class="aws_result_link_top" href="' + taxitem.link + '">' + taxitem.name + '</a>';
237                                        html += '<span class="aws_result_content">';
238                                            html += '<span class="aws_result_title">';
239                                                html += taxitem.name;
240                                                if ( taxitem.count ) {
241                                                    html += '<span class="aws_result_count">&nbsp;(' + taxitem.count + ')</span>';
242                                                }
243                                            html += '</span>';
244                                            if ( ( typeof taxitem.excerpt !== 'undefined' ) && taxitem.excerpt ) {
245                                                html += '<span class="aws_result_excerpt">' + taxitem.excerpt + '</span>';
246                                            }
247                                        html += '</span>';
248                                    html += '</div>';
249                                html += '</li>';
250
251                            });
252                        }
253
254                    });
255
256                }
257
258                if ( ( typeof response.products !== 'undefined' ) && response.products.length > 0 ) {
259
260                    $.each(response.products, function (i, result) {
261
262                        resultNum++;
263
264                        html += '<li class="aws_result_item" style="position:relative;">';
265                        html += '<div class="aws_result_link">';
266
267                        html += '<a class="aws_result_link_top" href="' + result.link + '">' + result.title.replace(/(<[\s\S]*>)/gm, '') + '</a>';
268
269                        if ( result.image ) {
270                            html += '<span class="aws_result_image">';
271                            html += '<img src="' + result.image 
271+ '">';
272                            html += '</span>';
273                        }
274
275                        html += '<span class="aws_result_content">';
276
277                        html += '<span class="aws_result_title">';
278                            html += result.title;
279                            if ( result.featured ) {
280                                html += '<span class="aws_result_featured" title="Featured"><svg version="1.1" viewBox="0 0 20 21" xmlns="http://www.w3.org/2000/svg" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns" xmlns:xlink="http://www.w3.org/1999/xlink"><g fill-rule="evenodd" stroke="none" stroke-width="1"><g transform="translate(-296.000000, -422.000000)"><g transform="translate(296.000000, 422.500000)"><path d="M10,15.273 L16.18,19 L14.545,11.971 L20,7.244 L12.809,6.627 L10,0 L7.191,6.627 L0,7.244 L5.455,11.971 L3.82,19 L10,15.273 Z"/></g></g></g></svg></span>';
281                            }
282                        html += '</span>';
283
284                        if ( result.stock_status ) {
285                            var statusClass = result.stock_status.status ? 'in' : 'out';
286                            html += '<span class="aws_result_stock ' + statusClass + '">';
287                                html += result.stock_status.text;
288                            html += '</span>';
289                        }
290
291                        if ( result.sku ) {
292                            html += '<span class="aws_result_sku">' + translate.sku +  result.sku + '</span>';
293                        }
294
295                        if ( result.excerpt ) {
296                            html += '<span class="aws_result_excerpt">' + result.excerpt + '</span>';
297                        }
298
299                        if ( result.price ) {
300                            html += '<span class="aws_result_price">' + result.price + '</span>';
301                        }
302
303                        html += '</span>';
304
305                        if ( result.on_sale ) {
306                            html += '<span class="aws_result_sale">';
307                            html += '<span class="aws_onsale">' + translate.sale + '</span>';
308                            html += '</span>';
309                        }
310
311                        html += '</div>';
312                        html += '</li>';
313
314                    });
315
316                    if ( d.showMore && d.showPage ) {
317                        html += '<li class="aws_result_item aws_search_more"><a href="#">' + translate.showmore + '</a></li>';
318                    }
319
320                    //html += '<li class="aws_result_item"><a href="#">Next Page</a></li>';
321
322                }
323
324                if ( ! resultNum ) {
325                    html += '<li class="aws_result_item aws_no_result">' + translate.noresults + '</li>';
326                }
327
328
329                html += '</ul>';
330
331                // @since 2.05
332                html = AwsHooks.apply_filters( 'aws_results_html', html, { response: response, data: d, translate: translate } );
333
334
335                methods.hideLoader();
336
337                $(d.resultBlock).html( html );
338
339                methods.showResultsBlock();
340
341                if ( eShowResults ) {
342                    self[0].dispatchEvent( eShowResults );
343                }
344
345            },
346
347            showResultsBlock: function() {
348                methods.resultLayout();
349                methods.resultsShow();
350            },
351
352            showLoader: function() {
353                $searchForm.addClass('aws-processing');
354            },
355
356            hideLoader: function() {
357                $searchForm.removeClass('aws-processing');
358            },
359
360            resultsShow: function() {
361                $(d.resultBlock).show();
362                $searchForm.addClass('aws-form-active');
363            },
364
365            resultsHide: function() {
366                $(d.resultBlock).hide();
367                $searchForm.removeClass('aws-form-active');
368            },
369
370            onFocus: function( event ) {
371
372                var show = AwsHooks.apply_filters( 'aws_show_modal_layout', false, { instance: instance, form: self, data: d } );
373
374                if ( ! $('body').hasClass('aws-overlay') && ( ( methods.isMobile() && d.mobileScreen && ! methods.isFixed() ) || show ) ) {
375                    methods.showMobileLayout();
376                }
377
378                if ( searchFor !== '' ) {
379                    methods.showResultsBlock();
380                }
381
382            },
383
384            hideResults: function( event ) {
385                if ( ! $(event.target).closest( ".aws-container" ).length
386                    && ! $(event.target).closest( self ).length
387                    && ! $(event.target).closest( d.resultBlock ).length
388                ) {
389                    methods.resultsHide();
390                }
391            },
392
393            isResultsVisible:function() {
394                return $(d.resultBlock).is(":visible");
395            },
396
397            removeHovered: function() {
398                $( d.resultBlock ).find('.aws_result_item').removeClass('hovered');
399            },
400
401            resultLayout: function () {
402
403                var $resultsBlock = $( d.resultBlock );
404                var offset = self.offset();
405                var bodyOffset = $('body').offset();
406                var bodyPosition = $('body').css('position');
407                var bodyHeight = $(document).height();
408                var resultsHeight = $resultsBlock.height();
409
410                // @since 2.45
411                var forcePosition = AwsHooks.apply_filters( 'aws_results_force_position', false, { resultsBlock: $resultsBlock, form: self } );
412
413                if ( offset && bodyOffset  ) {
414
415                    var styles = {
416                        width: self.outerWidth(),
417                        top : 0,
418                        left: 0
419                    };
420
421                    if ( bodyPosition === 'relative' || bodyPosition === 'absolute' || bodyPosition === 'fixed' ) {
422                        styles.top = offset.top + $(self).innerHeight() - bodyOffset.top;
423                        styles.left = offset.left - bodyOffset.left;
424                    } else {
425                        styles.top = offset.top + $(self).innerHeight();
426                        styles.left = offset.left;
427                    }
428
429                    if ( ( ( bodyHeight - offset.top < 500 ) && ! forcePosition ) || ( forcePosition && forcePosition == 'top' ) ) {
430                        resultsHeight = methods.getResultsBlockHeight();
431                        if ( ( ( bodyHeight - offset.top < resultsHeight ) && ( offset.top >= resultsHeight ) ) || forcePosition ) {
432                            styles.top = styles.top - resultsHeight - $(self).innerHeight();
433                        }
434                    }
435
436                    // @since 2.10
437                    styles = AwsHooks.apply_filters( 'aws_results_layout', styles, { resultsBlock: $resultsBlock, form: self } );
438
439                    $resultsBlock.css( styles );
440
441                }
442
443            },
444
445            getResultsBlockHeight: function() {
446
447                var $resultsBlock = $( d.resultBlock );
448                var resultsHeight = $resultsBlock.height();
449
450                if ( resultsHeight === 0 ) {
451                    var copied_elem = $resultsBlock.clone()
452                        .attr("id", false)
453                        .css({visibility:"hidden", display:"block",
454                            position:"absolute"});
455                    $("body").append(copied_elem);
456                    //copied_elem.find('.mCSB_outside').attr('style', '');
457                    resultsHeight = copied_elem.height();
458                    copied_elem.remove();
459                }
460
461                return resultsHeight;
462
463            },
464
465            forceNewSearch: function ( term, submit ) {
466
467                if ( term && term !== '' ) {
468
469                    $searchField.val(term);
470                    searchFor = term;
471
472                    window.setTimeout(function(){
473                        methods.searchRequest();
474                        $searchField.focus();
475                        if ( submit || ! d.ajaxSearch ) {
476                            $searchForm.submit();
477                        }
478                    }, 50);
479
480                }
481
482            },
483
484            showMobileLayout: function() {
485                self.after('<div class="aws-placement-container"></div>');
486                self.addClass('aws-mobile-fixed').prepend('<div class="aws-mobile-fixed-close"><svg width="17" height="17" viewBox="1.5 1.5 21 21"><path d="M22.182 3.856c.522-.554.306-1.394-.234-1.938-.54-.543-1.433-.523-1.826-.135C19.73 2.17 11.955 10 11.955 10S4.225 2.154 3.79 1.783c-.438-.371-1.277-.4-1.81.135-.533.537-.628 1.513-.25 1.938.377.424 8.166 8.218 8.166 8.218s-7.85 7.864-8.166 8.219c-.317.354-.34 1.335.25 1.805.59.47 1.24.455 1.81 0 .568-.456 8.166-7.951 8.166-7.951l8.167 7.86c.747.72 1.504.563 1.96.09.456-.471.609-1.268.1-1.804-.508-.537-8.167-8.219-8.167-8.219s7.645-7.665 8.167-8.218z"></path></svg></div>');
487                $('body').addClass('aws-overlay').append('<div class="aws-overlay-mask"></div>').append( self );
488                $searchField.focus();
489            },
490
491            hideMobileLayout: function() {
492                $('.aws-placement-container').after( self ).remove();
493                self.removeClass('aws-mobile-fixed');
494                $('body').removeClass('aws-overlay');
495                $('.aws-mobile-fixed-close').remove();
496                $('.aws-overlay-mask').remove();
497            },
498            
499            isFixed: function() {
500                var $checkElements = self.add(self.parents());
501                var isFixed = false;
502                $checkElements.each(function(){
503                    if ($(this).css("position") === "fixed") {
504                        isFixed = true;
505                        return false;
506                    }
507                });
508                return isFixed;
509            },
510
511            analytics: function( label, submit ) {
512
513                /* from 2.95 */
514                methods.createAndDispatchEvent( document, 'awsAnalytics', { term: label, instance: instance, form: self, data: d } );
515
516                if ( d.useAnalytics ) {
517
518                    try {
519                        var sPage = submit ? '' : '/?s=' + encodeURIComponent( 'ajax-search:' + label );
520
521                        var tagF = false;
522                        if ( typeof gtag !== 'undefined' && gtag !== null ) {
523                            tagF = gtag;
524                        } else if ( typeof window.dataLayer !== 'undefined' && window.dataLayer !== null ) {
525                            tagF = function () { window.dataLayer.push(arguments) };
526                        }
527
528                        if ( tagF ) {
529
530                            tagF('event', 'AWS search', {
531                                'event_label': label,
532                                'event_category': 'AWS Search Term',
533                                'transport_type' : 'beacon'
534                            });
535
536                            tagF('event', 'aws_search', {
537                                'aws_search_term': label
538                            });
539
540                            if ( sPage ) {
541                                tagF('event', 'page_view', {
542                                    'page_path': sPage,
543                                    'page_title' : 'AWS search'
544                                });
545                            }
546
547                        }
548
549                        if ( typeof ga !== 'undefined' && ga !== null ) {
550                            ga('send', 'event', 'AWS search', 'AWS Search Term', label);
551                            if ( sPage ) {
552                                ga( 'send', 'pageview', sPage );
553                            }
554                        }
555
556                        if ( typeof pageTracker !== "undefined" && pageTracker !== null ) {
557                            if ( sPage ) {
558                                pageTracker._trackPageview( sPage );
559                            }
560                            pageTracker._trackEvent( 'AWS search', 'AWS search', 'AWS Search Term', label )
561                        }
562                        if ( typeof _gaq !== 'undefined' && _gaq !== null ) {
563                            _gaq.push(['_trackEvent', 'AWS search', 'AWS Search Term', label ]);
564                            if ( sPage ) {
565                                _gaq.push(['_trackPageview', sPage]);
566                            }
567                        }
568                        // This uses Monster Insights method of tracking Google Analytics.
569                        if ( typeof __gaTracker !== 'undefined' && __gaTracker !== null ) {
570                            __gaTracker( 'send', 'event', 'AWS search', 'AWS Search Term', label );
571                            if ( sPage ) {
572                                __gaTracker( 'send', 'pageview', sPage );
573                            }
574                        }
575                    }
576                    catch (error) {
577                    }
578                }
579            },
580
581            addClasses: function() {
582                if ( methods.isMobile() || d.showClear ) {
583                    $searchForm.addClass('aws-show-clear');
584                }
585            },
586
587            isMobile: function() {
588                var check = false;
589                (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|
589sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
590                return check;
591            },
592
593            createCustomEvent: function( event, params ) {
594
595                var customEvent = false;
596                params = params || null;
597
598                if ( typeof window.CustomEvent === "function" ) {
599                    customEvent = new CustomEvent( event, { bubbles: true, cancelable: true, detail: params } );
600
601                }
602                else if ( document.createEvent ) {
603                    customEvent = document.createEvent( 'CustomEvent' );
604                    customEvent.initCustomEvent( event, true, true, params );
605                }
606
607                return customEvent;
608
609            },
610
611            createAndDispatchEvent: function( obj, event, params ) {
612
613                var customEvent = methods.createCustomEvent( event, params );
614
615                if ( customEvent ) {
616                    obj.dispatchEvent( customEvent );
617                }
618
619            }
620
621        };
622
623
624        var self            = $(this),
625            $searchForm     = self.find('.aws-search-form'),
626            $searchField    = self.find('.aws-search-field'),
627            $searchButton   = self.find('.aws-search-btn'),
628            haveResults     = false,
629            eShowResults    = false,
630            requests        = Array(),
631            searchFor       = '',
632            keyupTimeout,
633            cachedResponse = new Array();
634
635        var ajaxUrl = ( self.data('url') !== undefined ) ? self.data('url') : false;
636
637        if ( document.createEvent ){
638            eShowResults = document.createEvent("Event");
639            eShowResults.initEvent('awsShowingResults', true, true);
640            eShowResults.eventName = 'awsShowingResults';
641        }
642
643        if ( options === 'relayout' ) {
644            var d = self.data(pluginPfx);
645            methods.resultLayout();
646            return;
647        }
648
649
650        instance++;
651
652        self.data( pluginPfx, {
653            minChars  : ( self.data('min-chars') !== undefined ) ? self.data('min-chars') : 1,
654            lang : ( self.data('lang') !== undefined ) ? self.data('lang') : false,
655            showLoader: ( self.data('show-loader') !== undefined ) ? self.data('show-loader') : true,
656            showMore: ( self.data('show-more') !== undefined ) ? self.data('show-more') : true,
657            ajaxSearch: ( self.data('ajax-search') !== undefined ) ? self.data('ajax-search') : true,
658            showPage: ( self.data('show-page') !== undefined ) ? self.data('show-page') : true,
659            showClear: ( self.data('show-clear') !== undefined ) ? self.data('show-clear') : false,
660            mobileScreen: ( self.data('mobile-screen') !== undefined ) ? self.data('mobile-screen') : false,
661            useAnalytics: ( self.data('use-analytics') !== undefined ) ? self.data('use-analytics') : false,
662            searchTimeout: ( self.data('timeout') !== undefined ) ? parseInt( self.data('timeout') ) : 300,
663            instance: instance,
664            resultBlock: '#aws-search-result-' + instance,
665            pageId: ( self.data('page-id') !== undefined ) ? self.data('page-id') : 0,
666            tax: ( self.data('tax') !== undefined ) ? self.data('tax') : 0
667        });
668
669
670        var d = self.data(pluginPfx);
671
672
673        // AWS is fully loaded
674        methods.createAndDispatchEvent( document, 'awsLoaded', { instance: instance, form: self, data: d } );
675
676
677        if ( $searchForm.length > 0 ) {
678            methods.init.call(this);
679        }
680
681
682        $searchField.on( 'keyup input', function(e) {
683            if ( e.keyCode != 40 && e.keyCode != 38 ) {
684                methods.onKeyup(e);
685            }
686        });
687
688
689        $searchField.on( 'focus', function (e) {
690            $searchForm.addClass('aws-focus');
691            methods.onFocus(e);
692        });
693
694        $searchField.on( 'focusout', function (e) {
695            $searchForm.removeClass('aws-focus');
696        });
697
698        $searchField.on( 'aws_search_force', function (e, term) {
699            methods.forceNewSearch( term, false );
700        });
701
702        $searchForm.on( 'keypress', function(e) {
703            if ( e.keyCode == 13 && ( ! d.showPage || $searchField.val() === '' ) ) {
704                e.preventDefault();
705            }
706        });
707
708
709        $searchButton.on( 'click', function (e) {
710            if ( d.showPage && $searchField.val() !== '' ) {
711                $searchForm.submit();
712            }
713        });
714
715
716        $searchForm.find('.aws-search-clear').on( 'click', function (e) {
717            $searchField.val('');
718            $searchField.focus();
719            methods.resultsHide();
720            $(d.resultBlock).html('');
721            searchFor = '';
722        });
723
724
725        $searchForm.on( 'submit', function(e) {
726            if ( ! d.ajaxSearch ) {
727                methods.analytics( $searchField.val(), true );
728            }
729        });
730
731
732        $(document).on( 'click', function (e) {
733            methods.hideResults(e);
734        });
735
736
737        $(window).on( 'resize', function(e) {
738            methods.resultLayout();
739        });
740
741
742        $(window).on( 'scroll', function(e) {
743            if ( $( d.resultBlock ).css('display') == 'block' ) {
744                methods.resultLayout();
745            }
746        });
747
748
749        $( d.resultBlock ).on( 'mouseenter', '.aws_result_item', function() {
750            methods.removeHovered();
751            $(this).addClass('hovered');
752            $searchField.trigger('mouseenter');
753        });
754
755
756        $( d.resultBlock ).on( 'mouseleave', '.aws_result_item', function() {
757            methods.removeHovered();
758        });
759
760
761        $( d.resultBlock ).on( 'click', '.aws_search_more', function(e) {
762            e.preventDefault();
763            $searchForm.submit();
764        });
765
766        $( d.resultBlock ).on( 'click', 'span[href], [data-link]', function(e) {
767            e.preventDefault();
768            var link = $(this).data('link') ? $(this).data('link') : $(this).attr('href');
769            if ( link === '' || link === '#' ) {
770                return;
771            }
772            e.stopPropagation();
773            if ( link ) {
774                window.location = link;
775            }
776        });
777
778        $( d.resultBlock ).on( 'click', '[data-aws-term-submit]', function(e) {
779            e.preventDefault();
780            var term = $(this).data('aws-term-submit');
781            var submit = $(this).data('aws-term-submit-form') ? true : false;
782            methods.forceNewSearch( term, submit );
783        });
784
785        $( self ).on( 'click', '.aws-mobile-fixed-close', function(e) {
786            methods.hideMobileLayout();
787        });
788
789
790        $(window).on( 'keydown', function(e) {
791
792            if ( e.keyCode == 40 || e.keyCode == 38 ) {
793                if ( methods.isResultsVisible() ) {
794
795                    e.stopPropagation();
796                    e.preventDefault();
797
798                    var $item = $( d.resultBlock ).find('.aws_result_item');
799                    var $hoveredItem = $( d.resultBlock ).find('.aws_result_item.hovered');
800                    var $itemsList = $( d.resultBlock ).find('ul');
801
802                    if ( e.keyCode == 40 ) {
803
804                        if ( $hoveredItem.length > 0 ) {
805                            methods.removeHovered();
806                            $hoveredItem.next().addClass('hovered');
807                        } else {
808                            $item.first().addClass('hovered');
809                        }
810
811                    }
812
813                    if ( e.keyCode == 38 ) {
814
815                        if ( $hoveredItem.length > 0 ) {
816                            methods.removeHovered();
817                            $hoveredItem.prev().addClass('hovered');
818                        } else {
819                            $item.last().addClass('hovered');
820                        }
821
822                    }
823
824                    var activeItemOffset = $(".aws_result_item.hovered").position();
825                    if ( activeItemOffset ) {
826                        $itemsList.animate({
827                            scrollTop: activeItemOffset.top + $itemsList.scrollTop()
828                        }, 400);
829                    }
830
831                }
832            }
833
834        });
835
836
837    };
838
839
840    // Call plugin method
841    $(document).ready( function() {
842
843        $(selector).each( function() {
844            $(this).aws_search();
845        });
846
847        // Enfold header
848        $('[data-avia-search-tooltip]').on( 'click', function() {
849            window.setTimeout(function(){
850                $(selector).aws_search();
851            }, 1000);
852        } );
853
854        // Search results filters fix
855        var $filters_widget = $('.woocommerce.widget_layered_nav_filters');
856        var searchQuery = window.location.search;
857
858        if ( $filters_widget.length > 0 && searchQuery ) {
859            if ( searchQuery.indexOf('type_aws=true') !== -1 ) {
860                var $filterLinks = $filters_widget.find('ul li.chosen a');
861                if ( $filterLinks.length > 0 ) {
862                    var addQuery = '&type_aws=true';
863                    $filterLinks.each( function() {
864                        var filterLink = $(this).attr("href");
865                        if ( filterLink && filterLink.indexOf('post_type=product') !== -1 ) {
866                            $(this).attr( "href", filterLink + addQuery );
867                        }
868                    });
869                }
870            }
871        }
872
873        // Buttons to force certain terms search
874        $('[data-aws-term-submit]').on( 'click', function(e) {
875            e.preventDefault();
876
877            var $btn = $(this);
878            var term = $btn.data('aws-term-submit');
879            var searchForm;
880
881            if ( $btn.closest('.aws-search-result').length > 0  ) {
882                return;
883            }
884
885            if ( term && term !== '' ) {
886
887                if ( $btn.data('aws-selector') !== 'undefined' ) {
888                    var selector = $btn.data('aws-selector');
889                    searchForm = $( $btn.data('aws-selector') );
890                    if ( searchForm.length > 0 && ! searchForm.hasClass('aws-search-form') ) {
891                        searchForm = searchForm.find('.aws-search-form');
892                    }
893                } else if ( $btn.prev('.aws-container').length > 0 ) {
894                    searchForm = $btn.prev('.aws-container').find('.aws-search-form');
895                } else if ( $btn.next('.aws-container').length > 0 ) {
896                    searchForm = $btn.next('.aws-container').find('.aws-search-form');
897                } else if ( $btn.closest('.aws-container').length > 0 ) {
898                    searchForm = $btn.closest('.aws-container').find('.aws-search-form');
899                }
900
901                if ( typeof searchForm === 'undefined' || ! searchForm.length > 0 ) {
902
903                    var parentCount = 0;
904                    var parentElem;
905
906                    do {
907                        parentCount++;
908                        parentElem = typeof parentElem !== 'undefined' ? parentElem.parent() : $btn.parent();
909                        searchForm = parentElem.find('.aws-search-form');
910                    } while ( parentCount < 4 && ! searchForm.length > 0 );
911
912                    if ( ( typeof searchForm === 'undefined' || ! searchForm.length > 0 ) && $('.aws-container:visible:first').length > 0 ) {
913                        searchForm = $('.aws-container:visible:first .aws-search-form');
914                    }
915
916                }
917
918                if ( searchForm && searchForm.length > 0 ) {
919                    var $searchField = searchForm.find('.aws-search-field');
920                    $searchField.trigger( 'aws_search_force', [ term ] );
921                }
922
923            }
924
925        } );
926
927    });
928
929
930})( 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.