|
1013 | 1013 | 'returned': sortResults(results_returned, true),
|
1014 | 1014 | 'others': sortResults(results),
|
1015 | 1015 | };
|
1016 |
| - if (ALIASES[window.currentCrate][query.raw]) { |
| 1016 | + if (ALIASES && ALIASES[window.currentCrate] && |
| 1017 | + ALIASES[window.currentCrate][query.raw]) { |
1017 | 1018 | var aliases = ALIASES[window.currentCrate][query.raw];
|
1018 | 1019 | for (var i = 0; i < aliases.length; ++i) {
|
1019 | 1020 | ret['others'].unshift(aliases[i]);
|
|
1188 | 1189 | return '<span>' + path.replace(/::/g, '::</span><span>');
|
1189 | 1190 | }
|
1190 | 1191 |
|
| 1192 | + function buildHrefAndPath(item) { |
| 1193 | + var displayPath; |
| 1194 | + var href; |
| 1195 | + var type = itemTypes[item.ty]; |
| 1196 | + var name = item.name; |
| 1197 | + |
| 1198 | + if (type === 'mod') { |
| 1199 | + displayPath = item.path + '::'; |
| 1200 | + href = rootPath + item.path.replace(/::/g, '/') + '/' + |
| 1201 | + name + '/index.html'; |
| 1202 | + } else if (type === "primitive") { |
| 1203 | + displayPath = ""; |
| 1204 | + href = rootPath + item.path.replace(/::/g, '/') + |
| 1205 | + '/' + type + '.' + name + '.html'; |
| 1206 | + } else if (type === "externcrate") { |
| 1207 | + displayPath = ""; |
| 1208 | + href = rootPath + name + '/index.html'; |
| 1209 | + } else if (item.parent !== undefined) { |
| 1210 | + var myparent = item.parent; |
| 1211 | + var anchor = '#' + type + '.' + name; |
| 1212 | + var parentType = itemTypes[myparent.ty]; |
| 1213 | + if (parentType === "primitive") { |
| 1214 | + displayPath = myparent.name + '::'; |
| 1215 | + } else { |
| 1216 | + displayPath = item.path + '::' + myparent.name + '::'; |
| 1217 | + } |
| 1218 | + href = rootPath + item.path.replace(/::/g, '/') + |
| 1219 | + '/' + parentType + |
| 1220 | + '.' + myparent.name + |
| 1221 | + '.html' + anchor; |
| 1222 | + } else { |
| 1223 | + displayPath = item.path + '::'; |
| 1224 | + href = rootPath + item.path.replace(/::/g, '/') + |
| 1225 | + '/' + type + '.' + name + '.html'; |
| 1226 | + } |
| 1227 | + return [displayPath, href]; |
| 1228 | + } |
| 1229 | + |
1191 | 1230 | function addTab(array, query, display) {
|
1192 | 1231 | var extraStyle = '';
|
1193 | 1232 | if (display === false) {
|
|
1211 | 1250 | name = item.name;
|
1212 | 1251 | type = itemTypes[item.ty];
|
1213 | 1252 |
|
1214 |
| - if (type === 'mod') { |
1215 |
| - displayPath = item.path + '::'; |
1216 |
| - href = rootPath + item.path.replace(/::/g, '/') + '/' + |
1217 |
| - name + '/index.html'; |
1218 |
| - } else if (type === "primitive") { |
1219 |
| - displayPath = ""; |
1220 |
| - href = rootPath + item.path.replace(/::/g, '/') + |
1221 |
| - '/' + type + '.' + name + '.html'; |
1222 |
| - } else if (type === "externcrate") { |
1223 |
| - displayPath = ""; |
1224 |
| - href = rootPath + name + '/index.html'; |
1225 |
| - } else if (item.parent !== undefined) { |
1226 |
| - var myparent = item.parent; |
1227 |
| - var anchor = '#' + type + '.' + name; |
1228 |
| - var parentType = itemTypes[myparent.ty]; |
1229 |
| - if (parentType === "primitive") { |
1230 |
| - displayPath = myparent.name + '::'; |
1231 |
| - } else { |
1232 |
| - displayPath = item.path + '::' + myparent.name + '::'; |
1233 |
| - } |
1234 |
| - href = rootPath + item.path.replace(/::/g, '/') + |
1235 |
| - '/' + parentType + |
1236 |
| - '.' + myparent.name + |
1237 |
| - '.html' + anchor; |
1238 |
| - } else { |
1239 |
| - displayPath = item.path + '::'; |
1240 |
| - href = rootPath + item.path.replace(/::/g, '/') + |
1241 |
| - '/' + type + '.' + name + '.html'; |
1242 |
| - } |
| 1253 | + var res = buildHrefAndPath(item); |
| 1254 | + var href = res[1]; |
| 1255 | + var displayPath = res[0]; |
1243 | 1256 |
|
1244 | 1257 | output += '<tr class="' + type + ' result"><td>' +
|
1245 | 1258 | '<a href="' + href + '">' +
|
|
1268 | 1281 | }
|
1269 | 1282 |
|
1270 | 1283 | function showResults(results) {
|
| 1284 | + if (results['others'].length === 1 && |
| 1285 | + getCurrentValue('rustdoc-go-to-only-result') === "true") { |
| 1286 | + var elem = document.createElement('a'); |
| 1287 | + var res = buildHrefAndPath(results['others'][0]); |
| 1288 | + elem.href = res[1]; |
| 1289 | + elem.style.display = 'none'; |
| 1290 | + // For firefox, we need the element to be in the DOM so it can be clicked. |
| 1291 | + document.body.appendChild(elem); |
| 1292 | + elem.click(); |
| 1293 | + } |
1271 | 1294 | var output, query = getQuery(search_input.value);
|
1272 | 1295 |
|
1273 | 1296 | currentResults = query.id;
|
|
1721 | 1744 |
|
1722 | 1745 | function toggleAllDocs(pageId) {
|
1723 | 1746 | var toggle = document.getElementById("toggle-all-docs");
|
| 1747 | + if (!toggle) { |
| 1748 | + return; |
| 1749 | + } |
1724 | 1750 | if (hasClass(toggle, "will-expand")) {
|
1725 | 1751 | updateLocalStorage("rustdoc-collapse", "false");
|
1726 | 1752 | removeClass(toggle, "will-expand");
|
|
1977 | 2003 | collapseDocs(e.previousSibling.childNodes[0], "toggle");
|
1978 | 2004 | }
|
1979 | 2005 | }
|
1980 |
| - }) |
| 2006 | + }); |
1981 | 2007 |
|
1982 | 2008 | autoCollapseAllImpls(getPageId());
|
1983 | 2009 |
|
|
0 commit comments