1var shouldKeepChecking = true, 2 isLoadingPage = false; 3 4var views = { 5 formsInit: function () { 6 $('form:not(.ignore)').each(function () { 7 $(this).validate({ 8 submitHandler: function (form) { 9 event.stopPropagation(); 10 var $form = $(form) 11 var method = $form.attr('name'), 12 formName = $form.attr('data-name'), 13 relatedContentNodeId = $(form).attr('data-relatedContentNodeId'); 14 15 var grecaptcha = window.grecaptcha; 16 17 var recapchaResponse = $form.find('.g-recaptcha-response').val(); 18 19 if (recapchaResponse !== 'undefined') { 20 if (recapchaResponse != "") { 21 $('p.g-recaptcha-error strong').text(''); 22 } 23 else { 24 $('p.g-recaptcha-error strong').text('Verification failed, please try again'); 25 grecaptcha.reset(); 26 return; 27 } 28 } 29 30 $form.addClass('loading'); 31 $('.error-msg').remove(); 32 33 models.submission(method, $(form).serialize(), formName, relatedContentNodeId).success(function (data) { 34 //console.log(data); 35 controllers.getSubmission(data); 36 }); 37 return false; 38 } 39 }); 40 }); 41 //$('form:not(.ignore)').submit(function (event) { 42 43 // return false; 44 //}); 45 }, 46 searchInit: function () { 47 $('.grid-view').each(function () { 48 var $this = $(this); 49 var pageSize = parseInt($this.attr('data-pageSize')); 50 var results = parseInt($this.find(".jTotalResults").attr('data-results')); 51 if (results <= pageSize) { 52 $this.find('#IndexChecker').hide(); 53 } 54 if (results == 0 && !$this.hasClass('show-if-empty')) { 55 $this.hide(); 56 $this.next().css("margin-top", "20px") 57 if ($('.search-error').length) { 58 $('.search-error').show(); 59 } 60 } 61 }); 62 isLoadingPage = false; 63 $("#checkboxes label").on('click touch', function (event) { 64 event.stopPropagation(); 65 var grid = $('.grid-view'); 66 var filters = ""; 67 var $checkbox = $(this).parent().find("input[type='checkbox']"); 68 if (grid.attr('data-filter').length) { 69 var filters = grid.attr('data-filter'); 70 if ($checkbox.is(":checked")) { 71 if (filters.indexOf(',' + $checkbox.val()) != -1) { 72 filters = filters.replace(',' + $checkbox.val(), ""); 73 } 74 else { 75 filters = filters.replace($checkbox.val(), ""); 76 } 77 } 78 else { 79 filters += ',' + $checkbox.val(); 80 } 81 } 82 else { 83 filters += $checkbox.val(); 84 } 85 grid.attr('data-filter', filters); 86 controllers.dataProcessor(0, true, null); 87 }); 88 $(".jTabFilter a").on("click touch", function (event) { 89 event.preventDefault(); 90 var gridId = $(this).closest(".jTabFilter").attr("data-gridId"); 91 var grid = $('#' + gridId); 92 var filters = $(this).attr('data-id'); 93 $('.grid-view').attr('data-filter', filters); 94 controllers.dataProcessor(0, true, null, grid); 95 }); 96 if ($('.jSearch').length > 0) { 97 $('.jSearch').on("click touch", function (event) { 98 event.preventDefault(); 99 event.stopPropagation(); 100 101 var r = $(this).closest(".regional"); 102 if (r.hasClass("open")) { 103 $("#q").blur(); 104 r.removeClass("open"); 105 r.find(".search-close").hide(); 106 } 107 else { 108 r.addClass("open"); 109 r.find(".search-close").show(); 110 setTimeout(function () { 111 r.find("#q").focus(); 112 }, 500); 113 $('.search-close').on("click touch", function () { 114 r.removeClass("open"); 115 $(this).hide(); 116 }); 117 } 118 }); 119 } 120 $('.filters select').change(function () { 121 var grid = $('.grid-view'); 122 grid.attr('data-sort', $(this).val()); 123 controllers.dataProcessor(0, true, null); 124 }); 125 if ($('.grid').length > 0) { 126 for (i = 0; i < $('.grid').length; i++) { 127 128 if ($('.grid:eq(' + i + ')').hasClass('nc-grid')) { 129 new AnimOnScroll($('.grid:eq(' + i + ')')[0], { 130 minDuration: 0.4, 131 maxDuration: 0.7, 132 viewportFactor: 0.2 133 }); 134 } 135 else { 136 let gridEl = document.getElementById('grid'); 137 138 if (gridEl !== null) { 139 if (i == 0) { 140 new AnimOnScroll(document.getElementById('grid'), { 141 minDuration: 0.4, 142 maxDuration: 0.7, 143 viewportFactor: 0.2 144 }); 145 } 146 else { 147 new AnimOnScroll(document.getElementById('grid' + i), { 148 minDuration: 0.4, 149 maxDuration: 0.7, 150 viewportFactor: 0.2 151 }); 152 } 153 } 154 } 155 } 156 } 157 } 158}, 159 controllers = { 160 button: null,
161 startNextLoad: function (button) { 162 event.preventDefault(); 163 164 var _this = this; 165 _this.button = $(button); 166 167 if (_this.button.hasClass('wait')) 168 return; 169 else 170 _this.button.addClass('wait'); 171 172 var grid = _this.button.closest(".grid-view"); 173 var currentPage = parseInt(_this.button.attr('data-pageidx')), 174 nextPage = currentPage += 1; 175 var urlParams = new URLSearchParams(window.location.search); 176 177 $("#SearchTerm").val(urlParams.get('q')); 178 179 if (!isLoadingPage) { 180 isLoadingPage = true; 181 controllers.dataProcessor(nextPage, false, null, grid); 182 } 183 }, 184 dataProcessor: function (newPageIdx, replace, $form, grid, callback) { 185 if (grid == null) { 186 $('.grid-view').not('.ignore-dataprocessing').each(function () { 187 controllers.singleGridProcessor(newPageIdx, replace, $form, $(this), callback); 188 }); 189 } 190 else { 191 controllers.singleGridProcessor(newPageIdx, replace, $form, grid, callback); 192 } 193 if ($('.scroll-too').length && $form != null) { 194 var aTag = $("a[name='first-block']"); 195 $('html,body').animate({ scrollTop: (aTag.offset().top - 100) }, 'slow'); 196 } 197 }, 198 singleGridProcessor: function (newPageIdx, replace, $form, grid, callback) { 199 200 var _this = this; 201 202 const urlParams = new URLSearchParams(window.location.search); 203 const term = urlParams.get('q'); 204 var searchTerm = $("#SearchTerm"); 205 var searchTermVal = searchTerm.val(); 206 207 if (searchTerm.length && (searchTermVal != null && searchTermVal != "") && term != null) { 208 var newUrl = window.location.pathname + '?q=' + searchTermVal; 209 //window.location.replace(newUrl); 210 if (history.pushState) { 211 history.pushState('', '', newUrl); 212 } 213 } 214 215 var postData = "filter=" + grid.attr('data-filter'); 216 postData += "&colSize=" + grid.attr('data-col'); 217 postData += "&pageIdx=" + newPageIdx; 218 if (grid.attr('data-pageSize').length > 0) { 219 postData += "&pageSize=" + grid.attr('data-pageSize'); 220 } 221 if (grid.attr('data-sort').length > 0) { 222 postData += "&sort=" + grid.attr('data-sort'); 223 } 224 if (grid.attr('data-include') != null && grid.attr('data-include').length > 0) { 225 postData += "&includes=" + grid.attr('data-include'); 226 } 227 if (grid.attr('data-exclude') != null && grid.attr('data-exclude').length > 0) { 228 postData += "&excludes=" + grid.attr('data-exclude'); 229 } 230 if ($form != null && $form.q.value.length > 0) { 231 postData += "&term=" + $form.q.value; 232 } 233 else if (searchTerm.length && (searchTermVal != null && searchTermVal != "")) { 234 postData += "&term=" + searchTermVal; 235 } 236 if (grid.attr('data-tmpl') != null && grid.attr('data-tmpl').length > 0) { 237 postData += "&customResultsTemplate=" + grid.attr('data-tmpl'); 238 } 239 grid.find('#IndexChecker').attr('data-pageidx', newPageIdx); 240 models.searchPost(postData).success(function (data) { 241 242 if (_this.button) 243 _this.button.removeClass('wait'); 244 245 controllers.loadMoreArticles(data, replace, newPageIdx, grid); 246 var totalResults = 0; 247 if ($('.jNumReplace').length) { 248 $('.jNumReplace').each(function () { 249 var Results = $(this).closest(".grid-view").find(".jTotalResults").attr("data-results"); 250 totalResults += parseInt(Results); 251 $(this).html(Results); 252 }); 253 } 254 else { 255 totalResults = $(".jTotalResults").attr("data-results"); 256 } 257 $('.jTotalReplace').html(totalResults); 258 259 260 261 if (callback && $.isFunction(callback)) 262 callback.call(grid, ($form != null) ? $form.q.value : null, data); 263 }); 264 },
265 loadMoreArticles: function (data, replace, newPageIdx, grid) { 266 var $content = $(data); 267 var gridId = grid.find(".grid").attr('id'); 268 //console.log($content.filter('div.item').length); 269 grid.find('#IndexChecker').attr('data-pageidx', newPageIdx); 270 if ($content.filter('div.item').length) { 271 grid.show() 272 if (replace) { 273 grid.find('.grid').masonry('remove', grid.find('.grid').find('div.item')).html('').append($content).masonry('appended', $content.filter('div')).masonry('layout'); 274 } else { 275 if (grid.find('.grid').length) { 276 grid.find('.grid').append($content).masonry('appended', $content.filter('div')); 277 } 278 else { 279 280 var contentContainer = grid.find('#grid'); 281 282 if (contentContainer.length) 283 contentContainer.html($content); 284 else 285 grid.children('div:eq(0)').html($content); 286 } 287 // 288 } 289 var totalResults = parseInt(grid.find(".jTotalResults").attr('data-results')); 290 if ($content.filter('div.item').length == grid.attr('data-pageSize') || (newPageIdx == 0 && grid.find('.item').length < totalResults)) { 291 grid.find('#IndexChecker').show(); 292 } 293 else { 294 grid.find('#IndexChecker').hide(); 295 } 296 297 //if (typeof addthis === "object") { 298 // addthis.toolbox(grid.find('.grid')); 299 //} 300 301 if (gridId) { 302 //need to rewrite and/or fix this plugin! 303 new AnimOnScroll(document.getElementById(gridId), { 304 minDuration: 0.4, 305 maxDuration: 0.7, 306 viewportFactor: 0.2 307 }); 308 } 309 } else { 310 if (newPageIdx == 0) { 311 grid.find('.grid').masonry('remove', grid.find('.grid').find('div')); 312 grid.hide(); 313 grid.find(".jTotalResults").attr('data-results', 0); 314 } 315 shouldKeepChecking = false; 316 grid.find('#IndexChecker').hide(); 317 } 318 isLoadingPage = false; 319 }, 320 getSubmission: function (data) { 321 var form = $('.loading'); 322 //console.log('data', data) 323 if ((data.status && data.status == "Success") || data.indexOf("success") > -1) { 324 var t = form.attr('data-title'); 325 var msg = form.attr('data-msg'); 326 console.log(msg) 327 form.addClass('success').removeClass('loading'); 328 form.parent().append('<div class="col-xs-12 text-center pb30"><h3>' + t + '</h3><p>' + msg + '</p></div>'); 329 $('form input[type=text], form input[type=tel], form input[type=email], form textarea').each(function () { 330 $(this).val(''); 331 }); 332 $('form input[type=checkbox]').each(function () { 333 $(this).prop('checked', false); 334 $(this).parent().removeClass('active'); 335 }); 336 337 switch (form.attr('data-name')) { 338 case 'ContactForm': 339 ga('send', { hitType: 'event', eventCategory: 'Contact-Us', eventAction: 'Send', eventLabel: location.href, eventValue: 0 }); 340 break; 341 default: 342 } 343 344 } 345 else { 346 form.removeClass('loading'); 347 form.parent().append('<p class="error-msg">An error occurred. Please try again</p>'); 348 } 349 } 350 }, 351 models = { 352 submission: function (method, d, formName, relatedContentNodeId) { 353 354 console.log('/umbraco/api/formapi/' + method); 355 var sb = { content: d, name: formName }; 356 357 if (relatedContentNodeId) { 358 sb.relatedContentNodeId = relatedContentNodeId; 359 } 360 361 return $.ajax({
362 url: '/umbraco/api/formapi/' + method, 363 type: 'POST', 364 dataType: 'json', 365 processData: false, 366 data: JSON.stringify(sb), 367 contentType: "application/json", 368 error: function (xhr, textStatus, errorThrown) { 369 // 370 console.log("Error. textStatus: " +textStatus); 371 372 }, 373 success: function(xhr, textStatus) { 374 console.log("textStatus: " +textStatus); 375} 376 }); 377 }, 378 searchPost: function (postData) { 379 console.log("postdata: " + postData); 380 return $.ajax({ 381 url: '/umbraco/Surface/CmsDataSurface/ArticleFilterSearch', 382 type: 'GET', 383 processData: false, 384 data: postData, 385 error: function (xhr, textStatus, errorThrown) { 386 //do something sensible 387 console.log(xhr); 388 389 console.log('status'); 390 console.log(textStatus); 391 console.log(errorThrown); 392 } 393 }); 394 } 395 } 396 397views.searchInit(); 398views.formsInit();
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.