PageSourceSearch

https://asianturtleprogram.org/wp-content/themes/xtra/assets/js/search.js?ver=7.0.6

js asianturtleprogram.org collected 2026-09-24 22:51:32 UTC 6,398 bytes, 212 lines download raw bytes

1jQuery( function( $ ) {
2
3	var body 	= $( document.body ),
4		overlay = $( '.codevz-plus-dropdown-overlay .inner_layout > .cz_overlay' );
5
6	let typingTimer;
7
8	// Header search custom category selection list.
9	body.on( 'click', '.codevz-search-category > strong', function() {
10
11		$( '.codevz-search-category > div' ).slideToggle( 'fast' );
12
13	}).on( 'click', '.codevz-search-category li', function() {
14
15		var $this = $( this ),
16			caty = $( '.codevz-search-category' );
17
18		$this.addClass( 'codevz-active' );
19		caty.find( 'li' ).not( $this ).removeClass( 'codevz-active' );
20
21		caty.find( '> div' ).slideUp( 'fast' );
22
23		caty.find( '> strong span' ).html( $this.text() );
24
25		caty.find( '> input' ).val( $this.attr( 'data-cat' ) ).trigger( 'change' );
26
27	// Trending search.
28	}).on( 'click', '.codevz-search-trending a', function() {
29
30		$( '[name="s"]' ).val( $( this ).text() ).trigger( 'change' ).closest( 'form' ).submit();
31
32	// Header search input AJAX.
33	}).on( 'keyup', '.cz_ajax_search [name="s"]', function( e, time ) {
34
35	    var $this 	= $( this ),
36	        value   = $this.val(),
37	        form    = $this.parent(),
38	        results = form.next( '.ajax_search_results' ),
39	        icon 	= $( 'button i', form ),
40	        org 	= 'fa ' + icon.data('xtra-icon'),
41	        iLoader = 'fa fa-superpowers fa-pulse',
42	        trending= $( '.codevz-search-trending' );
43
44	    // Prevent duplicate requests for the same input
45	    if ( value === $this.data( 'codevz-prev-search' ) ) {
46	        return;
47	    }
48
49		// Save the last searched value
50		$this.data( 'codevz-prev-search', value );
51
52		// Hide results if they are visible before sending new request
53		if ( results.is( ':visible' ) ) {
54		    results.stop(true, true).slideUp('fast');
55		}
56
57		// Check input length before sending request
58		if ( value.length < 3 ) {
59			overlay.fadeOut();
60		    icon.removeClass(iLoader).addClass(org);
61			trending.slideDown('fast');
62		    return;
63		} else {
64		    icon.removeClass(org).addClass(iLoader);
65		}
66
67		trending.slideUp('fast');
68
69	    // Clear the previous timeout to debounce
70	    clearTimeout(typingTimer);
71
72	    // Start a new timeout sending AJAX.
73	    typingTimer = setTimeout(function() {
74
75			var tempForm = form.clone();
76			tempForm.find('input[type="hidden"]').prop('disabled', false);
77
78	        $.ajax({
79	            type: "GET",
80	            url: body.data('ajax') || ajaxurl,
81	            dataType: 'html',
82	            data: "action=codevz_ajax_search&" + tempForm.serialize(),
83				success: function(data) {
84				    overlay.css( 'z-index', '99' ).fadeIn();
85				    trending.slideUp('fast');
86
87				    var $html = $( '<div>' + data + '</div>' );
88
89				    if ( value ) {
90				        var regex = new RegExp( '(' + value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') + ')', 'gi' );
91
92				        $html.find( 'h3 a' ).each( function() {
93				            var title = $( this ).html();
94				            $( this ).html( title.replace( regex, '<strong class="ajax_search_results_hightlight">$1</strong>' ) );
95				        });
96				    }
97
98				    results.html( $html.html() ).stop(true, true).slideDown('fast');
99				    icon.removeClass(iLoader).addClass(org);
100				},
101	            error: function(xhr, status, error) {
102					overlay.css( 'z-index', '99' ).fadeIn();
103					trending.slideUp('fast');
104	                results.html('<b class="ajax_search_error">' + error + '</b>').stop(true, true).slideDown('fast');
105	                icon.removeClass(iLoader).addClass(org);
106	                console.log(xhr, status, error);
107	            }
108	        });
109
110	    }, 1500 ); // Wait until user stops typing
111
112	// Search icon
113	}).on( 'click', '.search_with_icon', function( e ) {
114
115		e.stopPropagation();
116
117	}).on( 'click', '.search_with_icon [name="s"]', function() {
118
119		if ( $( this ).val() ) {
120
121			overlay.css( 'z-index', '99' ).fadeIn();
122
123			if ( $( '.ajax_search_results .item_small' ).length ) {
124				$( '.ajax_search_results' ).slideDown( 'fast' );
125			}
126
127		}
128
129	// Search dropdown.
130	}).on( 'click', '.search_style_icon_dropdown .xtra-search-icon', function() {
131
132		var x 		= $( this ),
133			outer 	= x.parent().find('.outer_search'),
134			row 	= x.closest('.row').parent();
135
136		if ( outer.is( ':visible' ) ) {
137			row.css( 'z-index', '' );
138			outer.fadeOut( 'fast' );
139			overlay.fadeOut();
140		} else {
141			row.css( 'z-index', '99' );
142			outer.fadeIn( 'fast' ).find('input').trigger( 'focus' );
143			overlay.css( 'z-index', '99' ).fadeIn();
144		}
145
146	// Auto x-position search in header.
147	}).on( 'click mouseenter', '.search_style_icon_dropdown', function() {
148
149		var x 			= $( this ),
150			iconX 		= x.find( '.xtra-search-icon' ),
151			iconWidth 	= iconX.outerWidth(),
152			dropdown  	= x.find( '.outer_search' );
153
154		if ( ( $( window ).width() / 2 ) > ( x.offset().left + 100 ) ) {
155
156			x.addClass( 'inview_right' );
157
158			var iconMl = parseFloat( iconX.css( 'marginLeft' ) );
159
160			if ( body.hasClass( 'rtl' ) ) {
161				dropdown.css( 'left', ( ( iconWidth / 2 ) - 38 + iconMl ) );
162			} else {
163				dropdown.css( 'left', -( ( iconWidth / 2 ) - 36 + iconMl ) );
164			}
165
166		} else {
167
168			dropdown.css( 'right', ( ( iconWidth / 2 ) - 36 + parseFloat( iconX.css( 'marginRight' ) ) ) );
169
170		}
171
172	// Search fullscreen.
173	}).on( 'click', '.search_style_icon_full .xtra-search-icon', function( e ) {
174
175		var x = $( this ),
176			o = $( '.inner_layout > .cz_overlay' ),
177			s = x.parent().find( '.outer_search' );
178
179		o.css( 'z-index', '99' ).fadeIn();
180		s.fadeIn( 'fast' ).find( 'input' ).trigger( 'focus' );
181
182		if ( $( '#wpadminbar' ).length ) {
183			s.css( 'marginTop', '32px' );
184		}
185
186		x.parent().find( '.xtra-close-icon' ).toggleClass( 'hide' ).off().on( 'click', function( e ) {
187			$( this ).addClass( 'hide' );
188			o.fadeOut();
189			s.fadeOut( 'fast' );
190		});
191
192	}).on( 'click', '.cz_overlay', function( e ) {
193
194		$( this ).css( 'z-index', '' ).fadeOut();
195
196	}).on( 'click', function( e ) {
197
198		if ( $( e.target ).closest( '.outer_search .search, .sub-menu, .cz_cart_items, .icon_mobile_offcanvas_menu, .xtra-fixed-mobile-nav' ).length ) {
199			return;
200		}
201
202		overlay.css( 'z-index', '' ).fadeOut();
203		body.find( '.page_header > div' ).css( 'z-index', '' );
204		body.find( '.ajax_search_results' ).fadeOut( 'fast' );
205		body.find( '.search_style_icon_dropdown, .search_style_icon_full' ).find( '.outer_search' ).fadeOut( 'fast' );
206		body.find( '.search_style_icon_full' ).find( '.xtra-close-icon' ).addClass( 'hide' );
207
208		$( '.codevz-search-category >
208 div' ).slideUp( 'fast' );
209
210	});
211
212});

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.