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 redirectUrl.query["sb-page"] = 1; 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 var itemsAdded = 0 107 $.each(data, function (itemIndex) { 108 if (data[itemIndex].Categories.length) { 109 $.each(data[itemIndex].Categories, function (categoryIndex, category) { 110 var itemWithCategory = JSON.parse(JSON.stringify(data[itemIndex])); 111 itemWithCategory['category'] = category; 112 dataWithCategories.splice(itemsAdded, 0, itemWithCategory); 113 itemsAdded++; 114 }); 115 dataWithCategories.splice(itemsAdded, 1); 116 } 117 }); 118 119 data = dataWithCategories; 120 } 121 122 async(data); 123 window.sbredirect[settings.BehaviorId] = data; 124 }); 125 } 126 }, 127 templates: { 128 suggestion: function (data) { 129 130 if (settings.UseAutocompleteWithCategories && data.category) { 131 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>'; 132 } else { 133 return '<div>' + data.Title + '</div>'; 134 } 135 } 136 }, 137 display: function (data) { 138 return data.Title; 139 }, 140 limit: settings.SuggestionCount * 2 141 }).on('typeahead:select typeahead:autocomplete', function (e, datum) { 142 $.each(window.sbredirect[settings.BehaviorId], function (index, item) { 143 if (item.Title == datum.Title) { 144 if (settings.UseAutocompleteWithCategories && datum.category) { 145 if (item.category.Title == datum.category.Title) { 146 if (item.Url == null || item.Url == '') { 147 searchRedirect(item.Title, item.category.Path); 148 return false; 149 } 150 window.location = item.Url; 151 } 152 } else if (item.Url) { 153 window.location = item.Url; 154 } else { 155 console.error('Could not find an URL for item with title ' + item.Title); 156 } 157 } 158 }) 159 }); 160 } 161 } 162 163 if (settings.IsLiveSearch == true) { 164 var liveTypingTimer; 165 var liveDoneTypingInterval = 300; 166 167 //on keyup, start the countdown
168 $searchInput.keyup(function () { 169 clearTimeout(liveTypingTimer); 170 if ($searchInput.val()) { 171 liveTypingTimer = setTimeout(liveDoneTyping, liveDoneTypingInterval); 172 } 173 }); 174 175 //user is "finished typing," do something 176 function liveDoneTyping() { 177 var liveRequest = dnnsf.getUrlParts(settings.RenderResultsApi); 178 liveRequest.query["behaviorId"] = settings.BehaviorId; 179 var requestData = { 180 SearchTerms: htmlEncode(inputSearchBox.val()), 181 FilerPortalId: $("#" + settings.ClientId).find('.portalFilter').val(), 182 Sorting: $("#" + settings.ClientId).find('.sb-dspl-sort-btn').attr('data-sort'), 183 PageSize: dnnsf.getUrlParts(window.location.href).query["sb-pagesize"] || '', 184 SortingFieldName: $("#" + settings.ClientId).find('.sb-dspl-sort-btn').attr('data-sort') 185 } 186 187 if (dnnsf.getUrlParts(window.location.href).query["sb-cat"] != '') { 188 requestData.Categories = [{ path: dnnsf.getUrlParts(window.location.href).query["sb-cat"] } || '']; 189 } 190 $.extend(liveRequest.query, dnnsf.parseQueryString(location.search)); 191 192 liveRequest.query["sb-page"] = 1; 193 194 $.post(liveRequest.getUrl(), 195 requestData, 196 function (reponse) { 197 $searchDiv.find('.sb-live-result').replaceWith(reponse); 198 var windowHref = dnnsf.getUrlParts(window.location.href); 199 var search = htmlEncode(inputSearchBox.val()); 200 201 if (!search) { 202 if (windowHref.query[settings.SearchParam]) 203 delete windowHref.query[settings.SearchParam]; 204 } 205 else 206 windowHref.query[settings.SearchParam] = search; 207 208 var sort = $("#" + settings.ClientId).find('.sb-dspl-sort-btn').attr('data-sort'); 209 if (!!sort) 210 windowHref.query["sb-sort"] = sort; 211 212 windowHref.query["sb-page"] = 1; 213 214 history.replaceState(null, null, windowHref.getUrl()); 215 }); 216 } 217 } 218 219 } 220})
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.