1(function ($) { 2 $(document).ready(function () { 3 var searchBoxIdFields = $('[data-sf-role="searchTextBoxId"]'); 4 5 for (var i = 0; i < searchBoxIdFields.length; i++) { 6 var searchBoxIdField = $(searchBoxIdFields[i]); 7 var controlServerData = { 8 resultsUrl: searchBoxIdField.siblings('[data-sf-role="resultsUrl"]').first().val(), 9 indexCatalogue: searchBoxIdField.siblings('[data-sf-role="indexCatalogue"]').first().val(), 10 wordsMode: searchBoxIdField.siblings('[data-sf-role="wordsMode"]').first().val(), 11 disableSuggestions: $.parseJSON(searchBoxIdField.siblings('[data-sf-role="disableSuggestions"]').first().val()), 12 minSuggestionLength: searchBoxIdField.siblings('[data-sf-role="minSuggestionLength"]').first().val(), 13 suggestionFields: searchBoxIdField.siblings('[data-sf-role="suggestionFields"]').first().val(), 14 language: searchBoxIdField.siblings('[data-sf-role="language"]').first().val(), 15 siteId: searchBoxIdField.siblings('[data-sf-role="siteId"]').first().val(), 16 suggestionsRoute: searchBoxIdField.siblings('[data-sf-role="suggestionsRoute"]').first().val(), 17 searchTextBoxSelector: searchBoxIdField.val(), 18 searchButtonSelector: searchBoxIdField.siblings('[data-sf-role="searchButtonId"]').first().val(), 19 searchProcessing: searchBoxIdField.siblings('[data-sf-role="searchProcessing"]').first().val() 20 }; 21 featherSearchBoxWidget(controlServerData); 22 } 23 24 function featherSearchBoxWidget(serverData) { 25 var searchTextBox = $(serverData.searchTextBoxSelector), 26 searchButton = $(serverData.searchButtonSelector), 27 suggestionType = ['category-search', 'matched-content']; 28 searchButton.click(navigateToResults); 29 searchTextBox.keypress(keypressHandler); 30 31 var searchProcessing = serverData.searchProcessing; 32 /* Initialization */ 33 if (!serverData.disableSuggestions) { 34 searchTextBox.keyup(keyupHandler); 35 36 try { 37 searchTextBox.autocomplete({ 38 autoFocus: false, 39 delay: 300, 40 minLength: 3, 41 source: function (request, response) { 42 $.ajax({
43 type: "GET", 44 url: serverData.suggestionsRoute, 45 dataType: 'json', 46 data: { Text: request.term }, 47 success: function (data) { 48 response(data.Suggestions); 49 } 50 }); 51 }, 52 messages: 53 { 54 noResults: '', 55 results: function () { } 56 }, 57 select: function (event, ui) { 58 if (ui.item !== undefined) { 59 if (ui.item.SuggestionType === 0) { 60 event.preventDefault(); 61 // category search 62 sendSentence(); 63 var data = { "Term": ui.item.Link, "CategorySearch": true, "ContentTypeValue": "", "OrFacets": true, "ExcludeQuestions": true }; 64 clearQuery = false; // initialized in contensearchresults/index.js 65 window.setTimeout(function () { 66 $.post("/submit-query", data, function (data, textStatus) { 67 if (data.queryReceived === "true") { 68 window.location = getLocation(); 69 } 70 }); 71 }, 3); 72 searchTextBox.val(ui.item.Title); 73 } 74 else { 75 document.location.href = ui.item.Link; 76 } 77 } 78 }, 79 }).autocomplete("instance")._renderMenu = function (ul, items) { 80 var that = this; 81 $.each(items, function (index, item) { 82 var li; 83 li = that._renderItemData(ul, item); 84 if (item.SuggestionType) { 85 li.attr("aria-label", suggestionType[item.SuggestionType] + " : " + item.Title); 86 } 87 }); 88 }; 89 90 searchTextBox.autocomplete("instance")._renderItem = function (ul, item) { 91 return $("<li>") 92 .addClass("search-suggestion") 93 .addClass("suggestion-type-" + suggestionType[item.SuggestionType]) 94 .attr("aria-label", item.Title) 95 .attr("data-type", suggestionType[item.SuggestionType]) 96 .attr("data-url", item.Link) 97 .append($("<span>")) 98 .append($("<p>").text(item.Title)) 99 .appendTo(ul); 100 }; 101 102 searchTextBox.autocomplete("widget").addClass("sf-autocomplete"); 103 104 } catch (e) { 105 // Fixes jQuery bug, causing IE7 to throw error "script3 member not found". 106 // The try/catch can be removed when the bug is fixed. 107 } 108 } 109 110 /* Event handlers */ 111 function keypressHandler(e) { 112 if (!e) 113 e = window.event; 114 115 var keyCode = null; 116 if (e.keyCode) { 117 keyCode = e.keyCode; 118 } 119 else { 120 keyCode = e.charCode; 121 } 122 123 if (keyCode === 13) { 124 navigateToResults(e); 125 } 126 } 127 128 function keyupHandler(e) { 129 if (e.keyCode !== 38 && // up arrow 130 e.keyCode !== 40 && // down arrow 131 e.keyCode !==27) { // esc 132 // When the auto complete menu is shown, only this event is detected 133 if (e.keyCode === 13) { 134 // when enter is pressed 135 navigateToResults(e); 136 } 137 } 138 } 139 140 /* Helper methods */ 141 function navigateToResults(e) { 142 if (!e) 143 e = window.event; 144 145 if (e.stopPropagation) { 146 e.stopPropagation(); 147 } 148 else { 149 e.cancelBubble = true; 150 } 151 if (e.preventDefault) { 152 e.preventDefault(); 153 } 154 else { 155 e.returnValue = false; 156 } 157 158 var query = searchTextBox.val(); 159 160 if (searchProcessing === "default") { 161 if (query && query.trim() && serverData.indexCatalogue) { 162 sendSentence(); 163 window.location = getLocation(); 164 } 165 } 166 else { 167 // customization. sends query term to contentsearchresults controller 168 // for storage, then loads results page 169 if (query && query.trim() && serverData.indexCatalogue) { 170 sendSentence(); 171 clearQuery = false; // initialized in contensearchresults/index.js 172 var data = { "Term": query, "CategorySearch": false, "ContentTypeValue": "", "OrFacets": true, "ExcludeQuestions": true }; 173 window.setTimeout(function () { 174 $.post("/submit-query", data, function (data, textStatus) { 175 if (data.queryReceived === "true") { 176 window.location = getLocation(); 177 } 178 }); 179 }, 3); 180 } 181 } 182 } 183 184 function getLocation() { 185 var query = searchTextBox.val().trim(); 186 187 var separator = (serverData.resultsUrl.indexOf("?") === -1) ? "?" : "&"; 188 189 var catalogueParam = separator + "indexCatalogue=" + encodeURIComponent(serverData.indexCatalogue), 190 searchQueryParam = "&searchQuery=" + encodeURIComponent(query); 191 192 var url = serverData.resultsUrl + catalogueParam + searchQueryParam; 193 194 return url; 195 } 196 197 function sendSentence() { 198 if (window.DataIntelligenceSubmitScript) { 199 DataIntelligenceSubmitScript._client.sentenceClient.writeSentence({ 200 predicate: "Search for", 201 object: searchTextBox.val(), 202 objectMetadata: [{ 203 'K': 'PageUrl', 204 'V': location.href 205 }] 206 }); 207 } 208 } 209 } 210 });
211}(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.