|
13 | 13 |
|
14 | 14 | (function() {
|
15 | 15 | "use strict";
|
16 |
| - var resizeTimeout, interval; |
17 | 16 |
|
18 | 17 | // This mapping table should match the discriminants of
|
19 | 18 | // `rustdoc::html::item_type::ItemType` type in Rust.
|
|
37 | 36 | "constant",
|
38 | 37 | "associatedconstant"];
|
39 | 38 |
|
| 39 | + // used for special search precedence |
| 40 | + var TY_PRIMITIVE = itemTypes.indexOf("primitive"); |
| 41 | + |
40 | 42 | $('.js-only').removeClass('js-only');
|
41 | 43 |
|
42 | 44 | function getQueryStringParams() {
|
|
64 | 66 | if ($('#' + from).length === 0) {
|
65 | 67 | return;
|
66 | 68 | }
|
67 |
| - if (ev === null) $('#' + from)[0].scrollIntoView(); |
| 69 | + if (ev === null) { $('#' + from)[0].scrollIntoView(); }; |
68 | 70 | $('.line-numbers span').removeClass('line-highlighted');
|
69 | 71 | for (i = from; i <= to; ++i) {
|
70 | 72 | $('#' + i).addClass('line-highlighted');
|
|
74 | 76 | highlightSourceLines(null);
|
75 | 77 | $(window).on('hashchange', highlightSourceLines);
|
76 | 78 |
|
77 |
| - $(document).on('keyup', function(e) { |
| 79 | + $(document).on('keyup', function handleKeyboardShortcut(e) { |
78 | 80 | if (document.activeElement.tagName === 'INPUT') {
|
79 | 81 | return;
|
80 | 82 | }
|
|
133 | 135 | return function(s1, s2) {
|
134 | 136 | if (s1 === s2) {
|
135 | 137 | return 0;
|
136 |
| - } else { |
137 |
| - var s1_len = s1.length, s2_len = s2.length; |
138 |
| - if (s1_len && s2_len) { |
139 |
| - var i1 = 0, i2 = 0, a, b, c, c2, row = row2; |
140 |
| - while (i1 < s1_len) |
141 |
| - row[i1] = ++i1; |
142 |
| - while (i2 < s2_len) { |
143 |
| - c2 = s2.charCodeAt(i2); |
144 |
| - a = i2; |
145 |
| - ++i2; |
146 |
| - b = i2; |
147 |
| - for (i1 = 0; i1 < s1_len; ++i1) { |
148 |
| - c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0); |
149 |
| - a = row[i1]; |
150 |
| - b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c); |
151 |
| - row[i1] = b; |
152 |
| - } |
| 138 | + } |
| 139 | + var s1_len = s1.length, s2_len = s2.length; |
| 140 | + if (s1_len && s2_len) { |
| 141 | + var i1 = 0, i2 = 0, a, b, c, c2, row = row2; |
| 142 | + while (i1 < s1_len) { |
| 143 | + row[i1] = ++i1; |
| 144 | + } |
| 145 | + while (i2 < s2_len) { |
| 146 | + c2 = s2.charCodeAt(i2); |
| 147 | + a = i2; |
| 148 | + ++i2; |
| 149 | + b = i2; |
| 150 | + for (i1 = 0; i1 < s1_len; ++i1) { |
| 151 | + c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0); |
| 152 | + a = row[i1]; |
| 153 | + b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c); |
| 154 | + row[i1] = b; |
153 | 155 | }
|
154 |
| - return b; |
155 |
| - } else { |
156 |
| - return s1_len + s2_len; |
157 | 156 | }
|
| 157 | + return b; |
158 | 158 | }
|
| 159 | + return s1_len + s2_len; |
159 | 160 | };
|
160 | 161 | })();
|
161 | 162 |
|
|
187 | 188 | results = [],
|
188 | 189 | split = valLower.split("::");
|
189 | 190 |
|
190 |
| - //remove empty keywords |
| 191 | + // remove empty keywords |
191 | 192 | for (var j = 0; j < split.length; ++j) {
|
192 | 193 | split[j].toLowerCase();
|
193 | 194 | if (split[j] === "") {
|
|
286 | 287 | return [];
|
287 | 288 | }
|
288 | 289 |
|
289 |
| - results.sort(function(aaa, bbb) { |
| 290 | + results.sort(function sortResults(aaa, bbb) { |
290 | 291 | var a, b;
|
291 | 292 |
|
292 | 293 | // Sort by non levenshtein results and then levenshtein results by the distance
|
293 | 294 | // (less changes required to match means higher rankings)
|
294 | 295 | a = (aaa.lev);
|
295 | 296 | b = (bbb.lev);
|
296 |
| - if (a !== b) return a - b; |
| 297 | + if (a !== b) { return a - b; } |
297 | 298 |
|
298 | 299 | // sort by crate (non-current crate goes later)
|
299 | 300 | a = (aaa.item.crate !== window.currentCrate);
|
300 | 301 | b = (bbb.item.crate !== window.currentCrate);
|
301 |
| - if (a !== b) return a - b; |
| 302 | + if (a !== b) { return a - b; } |
302 | 303 |
|
303 | 304 | // sort by exact match (mismatch goes later)
|
304 | 305 | a = (aaa.word !== valLower);
|
305 | 306 | b = (bbb.word !== valLower);
|
306 |
| - if (a !== b) return a - b; |
| 307 | + if (a !== b) { return a - b; } |
307 | 308 |
|
308 | 309 | // sort by item name length (longer goes later)
|
309 | 310 | a = aaa.word.length;
|
310 | 311 | b = bbb.word.length;
|
311 |
| - if (a !== b) return a - b; |
| 312 | + if (a !== b) { return a - b; } |
312 | 313 |
|
313 | 314 | // sort by item name (lexicographically larger goes later)
|
314 | 315 | a = aaa.word;
|
315 | 316 | b = bbb.word;
|
316 |
| - if (a !== b) return (a > b ? +1 : -1); |
| 317 | + if (a !== b) { return (a > b ? +1 : -1); } |
317 | 318 |
|
318 | 319 | // sort by index of keyword in item name (no literal occurrence goes later)
|
319 | 320 | a = (aaa.index < 0);
|
320 | 321 | b = (bbb.index < 0);
|
321 |
| - if (a !== b) return a - b; |
| 322 | + if (a !== b) { return a - b; } |
322 | 323 | // (later literal occurrence, if any, goes later)
|
323 | 324 | a = aaa.index;
|
324 | 325 | b = bbb.index;
|
325 |
| - if (a !== b) return a - b; |
| 326 | + if (a !== b) { return a - b; } |
| 327 | + |
| 328 | + // special precedence for primitive pages |
| 329 | + if ((aaa.item.ty === TY_PRIMITIVE) && (bbb.item.ty !== TY_PRIMITIVE)) { |
| 330 | + return -1; |
| 331 | + } |
326 | 332 |
|
327 | 333 | // sort by description (no description goes later)
|
328 | 334 | a = (aaa.item.desc === '');
|
329 | 335 | b = (bbb.item.desc === '');
|
330 |
| - if (a !== b) return a - b; |
| 336 | + if (a !== b) { return a - b; } |
331 | 337 |
|
332 | 338 | // sort by type (later occurrence in `itemTypes` goes later)
|
333 | 339 | a = aaa.item.ty;
|
334 | 340 | b = bbb.item.ty;
|
335 |
| - if (a !== b) return a - b; |
| 341 | + if (a !== b) { return a - b; } |
336 | 342 |
|
337 | 343 | // sort by path (lexicographically larger goes later)
|
338 | 344 | a = aaa.item.path;
|
339 | 345 | b = bbb.item.path;
|
340 |
| - if (a !== b) return (a > b ? +1 : -1); |
| 346 | + if (a !== b) { return (a > b ? +1 : -1); } |
341 | 347 |
|
342 | 348 | // que sera, sera
|
343 | 349 | return 0;
|
|
388 | 394 | * @return {[boolean]} [Whether the result is valid or not]
|
389 | 395 | */
|
390 | 396 | function validateResult(name, path, keys, parent) {
|
391 |
| - for (var i=0; i < keys.length; ++i) { |
| 397 | + for (var i = 0; i < keys.length; ++i) { |
392 | 398 | // each check is for validation so we negate the conditions and invalidate
|
393 | 399 | if (!(
|
394 | 400 | // check for an exact name match
|
|
423 | 429 | raw: raw,
|
424 | 430 | query: query,
|
425 | 431 | type: type,
|
426 |
| - id: query + type, |
| 432 | + id: query + type |
427 | 433 | };
|
428 | 434 | }
|
429 | 435 |
|
|
432 | 438 |
|
433 | 439 | $results.on('click', function() {
|
434 | 440 | var dst = $(this).find('a')[0];
|
435 |
| - if (window.location.pathname == dst.pathname) { |
| 441 | + if (window.location.pathname === dst.pathname) { |
436 | 442 | $('#search').addClass('hidden');
|
437 | 443 | $('#main').removeClass('hidden');
|
438 | 444 | document.location.href = dst.href;
|
|
595 | 601 |
|
596 | 602 | function itemTypeFromName(typename) {
|
597 | 603 | for (var i = 0; i < itemTypes.length; ++i) {
|
598 |
| - if (itemTypes[i] === typename) return i; |
| 604 | + if (itemTypes[i] === typename) { return i; } |
599 | 605 | }
|
600 | 606 | return -1;
|
601 | 607 | }
|
|
604 | 610 | searchIndex = [];
|
605 | 611 | var searchWords = [];
|
606 | 612 | for (var crate in rawSearchIndex) {
|
607 |
| - if (!rawSearchIndex.hasOwnProperty(crate)) { continue } |
| 613 | + if (!rawSearchIndex.hasOwnProperty(crate)) { continue; } |
608 | 614 |
|
609 | 615 | // an array of [(Number) item type,
|
610 | 616 | // (String) name,
|
|
690 | 696 | }
|
691 | 697 |
|
692 | 698 | function plainSummaryLine(markdown) {
|
693 |
| - var str = markdown.replace(/\n/g, ' ') |
694 |
| - str = str.replace(/'/g, "\'") |
695 |
| - str = str.replace(/^#+? (.+?)/, "$1") |
696 |
| - str = str.replace(/\[(.*?)\]\(.*?\)/g, "$1") |
697 |
| - str = str.replace(/\[(.*?)\]\[.*?\]/g, "$1") |
698 |
| - return str; |
| 699 | + markdown.replace(/\n/g, ' ') |
| 700 | + .replace(/'/g, "\'") |
| 701 | + .replace(/^#+? (.+?)/, "$1") |
| 702 | + .replace(/\[(.*?)\]\(.*?\)/g, "$1") |
| 703 | + .replace(/\[(.*?)\]\[.*?\]/g, "$1"); |
699 | 704 | }
|
700 | 705 |
|
701 | 706 | index = buildIndex(rawSearchIndex);
|
702 | 707 | startSearch();
|
703 | 708 |
|
704 | 709 | // Draw a convenient sidebar of known crates if we have a listing
|
705 |
| - if (rootPath == '../') { |
| 710 | + if (rootPath === '../') { |
706 | 711 | var sidebar = $('.sidebar');
|
707 | 712 | var div = $('<div>').attr('class', 'block crate');
|
708 | 713 | div.append($('<h2>').text('Crates'));
|
709 | 714 |
|
710 | 715 | var crates = [];
|
711 | 716 | for (var crate in rawSearchIndex) {
|
712 |
| - if (!rawSearchIndex.hasOwnProperty(crate)) { continue } |
| 717 | + if (!rawSearchIndex.hasOwnProperty(crate)) { continue; } |
713 | 718 | crates.push(crate);
|
714 | 719 | }
|
715 | 720 | crates.sort();
|
716 | 721 | for (var i = 0; i < crates.length; ++i) {
|
717 | 722 | var klass = 'crate';
|
718 |
| - if (crates[i] == window.currentCrate) { |
| 723 | + if (crates[i] === window.currentCrate) { |
719 | 724 | klass += ' current';
|
720 | 725 | }
|
721 | 726 | if (rawSearchIndex[crates[i]].items[0]) {
|
|
738 | 743 |
|
739 | 744 | function block(shortty, longty) {
|
740 | 745 | var filtered = items[shortty];
|
741 |
| - if (!filtered) return; |
| 746 | + if (!filtered) { return; } |
742 | 747 |
|
743 | 748 | var div = $('<div>').attr('class', 'block ' + shortty);
|
744 | 749 | div.append($('<h2>').text(longty));
|
|
749 | 754 | var desc = item[1]; // can be null
|
750 | 755 |
|
751 | 756 | var klass = shortty;
|
752 |
| - if (name === current.name && shortty == current.ty) { |
| 757 | + if (name === current.name && shortty === current.ty) { |
753 | 758 | klass += ' current';
|
754 | 759 | }
|
755 | 760 | var path;
|
|
779 | 784 | var list = $('#implementors-list');
|
780 | 785 | var libs = Object.getOwnPropertyNames(imp);
|
781 | 786 | for (var i = 0; i < libs.length; ++i) {
|
782 |
| - if (libs[i] == currentCrate) continue; |
| 787 | + if (libs[i] === currentCrate) { continue; } |
783 | 788 | var structs = imp[libs[i]];
|
784 | 789 | for (var j = 0; j < structs.length; ++j) {
|
785 | 790 | var code = $('<code>').append(structs[j]);
|
|
811 | 816 | if (sectionIsCollapsed) {
|
812 | 817 | // button will expand the section
|
813 | 818 | return "+";
|
814 |
| - } else { |
815 |
| - // button will collapse the section |
816 |
| - // note that this text is also set in the HTML template in render.rs |
817 |
| - return "\u2212"; // "\u2212" is '−' minus sign |
818 | 819 | }
|
| 820 | + // button will collapse the section |
| 821 | + // note that this text is also set in the HTML template in render.rs |
| 822 | + return "\u2212"; // "\u2212" is '−' minus sign |
819 | 823 | }
|
820 | 824 |
|
821 | 825 | $("#toggle-all-docs").on("click", function() {
|
|
847 | 851 | }
|
848 | 852 | if (relatedDoc.is(".docblock")) {
|
849 | 853 | if (relatedDoc.is(":visible")) {
|
850 |
| - relatedDoc.slideUp({duration:'fast', easing:'linear'}); |
| 854 | + relatedDoc.slideUp({duration: 'fast', easing: 'linear'}); |
851 | 855 | toggle.parent(".toggle-wrapper").addClass("collapsed");
|
852 | 856 | toggle.children(".inner").text(labelForToggleButton(true));
|
853 | 857 | toggle.children(".toggle-label").fadeIn();
|
854 | 858 | } else {
|
855 |
| - relatedDoc.slideDown({duration:'fast', easing:'linear'}); |
| 859 | + relatedDoc.slideDown({duration: 'fast', easing: 'linear'}); |
856 | 860 | toggle.parent(".toggle-wrapper").removeClass("collapsed");
|
857 | 861 | toggle.children(".inner").text(labelForToggleButton(false));
|
858 | 862 | toggle.children(".toggle-label").hide();
|
|
877 | 881 | $('<span/>', {'class': 'toggle-label'})
|
878 | 882 | .css('display', 'none')
|
879 | 883 | .html(' Expand description'));
|
880 |
| - var wrapper = $("<div class='toggle-wrapper'>").append(mainToggle); |
| 884 | + var wrapper = $("<div class='toggle-wrapper'>").append(mainToggle); |
881 | 885 | $("#main > .docblock").before(wrapper);
|
882 | 886 | });
|
883 | 887 |
|
|
894 | 898 | }
|
895 | 899 |
|
896 | 900 | return function(ev) {
|
897 |
| - var cur_id = parseInt(ev.target.id); |
| 901 | + var cur_id = parseInt(ev.target.id, 10); |
898 | 902 |
|
899 | 903 | if (ev.shiftKey && prev_id) {
|
900 | 904 | if (prev_id > cur_id) {
|
|
0 commit comments