1jQuery(function($) { 2 var param_post_type; 3 var param_cat; 4 var param_tag; 5 function getUrlParameter(name) { 6 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); 7 var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); 8 var results = regex.exec(location.search); 9 return results === null 10 ? '' 11 : decodeURIComponent(results[1].replace(/\+/g, ' ')); 12 } 13 $(window).on('load', function() { 14 param_post_type = getUrlParameter('post_types'); 15 param_cat = getUrlParameter('categories'); 16 param_tag = getUrlParameter('tags'); 17 $('form.search-form').each(function(i, v) { 18 var param_post_type = getUrlParameter('post_types'); 19 var param_cat = getUrlParameter('categories'); 20 var param_tag = getUrlParameter('tags'); 21 if ($(v).width() < 480) { 22 $(v).addClass('small'); 23 } else { 24 $(v).addClass('large'); 25 } 26 $(v).addClass('asc-active'); 27 28 $(v).css('position', 'relative'); 29 $(v).append( 30 `<input type="hidden" name="post_types" value="${param_post_type}" /> 31 <input type="hidden" name="categories" value="${param_cat}" /> 32 <input type="hidden" name="tags" value="${param_tag}" />` 33 ); 34 }); 35 36 $('.search-field').after( 37 '<i class="asc-settings dashicons dashicons-admin-generic"></i>' 38 ); 39 40 var query; 41 var input = ''; 42 43 if (1 == ajax_object.options.enable_post_filter) { 44 input += `<div class="acs-filter-container posttype">`; 45 input += `<p>Filter by Post Type</p><ul>`; 46 postType = param_post_type.split(','); 47 48 var i = 0; 49 $.each(ajax_object.post_type, function(index, value) { 50 var checked = ''; 51 52 if ($.inArray(value, postType) > -1) { 53 checked = 'checked'; 54 } 55 input += ` 56 <li> 57 <input class="acs-filter-posttype filter" input name="post_type" type="checkbox" value="${value}" ${checked} /> ${value 58 .charAt(0) 59 .toUpperCase()}${value.slice(1)} 60 </li> 61 `; 62 i++; 63 }); 64 input += `</ul></div>`; 65 } 66 67 if (1 == ajax_object.options.enable_category_filter) { 68 input += '<div class="acs-filter-container category">'; 69 input += '<p>Filter by Categories</p><ul>'; 70 categories = param_cat.split(','); 71 var i = 0; 72 $.each(ajax_object.categories, function(index, value) { 73 var checked = ''; 74 75 if ($.inArray(value.term_id.toString(), categories) > -1) { 76 checked = 'checked'; 77 } 78 input += ` 79 <li> 80 <input class="acs-filter-category filter" input name="category" type="checkbox" value="${value.term_id}" ${checked} /> ${value.name} 81 </li> 82 `; 83 i++; 84 }); 85 input += '</ul></div>'; 86 } 87 88 if (1 == ajax_object.options.enable_tags_filter) { 89 input += `<div class="acs-filter-container tags">`; 90 input += `<p>Filter by Tags</p><ul>`; 91 tags = param_tag.split(','); 92 var i = 0; 93 $.each(ajax_object.tags, function(index, value) { 94 var checked = ''; 95 if ($.inArray(value.term_id.toString(), tags) > -1) { 96 checked = 'checked'; 97 } 98 input += ` 99 <li> 100 <input class="acs-filter-tags filter" input name="tag" type="checkbox" value=" 101 ${value.term_id}" ${checked} /> ${value.name} 102 </li> 103 `; 104 i++; 105 }); 106 input += `</ul></div>`; 107 } 108 109 $('.search-field') 110 .parents('form') 111 .after( 112 `<div id="ajax-autosearch" class="acs-container" style="display: none;"><form>${input}</form></div>` 113 ); 114 }); 115 $('.search-field').on('keyup focus', function() { 116 var $this = $(this); 117 query = $(this).val(); 118 var post_type = []; 119 var category = []; 120 var tag = []; 121 122 $.each($("input[name='post_type']:checked"), function() { 123 post_type.push($(this).val()); 124 }); 125 126 $.each($("input[name='category']:checked"), function() { 127 category.push($(this).val()); 128 }); 129 130 $.each($("input[name='tag']:checked"), function() { 131 tag.push($(this).val()); 132 }); 133 134 if ('' == query) { 135 $this 136 .parents('form') 137 .siblings('.asc-container') 138 .remove(); 139 $('#ajax-autosearch').hide(); 140 return false; 141 } else { 142 if ($('#ajax-autosearch').length == 0) { 143 } else { 144 //$('#autocomplete-search').show(); 145 } 146 } 147 148 var data = { 149 action: 'search', 150 query: query, 151 post_type: post_type, 152 category: category, 153 tag: tag 154 }; 155 156 // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php 157 jQuery.post(ajax_object.ajax_url, data, function(response) { 158 $this 159 .parents('form') 160 .siblings('.asc-container') 161 .remove(); 162 var $form = $this.parents('form'); 163 if ('' != query) { 164 var result; 165 result = render_results($form, ajax_object, response); 166 $this.parents('form').after(result); 167 if (0 == $('#autocomplete-close').length) 168 $this.after( 169 `<i id="autocomplete-close" class="dashicons dashicons-no"></i>` 170 ); 171 } else { 172 $this 173 .parents('form') 174 .siblings('.asc-container') 175 .remove(); 176 } 177 }); 178 }); 179 180 function render_results($form, ajax_object, response) { 181 var width = $form.width(); 182 var $offsetTop = $form.offset().top; 183 var $documentHeight = $(document).height(); 184 var $diff = $documentHeight - $offsetTop; 185 var style = '';
186 var container_class = ajax_object.options.layout; 187 if ('grid-layout' == ajax_object.options.layout) { 188 container_class = `${ajax_object.options.layout} ${ajax_object.options.column}`; 189 } 190 191 if ('0' == ajax_object.options.show_featured_image) { 192 container_class += ' aas-image-off'; 193 } 194 195 $form.siblings('.acs-container').css('top', '-180'); 196 style += `width: ${width}px;`; 197 if ($diff < 250) { 198 style += `top: -250px;`; 199 } 200 201 if ('' == response) { 202 result = ` 203 <div class="asc-container ${container_class}" style="${style}"> 204 <div id="autocomplete-search-results" class="ajax-autosearch-results"> 205 ${ajax_object.no_result_found} 206 </div> 207 </div> 208 `; 209 } else { 210 var button = ` 211 <a class="asc-submit-button" href="#"> 212 ${ajax_object.more_button} 213 </a> 214 `; 215 result = ` 216 <div class="asc-container ${container_class}" style="${style}"> 217 <div id="autocomplete-search-results" class="ajax-autosearch-results"> 218 ${response} 219 ${button} 220 </div> 221 </div> 222 `; 223 } 224 return result; 225 } 226 227 $('body').on('click', '#autocomplete-close', function(e) { 228 if ('autocomplete-close' == e.target.id) { 229 $this = $('#' + e.target.id); 230 $this 231 .parents('form.search-form') 232 .parents('section') 233 .find('div#ajax-autosearch') 234 .hide(); 235 $this 236 .parents('form.search-form') 237 .siblings('.asc-container') 238 .remove(); 239 $this.prev('.search-field').val(''); 240 $this.remove(); 241 flag = false; 242 } 243 }); 244 245 $('body').on('change', '.filter', function(e) { 246 var $this = $(this); 247 var post_type = []; 248 var category = []; 249 var tag = []; 250 251 $.each($("input[name='post_type']:checked"), function() { 252 post_type.push($(this).val()); 253 }); 254 255 $.each($("input[name='category']:checked"), function() { 256 category.push(parseInt($(this).val())); 257 }); 258 259 $.each($("input[name='tag']:checked"), function() { 260 tag.push(parseInt($(this).val())); 261 }); 262 263 if ('' == query) { 264 $this 265 .parents('form') 266 .siblings('.asc-container') 267 .remove(); 268 $('#ajax-autosearch').hide(); 269 return false; 270 } else { 271 if ($('#ajax-autosearch').length == 0) { 272 } else { 273 //$('#autocomplete-search').show(); 274 } 275 } 276 277 var data = { 278 action: 'search', 279 query: query, 280 post_type: post_type, 281 category: category, 282 tag: tag 283 }; 284 $this = $(e.target) 285 .parents('#ajax-autosearch') 286 .siblings('form.search-form'); 287 288 $this.find("input[name='post_types']").val(post_type); 289 $this.find("input[name='categories']").val(category); 290 $this.find("input[name='tags']").val(tag); 291 292 // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php 293 jQuery.post(ajax_object.ajax_url, data, function(response) { 294 $this.siblings('.asc-container').remove(); 295 var result; 296 result = render_results($this, ajax_object, response); 297 $this.after(result); 298 if (0 == $('#autocomplete-close').length) { 299 $this 300 .children('input.search-field') 301 .after( 302 `<i id="autocomplete-close" class="dashicons dashicons-no"></i>` 303 ); 304 } 305 }); 306 }); 307 308 $('body').on('click', '.asc-settings', function() { 309 var $form = $(this).parents('form.search-form'); 310 var $offsetTop = $form.offset().top; 311 var $documentHeight = $(document).height(); 312 var $diff = $documentHeight - $offsetTop; 313 if ($diff < 250) { 314 $form.siblings('.acs-container').css('top', '-140px'); 315 } 316 var width = $(this) 317 .parents('form.search-form') 318 .width(); 319 $form.siblings('.acs-container').css('width', width); 320 321 $(this) 322 .parents('form.search-form') 323 .siblings('.acs-container') 324 .toggle(); 325 }); 326 327 var params_array = []; 328 $('body').on('click', '.asc-submit-button', function(e) { 329 e.preventDefault(); 330 $(e.target) 331 .parents('.asc-container') 332 .siblings('form.search-form') 333 .find(':input') 334 .each(function(i, v) { 335 var input_class = $(v).attr('class'); 336 337 if ('search-field' == input_class) { 338 params_array.push($(v).val()); 339 } else if ('ajax-autosearch-filter-input' == input_class) { 340 if ('' != $(v).val()) { 341 params_array.push($(v).attr('name') + '=' + $(v).val()); 342 } 343 } 344 }); 345 window.location.href = ajax_object.home_url + params_array.join('&'); 346 }); 347 348 $('form.search-form').on('submit', function(e) { 349 var $post_type_input = $(this).find('input[name="post_types"]'); 350 var $cat_input = $(this).find('input[name="categories"]'); 351 var $tag_input = $(this).find('input[name="tags"]'); 352 353 if ('' === $post_type_input.val()) { 354 $post_type_input.remove(); 355 } 356 if ('' === $cat_input.val()) { 357 $cat_input.remove(); 358 } 359 if ('' === $tag_input.val()) { 360 $tag_input.remove(); 361 } 362 }); 363});
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.