1// FindAProperty namespace - encapsulate the KO map model, view, viewmodel 2(function (FindAProperty, $, undefined) 3{ 4 var findProperty = 5 { 6 itemsQuery: ko.observable(), 7 keycode13counter: ko.observable(0), 8 keywords: ko.observableArray(), 9 propertyInputStatus: ko.pureComputed(function () 10 { 11 return findProperty.propertySearchTerm().length > 0 ? "inputLabelContent populated" : "inputLabelContent"; 12 }), 13 propertySearchTerm: ko.observable(), 14 propertySearchTermClass: ko.pureComputed(function () { return !findProperty.StringIsNullOrEmpty(findProperty.propertySearchTerm()); }), 15 ClearValue: function () 16 { 17 findProperty.propertySearchTerm(""); 18 }, 19 DoAutoCompleteSearch: function () 20 { 21 $.ajax({ 22 type: "POST", 23 url: "/api/ResolveFindAPropertyTerm?term=" + encodeURIComponent(findProperty.propertySearchTerm().trim()), 24 dataType: "json" 25 }) 26 .done(function (data, textStatus, jqXHR) 27 { 28 if (data.status === "success") 29 { 30 window.location.href = data.redirectUrl; 31 } 32 else 33 { 34 window.location.href = "/properties"; 35 } 36 }) 37 .fail(function (jqXHR, textStatus, errorThrown) 38 { 39 console.log("Search term: " + propertySearchTerm() + "\n" + errorThrown); 40 }) 41 .always(function (data, textStatus, jqXHR) 42 { 43 findProperty.ClearValue(); 44 }); 45 }, 46 Init: function () 47 { 48 $.ajax({
49 type: "POST", 50 url: "/api/GetAutocompleteKeywords", 51 dataType: "json" 52 }) 53 .done(function (response) 54 { 55 if (response.length > 0) 56 { 57 findProperty.keywords(response); 58 } 59 }); 60 }, 61 PropertySearchTermAction: function (data, event) 62 { 63 var eventSource = $("#propertySearchHeaderContainer .knockout-autocomplete").attr("data-selector"); 64 65 if (event.keyCode !== undefined) 66 { 67 event.preventDefault(); 68 69 if (event.keyCode === keys.enter) 70 { 71 findProperty.propertySearchTerm(findProperty.itemsQuery()); 72 73 if (findProperty.keywords.indexOf(findProperty.itemsQuery()) === -1 || (findProperty.keycode13counter() > 0 && eventSource === "keyboard") || ((eventSource === "mouseclick" || eventSource === "touch") && findProperty.keywords.indexOf(findProperty.itemsQuery()) >= 0)) 74 { 75 findProperty.DoAutoCompleteSearch(); 76 } 77 78 findProperty.keycode13counter(findProperty.keycode13counter() + 1); 79 } 80 else 81 { 82 if (findProperty.keywords.indexOf(findProperty.itemsQuery()) === -1) 83 { 84 findProperty.keycode13counter(0); 85 } 86 } 87 } 88 }, 89 PropertySearchTermActionButtonClick: function (data, event) 90 { 91 if (findProperty.StringIsNullOrEmpty(findProperty.propertySearchTerm())) 92 { 93 window.location.href = "/properties"; 94 } 95 else 96 { 97 findProperty.DoAutoCompleteSearch(); 98 } 99 }, 100 RenderSelectedItem: function (item) 101 { 102 return item.trim(); 103 }, 104 StringIsNullOrEmpty: function (val) 105 { 106 return (val === null || val === undefined || !/[A-Za-z0-9:,\.]+/.test(val)); 107 }, 108 TimeStampEvent: function (evt) 109 { 110 // used for debugging 111 var now = new Date(); 112 console.info(evt + ": " + now.toLocaleTimeString("en-US", { seconds: "numeric" }) + " - " + now.getMilliseconds() + "ms"); 113 } 114 }; 115 116 var keys = { 117 escape: 27, 118 up: 38, 119 down: 40, 120 pageUp: 33, 121 pageDown: 34, 122 enter: 13, 123 tab: 9, 124 shift: 16 125 }; 126 127 var scopeElt = document.getElementById("propertySearchHeaderContainer"); 128 129 if (scopeElt) 130 { 131 ko.applyBindings(findProperty, scopeElt); 132 findProperty.Init(); 133 } 134 135}(window.FindAProperty = window.FindAProperty || {}, 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.