1(function ($) { 2 3 let localCache = { 4 data: {}, 5 remove: function (url) { 6 delete localCache.data[url]; 7 }, 8 exist: function (url) { 9 return localCache.data.hasOwnProperty(url) && localCache.data[url] !== null; 10 }, 11 get: function (url) { 12 return localCache.data[url]; 13 }, 14 set: function (url, cachedData, callback) { 15 localCache.remove(url); 16 localCache.data[url] = cachedData; 17 if ($.isFunction(callback)) callback(cachedData); 18 } 19 }; 20 21 function initSearchIcon() { 22 const $search = $(this); 23 const $wrapper = $search.parents('.thegem-template-header').length ? $search.parents('.thegem-template-header') : $search.parent(); 24 const $buttonSearch = $('.thegem-te-search__item', $search); 25 26 if ($buttonSearch.closest('.te-menu-item-fullscreen-search').length) { 27 28 const $fullscreenSearch = $('.thegem-fullscreen-search', $search); 29 const $fullscreenSearchInput = $('.thegem-fullscreen-searchform-input', $search); 30 const $fullscreenSearchResults = $fullscreenSearch.find('.sf-result'); 31 const $fullscreenSearchClose = $fullscreenSearch.find('.sf-close'); 32 33 $('#page').append($fullscreenSearch); 34 35 let ajax, ajaxActive = false; 36 37 const fullscreenSearchTop = () => { 38 let searchTop; 39 40 searchTop = $wrapper.offset().top + $wrapper.outerHeight() - $(window).scrollTop(); 41 $fullscreenSearch.css('top', searchTop); 42 }; 43 44 const ajaxSearch = (query) => { 45 46 const postTypes = $fullscreenSearch.data('post-types'), 47 postTypesPpp = $fullscreenSearch.data('post-types-ppp'), 48 resultTitle = $fullscreenSearch.data('result-title'), 49 showAllText = $fullscreenSearch.data('show-all'); 50 51 if (!$fullscreenSearchInput.hasClass('styled')) { 52 let styles = $fullscreenSearchInput.data('styles'); 53 styles.forEach(function (style) { 54 $('head').append('<link rel="stylesheet" type="text/css" href="' + style + '">'); 55 }); 56 $fullscreenSearchInput.addClass('styled'); 57 } 58 59 if (ajaxActive) { 60 ajax.abort(); 61 } else { 62 $fullscreenSearchResults.prepend('<div class="preloader-new"><div class="preloader-spin"></div></div>'); 63 } 64 65 ajax = $.ajax({ 66 type: 'post', 67 url: thegem_scripts_data.ajax_url, 68 data: { 69 action: 'thegem_ajax_search', 70 search: query, 71 post_types: postTypes, 72 post_types_ppp: postTypesPpp, 73 result_title: resultTitle, 74 show_all_text: showAllText, 75 }, 76 beforeSend: function () { 77 if (localCache.exist(query)) { 78 $fullscreenSearchResults.find('.preloader-new').remove(); 79 $fullscreenSearchResults.find('.result-sections').html(localCache.get(query)); 80 return false; 81 } else { 82 ajaxActive = true; 83 } 84 }, 85 success: function (response) { 86 ajaxActive = false; 87 $fullscreenSearchResults.find('.preloader-new').remove(); 88 $fullscreenSearchResults.find('.result-sections').html(response); 89 localCache.set(query, response); 90 } 91 }); 92 }; 93 94 $buttonSearch.on('click', 'a', function (e) { 95 e.preventDefault(); 96 fullscreenSearchTop(); 97 98 $buttonSearch.toggleClass('active'); 99 $fullscreenSearch.toggleClass('active'); 100 101 if (ajaxActive) { 102 ajax.abort(); 103 ajaxActive = false; 104 } 105 106 $fullscreenSearchInput.val(''); 107 108 if ($('#site-header').hasClass('fixed')) { 109 setTimeout(function () { 110 $fullscreenSearchInput.focus(); 111 }, 500); 112 } else { 113 if ($(window).scrollTop() == 0) { 114 $('html, body').stop().animate({ 115 scrollTop: 0 116 }, 500); 117 } 118 $fullscreenSearchInput.focus(); 119 } 120 121 $fullscreenSearchResults.find('.preloader-new').remove(); 122 $fullscreenSearchResults.find('.result-sections').html(''); 123 124 let scrollbarWidth = window.innerWidth - document.documentElement.clientWidth; 125 $('.header-background, .top-area, .block-content, #page-title').css('padding-right', scrollbarWidth); 126 127 $('body').toggleClass('fullscreen-search-opened'); 128 }); 129 130 if ($fullscreenSearch.hasClass('ajax-search')) { 131 132 $fullscreenSearchInput.on('keyup', function () { 133 let query = $(this).val(); 134 135 if (query.length > 2) { 136 ajaxSearch(query); 137 } else { 138 if (ajaxActive) { 139 ajax.abort(); 140 ajaxActive = false;
141 } 142 $fullscreenSearchResults.find('.preloader-new').remove(); 143 $fullscreenSearchResults.find('.result-sections').html(''); 144 } 145 return false; 146 }); 147 148 $('.top-search-item', $fullscreenSearch).on('click', function (e) { 149 e.preventDefault(); 150 let query = $(this).data('search'); 151 ajaxSearch(query); 152 $fullscreenSearchInput.val(query); 153 return false; 154 }); 155 } 156 157 $fullscreenSearchClose.on('click', function (e) { 158 e.preventDefault(); 159 $buttonSearch.removeClass('active'); 160 $fullscreenSearch.removeClass('active'); 161 $('.header-background, .top-area, .block-content, #page-title').css('padding-right', 0); 162 $('body').removeClass('fullscreen-search-opened'); 163 if (ajaxActive) { 164 ajax.abort(); 165 ajaxActive = false; 166 } 167 $fullscreenSearchInput.val(''); 168 $fullscreenSearchResults.find('.preloader-new').remove(); 169 $fullscreenSearchResults.find('.result-sections').html(''); 170 }); 171 172 $(document).keyup(function (e) { 173 if (e.key === "Escape") { 174 $fullscreenSearchClose.trigger('click'); 175 } 176 }); 177 178 } else { 179 180 const $miniSearch = $('.minisearch', $search); 181 $('.thegem-te-search-hide').css('display', ''); 182 183 if ($buttonSearch.offset().left - $('#page').offset().left + $miniSearch.outerWidth() > $('#page').width()) { 184 $miniSearch.addClass('invert'); 185 } 186 187 $buttonSearch.on('click', 'a', function (e) { 188 e.preventDefault(); 189 190 $buttonSearch.toggleClass('active'); 191 192 $('.sf-input', $buttonSearch).focus(); 193 }); 194 195 $(document).on('click', function (e) { 196 if (!$(e.target).parents('.thegem-te-search__item').length) { 197 $('.thegem-te-search__item').removeClass('active'); 198 } 199 }); 200 } 201 } 202 203 204 $.fn.initSearchIcons = function () { 205 $(this).each(initSearchIcon); 206 }; 207 208 $(function() { 209 $('.thegem-te-search').initSearchIcons(); 210 211 if (navigator.appVersion.indexOf("Win") != -1) { 212 $('body').addClass('platform-Windows'); 213 } 214 }); 215 216 217})(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.