|
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.
|
|
64 | 63 | if ($('#' + from).length === 0) {
|
65 | 64 | return;
|
66 | 65 | }
|
67 |
| - if (ev === null) $('#' + from)[0].scrollIntoView(); |
| 66 | + if (ev === null) { $('#' + from)[0].scrollIntoView(); }; |
68 | 67 | $('.line-numbers span').removeClass('line-highlighted');
|
69 | 68 | for (i = from; i <= to; ++i) {
|
70 | 69 | $('#' + i).addClass('line-highlighted');
|
|
74 | 73 | highlightSourceLines(null);
|
75 | 74 | $(window).on('hashchange', highlightSourceLines);
|
76 | 75 |
|
77 |
| - $(document).on('keyup', function(e) { |
| 76 | + $(document).on('keyup', function handleKeyboardShortcut(e) { |
78 | 77 | if (document.activeElement.tagName === 'INPUT') {
|
79 | 78 | return;
|
80 | 79 | }
|
|
133 | 132 | return function(s1, s2) {
|
134 | 133 | if (s1 === s2) {
|
135 | 134 | 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 |
| - } |
| 135 | + } |
| 136 | + var s1_len = s1.length, s2_len = s2.length; |
| 137 | + if (s1_len && s2_len) { |
| 138 | + var i1 = 0, i2 = 0, a, b, c, c2, row = row2; |
| 139 | + while (i1 < s1_len) { |
| 140 | + row[i1] = ++i1; |
| 141 | + } |
| 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; |
153 | 152 | }
|
154 |
| - return b; |
155 |
| - } else { |
156 |
| - return s1_len + s2_len; |
157 | 153 | }
|
| 154 | + return b; |
158 | 155 | }
|
| 156 | + return s1_len + s2_len; |
159 | 157 | };
|
160 | 158 | })();
|
161 | 159 |
|
|
187 | 185 | results = [],
|
188 | 186 | split = valLower.split("::");
|
189 | 187 |
|
190 |
| - //remove empty keywords |
| 188 | + // remove empty keywords |
191 | 189 | for (var j = 0; j < split.length; ++j) {
|
192 | 190 | split[j].toLowerCase();
|
193 | 191 | if (split[j] === "") {
|
|
286 | 284 | return [];
|
287 | 285 | }
|
288 | 286 |
|
289 |
| - results.sort(function(aaa, bbb) { |
| 287 | + results.sort(function sortResults(aaa, bbb) { |
290 | 288 | var a, b;
|
291 | 289 |
|
292 | 290 | // Sort by non levenshtein results and then levenshtein results by the distance
|
293 | 291 | // (less changes required to match means higher rankings)
|
294 | 292 | a = (aaa.lev);
|
295 | 293 | b = (bbb.lev);
|
296 |
| - if (a !== b) return a - b; |
| 294 | + if (a !== b) { return a - b; } |
297 | 295 |
|
298 | 296 | // sort by crate (non-current crate goes later)
|
299 | 297 | a = (aaa.item.crate !== window.currentCrate);
|
300 | 298 | b = (bbb.item.crate !== window.currentCrate);
|
301 |
| - if (a !== b) return a - b; |
| 299 | + if (a !== b) { return a - b; } |
302 | 300 |
|
303 | 301 | // sort by exact match (mismatch goes later)
|
304 | 302 | a = (aaa.word !== valLower);
|
305 | 303 | b = (bbb.word !== valLower);
|
306 |
| - if (a !== b) return a - b; |
| 304 | + if (a !== b) { return a - b; } |
307 | 305 |
|
308 | 306 | // sort by item name length (longer goes later)
|
309 | 307 | a = aaa.word.length;
|
310 | 308 | b = bbb.word.length;
|
311 |
| - if (a !== b) return a - b; |
| 309 | + if (a !== b) { return a - b; } |
312 | 310 |
|
313 | 311 | // sort by item name (lexicographically larger goes later)
|
314 | 312 | a = aaa.word;
|
315 | 313 | b = bbb.word;
|
316 |
| - if (a !== b) return (a > b ? +1 : -1); |
| 314 | + if (a !== b) { return (a > b ? +1 : -1); } |
317 | 315 |
|
318 | 316 | // sort by index of keyword in item name (no literal occurrence goes later)
|
319 | 317 | a = (aaa.index < 0);
|
320 | 318 | b = (bbb.index < 0);
|
321 |
| - if (a !== b) return a - b; |
| 319 | + if (a !== b) { return a - b; } |
322 | 320 | // (later literal occurrence, if any, goes later)
|
323 | 321 | a = aaa.index;
|
324 | 322 | b = bbb.index;
|
325 |
| - if (a !== b) return a - b; |
| 323 | + if (a !== b) { return a - b; } |
| 324 | + |
326 | 325 |
|
327 | 326 | // sort by description (no description goes later)
|
328 | 327 | a = (aaa.item.desc === '');
|
329 | 328 | b = (bbb.item.desc === '');
|
330 |
| - if (a !== b) return a - b; |
| 329 | + if (a !== b) { return a - b; } |
331 | 330 |
|
332 | 331 | // sort by type (later occurrence in `itemTypes` goes later)
|
333 | 332 | a = aaa.item.ty;
|
334 | 333 | b = bbb.item.ty;
|
335 |
| - if (a !== b) return a - b; |
| 334 | + if (a !== b) { return a - b; } |
336 | 335 |
|
337 | 336 | // sort by path (lexicographically larger goes later)
|
338 | 337 | a = aaa.item.path;
|
339 | 338 | b = bbb.item.path;
|
340 |
| - if (a !== b) return (a > b ? +1 : -1); |
| 339 | + if (a !== b) { return (a > b ? +1 : -1); } |
341 | 340 |
|
342 | 341 | // que sera, sera
|
343 | 342 | return 0;
|
|
388 | 387 | * @return {[boolean]} [Whether the result is valid or not]
|
389 | 388 | */
|
390 | 389 | function validateResult(name, path, keys, parent) {
|
391 |
| - for (var i=0; i < keys.length; ++i) { |
| 390 | + for (var i = 0; i < keys.length; ++i) { |
392 | 391 | // each check is for validation so we negate the conditions and invalidate
|
393 | 392 | if (!(
|
394 | 393 | // check for an exact name match
|
|
423 | 422 | raw: raw,
|
424 | 423 | query: query,
|
425 | 424 | type: type,
|
426 |
| - id: query + type, |
| 425 | + id: query + type |
427 | 426 | };
|
428 | 427 | }
|
429 | 428 |
|
|
432 | 431 |
|
433 | 432 | $results.on('click', function() {
|
434 | 433 | var dst = $(this).find('a')[0];
|
435 |
| - if (window.location.pathname == dst.pathname) { |
| 434 | + if (window.location.pathname === dst.pathname) { |
436 | 435 | $('#search').addClass('hidden');
|
437 | 436 | $('#main').removeClass('hidden');
|
438 | 437 | document.location.href = dst.href;
|
|
595 | 594 |
|
596 | 595 | function itemTypeFromName(typename) {
|
597 | 596 | for (var i = 0; i < itemTypes.length; ++i) {
|
598 |
| - if (itemTypes[i] === typename) return i; |
| 597 | + if (itemTypes[i] === typename) { return i; } |
599 | 598 | }
|
600 | 599 | return -1;
|
601 | 600 | }
|
|
604 | 603 | searchIndex = [];
|
605 | 604 | var searchWords = [];
|
606 | 605 | for (var crate in rawSearchIndex) {
|
607 |
| - if (!rawSearchIndex.hasOwnProperty(crate)) { continue } |
| 606 | + if (!rawSearchIndex.hasOwnProperty(crate)) { continue; } |
608 | 607 |
|
609 | 608 | // an array of [(Number) item type,
|
610 | 609 | // (String) name,
|
|
690 | 689 | }
|
691 | 690 |
|
692 | 691 | 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; |
| 692 | + markdown.replace(/\n/g, ' ') |
| 693 | + .replace(/'/g, "\'") |
| 694 | + .replace(/^#+? (.+?)/, "$1") |
| 695 | + .replace(/\[(.*?)\]\(.*?\)/g, "$1") |
| 696 | + .replace(/\[(.*?)\]\[.*?\]/g, "$1"); |
699 | 697 | }
|
700 | 698 |
|
701 | 699 | index = buildIndex(rawSearchIndex);
|
702 | 700 | startSearch();
|
703 | 701 |
|
704 | 702 | // Draw a convenient sidebar of known crates if we have a listing
|
705 |
| - if (rootPath == '../') { |
| 703 | + if (rootPath === '../') { |
706 | 704 | var sidebar = $('.sidebar');
|
707 | 705 | var div = $('<div>').attr('class', 'block crate');
|
708 | 706 | div.append($('<h2>').text('Crates'));
|
709 | 707 |
|
710 | 708 | var crates = [];
|
711 | 709 | for (var crate in rawSearchIndex) {
|
712 |
| - if (!rawSearchIndex.hasOwnProperty(crate)) { continue } |
| 710 | + if (!rawSearchIndex.hasOwnProperty(crate)) { continue; } |
713 | 711 | crates.push(crate);
|
714 | 712 | }
|
715 | 713 | crates.sort();
|
716 | 714 | for (var i = 0; i < crates.length; ++i) {
|
717 | 715 | var klass = 'crate';
|
718 |
| - if (crates[i] == window.currentCrate) { |
| 716 | + if (crates[i] === window.currentCrate) { |
719 | 717 | klass += ' current';
|
720 | 718 | }
|
721 | 719 | if (rawSearchIndex[crates[i]].items[0]) {
|
|
738 | 736 |
|
739 | 737 | function block(shortty, longty) {
|
740 | 738 | var filtered = items[shortty];
|
741 |
| - if (!filtered) return; |
| 739 | + if (!filtered) { return; } |
742 | 740 |
|
743 | 741 | var div = $('<div>').attr('class', 'block ' + shortty);
|
744 | 742 | div.append($('<h2>').text(longty));
|
|
749 | 747 | var desc = item[1]; // can be null
|
750 | 748 |
|
751 | 749 | var klass = shortty;
|
752 |
| - if (name === current.name && shortty == current.ty) { |
| 750 | + if (name === current.name && shortty === current.ty) { |
753 | 751 | klass += ' current';
|
754 | 752 | }
|
755 | 753 | var path;
|
|
779 | 777 | var list = $('#implementors-list');
|
780 | 778 | var libs = Object.getOwnPropertyNames(imp);
|
781 | 779 | for (var i = 0; i < libs.length; ++i) {
|
782 |
| - if (libs[i] == currentCrate) continue; |
| 780 | + if (libs[i] === currentCrate) { continue; } |
783 | 781 | var structs = imp[libs[i]];
|
784 | 782 | for (var j = 0; j < structs.length; ++j) {
|
785 | 783 | var code = $('<code>').append(structs[j]);
|
|
811 | 809 | if (sectionIsCollapsed) {
|
812 | 810 | // button will expand the section
|
813 | 811 | 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 | 812 | }
|
| 813 | + // button will collapse the section |
| 814 | + // note that this text is also set in the HTML template in render.rs |
| 815 | + return "\u2212"; // "\u2212" is '−' minus sign |
819 | 816 | }
|
820 | 817 |
|
821 | 818 | $("#toggle-all-docs").on("click", function() {
|
|
847 | 844 | }
|
848 | 845 | if (relatedDoc.is(".docblock")) {
|
849 | 846 | if (relatedDoc.is(":visible")) {
|
850 |
| - relatedDoc.slideUp({duration:'fast', easing:'linear'}); |
| 847 | + relatedDoc.slideUp({duration: 'fast', easing: 'linear'}); |
851 | 848 | toggle.parent(".toggle-wrapper").addClass("collapsed");
|
852 | 849 | toggle.children(".inner").text(labelForToggleButton(true));
|
853 | 850 | toggle.children(".toggle-label").fadeIn();
|
854 | 851 | } else {
|
855 |
| - relatedDoc.slideDown({duration:'fast', easing:'linear'}); |
| 852 | + relatedDoc.slideDown({duration: 'fast', easing: 'linear'}); |
856 | 853 | toggle.parent(".toggle-wrapper").removeClass("collapsed");
|
857 | 854 | toggle.children(".inner").text(labelForToggleButton(false));
|
858 | 855 | toggle.children(".toggle-label").hide();
|
|
877 | 874 | $('<span/>', {'class': 'toggle-label'})
|
878 | 875 | .css('display', 'none')
|
879 | 876 | .html(' Expand description'));
|
880 |
| - var wrapper = $("<div class='toggle-wrapper'>").append(mainToggle); |
| 877 | + var wrapper = $("<div class='toggle-wrapper'>").append(mainToggle); |
881 | 878 | $("#main > .docblock").before(wrapper);
|
882 | 879 | });
|
883 | 880 |
|
|
894 | 891 | }
|
895 | 892 |
|
896 | 893 | return function(ev) {
|
897 |
| - var cur_id = parseInt(ev.target.id); |
| 894 | + var cur_id = parseInt(ev.target.id, 10); |
898 | 895 |
|
899 | 896 | if (ev.shiftKey && prev_id) {
|
900 | 897 | if (prev_id > cur_id) {
|
|
0 commit comments