1// This function is obsolete and used for old xsl templates (default-obsolete-v3) 2function sbInitboxResults(clientId) { 3 var resultsRoot = $("#" + clientId), 4 url = window.location.href; 5 6 if (url.match(/&sb-sort=[^&]*/g)) { 7 var sortType = url.match(/&sb-sort=[^&]*/g)[0]; 8 resultsRoot.find(".sort-sb-results > .dropdown-toggle.btn:first-child").html("Sort by: " + sortType.substr(sortType.indexOf("=") + 1)).append("<span class='caret' style='margin-left: 5px;'></span>"); 9 resultsRoot.find('.sort-sb-results').attr('data-sort', sortType); 10 } 11 12 resultsRoot.find(".sort-sb-results > ul.dropdown-menu > li > a").click(function () { 13 $(this).parents().eq(2).find(".dropdown-toggle.btn:first-child").html("Sort by: " + $(this).text()).append("<span class='caret' style='margin-left: 5px;'></span>"); 14 location.href = url.replace(/&sb-sort=[^&]*/, '') + '&sb-sort=' + $(this).attr('value'); 15 }); 16} 17 18window.sbredirect = {}; 19dnnsf.api = dnnsf.api || {}; 20dnnsf.api.searchboost = dnnsf.api.searchboost || {}; 21dnnsf.api.searchboost = $.extend(dnnsf.api.searchboost, { 22 initInputBox: function (settings) { 23 var $searchDiv = $("#" + settings.ClientId); 24 var selBox = 'input.search-box, input.sb-search-box, input.searchBox, input.sb-searchbox'; 25 var $searchInput = $searchDiv.find(selBox); 26 var $searchButton = $searchDiv.find('button.search-btn'); 27 28 var inputSearchBox = $("#" + settings.ClientId).find(selBox); 29 if (settings.PreventNormalSearchForAutocompleteWithSearchResults == false || settings.UseAutocompleteWithSearchResults == false) { 30 $searchInput.keydown(function (event) { 31 if (event.keyCode == 13) { 32 searchRedirect(htmlEncode($(inputSearchBox['1']).val() || $(inputSearchBox['0']).val())); 33 return false; 34 } 35 }); 36 $searchButton.click(function (event) { 37 searchRedirect(htmlEncode($(inputSearchBox['1']).val() || $(inputSearchBox['0']).val())); 38 return false; 39 }) 40 } 41 42 function htmlEncode(value) { 43 //create a in-memory div, set it's inner text(which jQuery automatically encodes) 44 //then grab the encoded contents back out. The div never exists on the page. 45 return $('<div/>').text(value).html(); 46 } 47 48 function searchRedirect(term, category) { 49 if (!term) 50 return false; 51 if (settings.IsLiveSearch != true) { 52 var redirectUrl = dnnsf.getUrlParts(settings.FwdToSearchResultsPageApi); 53 redirectUrl.query["terms"] = term; 54 if ($("#" + settings.ClientId).find('.portalFilter').length > 0) 55 redirectUrl.query["portalFilterId"] = $("#" + settings.ClientId).find('.portalFilter').val(); 56 redirectUrl.query["behaviorId"] = settings.BehaviorId; 57 redirectUrl.query["facets"] = category || dnnsf.getUrlParts(window.location.href).query["sb-cat"] || ''; 58 59 location.href = redirectUrl.getUrl(); 60 } 61 } 62 63 if (settings.SuggestionCount != 0 && !settings.IsLiveSearch == true) { 64 var typingTimer; 65 var doneTypingInterval = 300; 66 if (settings.UseAutocompleteWithSearchResults == false) { 67 $searchInput.typeahead( 68 { 69 hint: true, 70 highlight: true, 71 minLength: 1 72 }, { 73 name: 'searchTerms', 74 source: function (query, sync, async) { 75 clearTimeout(typingTimer); 76 if (htmlEncode($(inputSearchBox['1']).val() || $(inputSearchBox['0']).val())) { 77 typingTimer = setTimeout(doneTyping, doneTypingInterval); 78 } 79 function doneTyping() { 80 $.post(settings.SuggestionsApi + '?behaviorId=' + settings.BehaviorId + '&terms=' + htmlEncode($(inputSearchBox['1']).val() || $(inputSearchBox['0']).val()), function (data) { 81 async(data); 82 }); 83 } 84 }, 85 limit: settings.SuggestionCount * 2 86 }); 87 } 88 else { 89 $searchInput.typeahead( 90 { 91 hint: true, 92 highlight: true, 93 minLength: 1 94 }, { 95 name: 'searchTerms', 96 source: function (query, sync, async) { 97 clearTimeout(typingTimer); 98 if (htmlEncode($(inputSearchBox['1']).val() || $(inputSearchBox['0']).val())) { 99 typingTimer = setTimeout(doneTyping, doneTypingInterval); 100 } 101 function doneTyping() {
102 $.post(settings.SuggestionsApi + '?behaviorId=' + settings.BehaviorId + '&terms=' + htmlEncode($(inputSearchBox['1']).val() || $(inputSearchBox['0']).val()), function (data) { 103 if (settings.UseAutocompleteWithCategories && data.length) { 104 var dataWithCategories = JSON.parse(JSON.stringify(data)); 105 106 // only the most relevant search result(the first one) needs to have its categories shown in the search 107 if (data[0].Categories.length) { 108 $.each(data[0].Categories, function (categoryIndex, category) { 109 var itemWithCategory = JSON.parse(JSON.stringify(data[0])); 110 itemWithCategory['category'] = category; 111 dataWithCategories.splice(categoryIndex, 0, itemWithCategory); 112 }); 113 dataWithCategories.splice(data[0].Categories.length, 1); 114 } 115 data = dataWithCategories; 116 } 117 118 async(data); 119 window.sbredirect[settings.BehaviorId] = data; 120 }); 121 } 122 }, 123 templates: { 124 suggestion: function (data) { 125 126 if (settings.UseAutocompleteWithCategories && data.category) { 127 return '<div class="dnnsf-sb-suggestion"><span class="tt-data">' + data.Title + '</span> <span class="tt-category">' + (settings.CategoryText || 'in') + ' ' + data.category.Title + ' </span></div>'; 128 } else { 129 return '<div>' + data.Title + '</div>'; 130 } 131 } 132 }, 133 display: function(data) { 134 return data.Title; 135 }, 136 limit: settings.SuggestionCount * 2 137 }).on('typeahead:select typeahead:autocomplete', function (e, datum) { 138 $.each(window.sbredirect[settings.BehaviorId], function (index, item) { 139 if (item.Title == datum.Title) { 140 if (settings.UseAutocompleteWithCategories && datum.category) { 141 if (item.category.Title == datum.category.Title) { 142 searchRedirect(item.Title, item.category.Path); 143 return false; 144 } 145 } else if (item.Url) { 146 window.location = item.Url; 147 } else { 148 console.error('Could not find an URL for item with title ' + item.Title); 149 } 150 } 151 }) 152 }); 153 } 154 } 155 156 if (settings.IsLiveSearch == true) { 157 var liveTypingTimer; 158 var liveDoneTypingInterval = 300; 159 160 //on keyup, start the countdown 161 $searchInput.keyup(function () { 162 clearTimeout(liveTypingTimer); 163 if ($searchInput.val()) { 164 liveTypingTimer = setTimeout(liveDoneTyping, liveDoneTypingInterval); 165 } 166 }); 167 168 //user is "finished typing," do something 169 function liveDoneTyping() { 170 var liveRequest = dnnsf.getUrlParts(settings.RenderResultsApi); 171 liveRequest.query["behaviorId"] = settings.BehaviorId; 172 var requestData = { 173 SearchTerms: htmlEncode(inputSearchBox.val()), 174 FilerPortalId: $("#" + settings.ClientId).find('.portalFilter').val(), 175 Sorting: $("#" + settings.ClientId).find('.sb-dspl-sort-btn').attr('data-sort'), 176 PageSize: dnnsf.getUrlParts(window.location.href).query["sb-pagesize"] || '', 177 SortingFieldName: $("#" + settings.ClientId).find('.sb-dspl-sort-btn').attr('data-sort') 178 } 179 180 if (dnnsf.getUrlParts(window.location.href).query["sb-cat"] != '') { 181 requestData.Categories = [{ path: dnnsf.getUrlParts(window.location.href).query["sb-cat"] } || '']; 182 } 183 $.extend(liveRequest.query, dnnsf.parseQueryString(location.search)); 184 185 $.post(liveRequest.getUrl(), 186 requestData, 187 function (reponse) { 188 $searchDiv.find('.sb-live-result').replaceWith(reponse); 189 var windowHref = dnnsf.getUrlParts(window.location.href); 190 var search = htmlEncode(inputSearchBox.val()); 191 192 if (!search) { 193 if (windowHref.query[settings.SearchParam]) 194 delete windowHref.query[settings.SearchParam]; 195 } 196 else 197 windowHref.query[settings.SearchParam] = search; 198 199 var sort = $("#" + settings.ClientId).find('.sb-dspl-sort-btn').attr('data-sort'); 200 if (!!sort) 201 windowHref.query["sb-sort"] = sort; 202 203 history.replaceState(null, null, windowHref.getUrl()); 204 }); 205 } 206 } 207 208 } 209})
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.