1$(document).ready(function () { 2 //window.addEventListener("popstate", navChange(), false); 3 window.onpopstate = () => setTimeout(navChange(), 0); 4 function navChange() { 5 resetFilters(); 6 searchBlogs(getPageNumber(), true, true, true); 7 }; 8 9 function getParameterByName(name) { 10 var url = window.location.href; 11 name = name.replace(/[\[\]]/g, '\\$&'); 12 var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'); 13 var results = regex.exec(url); 14 if (!results) return null; 15 if (!results[2]) return ''; 16 return decodeURIComponent(results[2].replace(/\+/g, ' ')); 17 }; 18 19 String.prototype.format = function () { 20 // store arguments in an array 21 var args = arguments; 22 // use replace to iterate over the string 23 // select the match and check if the related argument is present 24 // if yes, replace the match with the argument 25 return this.replace(/{([0-9]+)}/g, function (match, index) { 26 // check if the argument is present 27 return typeof args[index] == 'undefined' ? match : args[index]; 28 }); 29 }; 30 31 var pageSize = 10; 32 function bindElements() { 33 $("a.page").on("click", function (e) { 34 e.preventDefault(); 35 searchBlogs($(this).data("pagenumber"), true); 36 }); 37 38 $("a.filter-author").on("click", function (e) { 39 var author = $(this).data("author") 40 if (!author) { 41 e.preventDefault(); 42 return false; 43 } 44 if ($(this).attr("href").indexOf("#") >= 0) { 45 e.preventDefault(); 46 $("#author-select").val(author); 47 searchBlogs(1, true); 48 return false; 49 } 50 return true; 51 }); 52 } 53 54 function getDateValue(selector) { 55 var input = $(selector); 56 if (!input || !input.val()) return null; 57 58 var date = new Date(input.val()); 59 return date.toISOString(); 60 } 61 62 function getDateSubstring(dateString) { 63 return dateString.split('T')[0]; 64 } 65 66 function searchBlogs(page, shouldScroll, searchOnLoad, navChanged) { 67 var mobileBreakpoint = window.innerWidth <= 992; 68 69 if (searchOnLoad) { 70 var keyword = getParameterByName("keyword"); 71 var dateStart = getParameterByName("dateStart"); 72 var dateEnd = getParameterByName("dateEnd"); 73 var topic = getParameterByName("topic"); 74 var author = getParameterByName("author"); 75 var language = $("#hdn-language").val(); //getParameterByName("language"); 76 77 var subtopicsParam = getParameterByName("subtopics"); 78 if (subtopicsParam) { 79 var subtopicsDecoded = subtopicsParam.split(","); 80 var subtopics = subtopicsDecoded.map(encodeURIComponent); 81 } 82 } else { 83 var keyword = ""; 84 if (mobileBreakpoint) { 85 keyword = $("#blog-search-input-m").val(); 86 } else { 87 keyword = $("#blog-search-input").val(); 88 } 89 var dateStart = getDateValue("#date-input-start"); 90 var dateEnd = getDateValue("#date-input-end"); 91 var topic = $("#topic-select option:selected").val(); 92 var author = $("#author-select option:selected").val(); 93 var language = $("#hdn-language").val(); 94 var subtopics = []; 95 if (topic && topic !== "") { 96 // Only include subtopic filters if there are any excluded(unchecked) 97 var uncheckedSubgroupItems = $("div[data-group='" + topic + "'] input[type='checkbox']:not(:checked)"); 98 if (uncheckedSubgroupItems != null && uncheckedSubgroupItems.length > 0) { 99 var checkedSubgroupItems = $("div[data-group='" + topic + "'] input[type='checkbox']:checked"); 100 if (checkedSubgroupItems != null) { 101 $.each(checkedSubgroupItems, function (index, item) { 102 var subtopic = $(item).val() 103 subtopics.push(encodeURIComponent(subtopic)); 104 }); 105 } 106 } 107 } 108 } 109 110 var params = {}; 111 112 if (keyword && keyword != "") { 113 params.keyword = encodeURIComponent(keyword); 114 } 115 if (dateStart != null) { 116 params.dateStart = dateStart; 117 } 118 if (dateEnd != null) { 119 params.dateEnd = dateEnd; 120 } 121 if (topic && topic != "") { 122 params.topic = encodeURIComponent(topic); 123 } 124 if (author && author != "") { 125 params.author = encodeURIComponent(author); 126 } 127 if (subtopics && subtopics.length > 0) { 128 params.subtopics = subtopics; 129 } 130 131 var filterElement = $('#blog-edit-filters'); 132 var filtersCount = Object.keys(params).length; 133 if (filtersCount > 0) { 134 filterElement.html(blogDictionary.EditFiltersApplied.format(filtersCount)); 135 } else { 136 filterElement.html(blogDictionary.EditFilters); 137 } 138 139 if (language && language != "") { 140 params.language = language; 141 } 142 params.page = page; 143 params.pageSize = pageSize; 144 var apiUrl = (currentLangCode != "en" ? "/" + currentLangCode : "") + "/api/sitecore/Blogs/BlogsResult"; 145 $.ajax({
146 type: "POST", 147 url: apiUrl, 148 data: JSON.stringify(params), 149 contentType: "application/json; charset=utf-8", 150 success: function (response) { 151 if (response && response.length > 0) { 152 153 if (searchOnLoad && navChanged) { 154 setTimeout(function () { 155 if (mobileBreakpoint) { 156 $("#blog-search-input-m").val(keyword); 157 } else { 158 $("#blog-search-input").val(keyword); 159 } 160 if (params.dateStart != null) { 161 var dateStartValue = getDateSubstring(dateStart); 162 $("#date-input-start").val(dateStartValue); 163 } 164 if (params.dateEnd != null) { 165 var dateEndValue = getDateSubstring(dateEnd); 166 $("#date-input-end").val(dateEndValue); 167 } 168 169 $("#topic-select option[value='" + topic + "']").prop("selected", true); 170 $("div[data-group='" + topic + "']").addClass("is-active"); 171 $("#author-select option[value='" + author + "']").prop("selected", true); 172 173 if (topic || subtopicsDecoded) { 174 var selectedSubTopics = subtopicsDecoded; 175 $("div[data-group='" + topic + "'] input[type='checkbox']").each(function () { 176 if ((selectedSubTopics == undefined && topic) || (selectedSubTopics == null || (selectedSubTopics && selectedSubTopics.includes($(this).val())))) { 177 $(this).prop("checked", true); 178 } else { 179 $(this).prop("checked", false); 180 } 181 }); 182 } 183 184 }, 1); 185 } 186 187 if (shouldScroll) { 188 $("html, body").animate({ scrollTop: 500 }, 600); 189 } 190 $("#blog-search-results").html(response); 191 192 var searchParams = Object.keys(params).map(key => key + '=' + params[key]).join('&'); 193 var newRelativePathQuery = window.location.pathname + '?' + searchParams; 194 var newUrlPath = window.location.origin + newRelativePathQuery; 195 if (!searchOnLoad && (window.history.state == null || newUrlPath != window.history.state.urlPath)) { 196 window.history.pushState({ urlPath: newUrlPath, page: page, isHistory: true }, "", newRelativePathQuery); 197 } 198 199 bindElements(); 200 201 // Close mobile filters 202 var form = document.querySelector(".page-filters.is-active"); 203 if (form) { 204 form.classList.remove("is-active"); 205 } 206 } 207 } 208 }); 209 } 210 211 function resetFilters() { 212 $("#date-input-start").val(""); 213 $("#date-input-end").val(""); 214 $("#topic-select option:eq(0)").prop("selected", true) 215 $(".page-filters__item.is-active").removeClass("is-active").addClass("hidden"); 216 $("#author-select option:eq(0)").prop("selected", true) 217 } 218 219 $('#input-apply').click(function (e) { 220 e.preventDefault(); 221 searchBlogs(1, false); 222 }); 223 224 $('#input-reset').click(function (e) { 225 e.preventDefault(); 226 $("#blog-search-input").val(""); 227 $("#blog-search-input-m").val(""); 228 resetFilters(); 229 searchBlogs(1, false); 230 }); 231 232 $('#blog-submit').click(function (e) { 233 e.preventDefault(); 234 resetFilters(); 235 searchBlogs(1, false); 236 });
237 238 $("#blog-search-input").on('keyup', function (e) { 239 if (e.key === 'Enter' || e.keyCode === 13) { 240 resetFilters(); 241 searchBlogs(1, false); 242 } 243 }); 244 245 function getPageNumber() { 246 let pageNumber = getParameterByName("page"); 247 return pageNumber ? pageNumber : 1; 248 } 249 //searchBlogs(getPageNumber(), false, true, false); 250 bindElements(); 251});
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.