|
15 | 15 | "use strict"; |
16 | 16 | var resizeTimeout, interval; |
17 | 17 |
|
| 18 | + // This mapping table should match the discriminants of |
| 19 | + // `rustdoc::html::item_type::ItemType` type in Rust. |
| 20 | + var itemTypes = ["mod", |
| 21 | + "externcrate", |
| 22 | + "import", |
| 23 | + "struct", |
| 24 | + "enum", |
| 25 | + "fn", |
| 26 | + "type", |
| 27 | + "static", |
| 28 | + "trait", |
| 29 | + "impl", |
| 30 | + "tymethod", |
| 31 | + "method", |
| 32 | + "structfield", |
| 33 | + "variant", |
| 34 | + "macro", |
| 35 | + "primitive", |
| 36 | + "associatedtype", |
| 37 | + "constant"]; |
| 38 | + |
18 | 39 | $('.js-only').removeClass('js-only'); |
19 | 40 |
|
20 | 41 | function getQueryStringParams() { |
|
33 | 54 | return window.history && typeof window.history.pushState === "function"; |
34 | 55 | } |
35 | 56 |
|
36 | | - function resizeShortBlocks() { |
37 | | - if (resizeTimeout) { |
38 | | - clearTimeout(resizeTimeout); |
39 | | - } |
40 | | - resizeTimeout = setTimeout(function() { |
41 | | - var contentWidth = $('.content').width(); |
42 | | - $('.docblock.short').width(function() { |
43 | | - return contentWidth - 40 - $(this).prev().width(); |
44 | | - }).addClass('nowrap'); |
45 | | - $('.summary-column').width(function() { |
46 | | - return contentWidth - 40 - $(this).prev().width(); |
47 | | - }) |
48 | | - }, 150); |
49 | | - } |
50 | | - resizeShortBlocks(); |
51 | | - $(window).on('resize', resizeShortBlocks); |
52 | | - |
53 | 57 | function highlightSourceLines(ev) { |
54 | 58 | var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/); |
55 | 59 | if (match) { |
|
205 | 209 | break; |
206 | 210 | } |
207 | 211 | } |
| 212 | + // searching by type |
| 213 | + } else if (val.search("->") > -1) { |
| 214 | + var trimmer = function (s) { return s.trim(); }; |
| 215 | + var parts = val.split("->").map(trimmer); |
| 216 | + var input = parts[0]; |
| 217 | + // sort inputs so that order does not matter |
| 218 | + var inputs = input.split(",").map(trimmer).sort(); |
| 219 | + var output = parts[1]; |
| 220 | + |
| 221 | + for (var i = 0; i < nSearchWords; ++i) { |
| 222 | + var type = searchIndex[i].type; |
| 223 | + if (!type) { |
| 224 | + continue; |
| 225 | + } |
| 226 | + |
| 227 | + // sort index inputs so that order does not matter |
| 228 | + var typeInputs = type.inputs.map(function (input) { |
| 229 | + return input.name; |
| 230 | + }).sort(); |
| 231 | + |
| 232 | + // allow searching for void (no output) functions as well |
| 233 | + var typeOutput = type.output ? type.output.name : ""; |
| 234 | + if (inputs.toString() === typeInputs.toString() && |
| 235 | + output == typeOutput) { |
| 236 | + results.push({id: i, index: -1, dontValidate: true}); |
| 237 | + } |
| 238 | + } |
208 | 239 | } else { |
209 | 240 | // gather matching search results up to a certain maximum |
210 | 241 | val = val.replace(/\_/g, ""); |
|
325 | 356 | path = result.item.path.toLowerCase(), |
326 | 357 | parent = result.item.parent; |
327 | 358 |
|
| 359 | + // this validation does not make sense when searching by types |
| 360 | + if (result.dontValidate) { |
| 361 | + continue; |
| 362 | + } |
| 363 | + |
328 | 364 | var valid = validateResult(name, path, split, parent); |
329 | 365 | if (!valid) { |
330 | 366 | result.id = -1; |
|
552 | 588 | showResults(results); |
553 | 589 | } |
554 | 590 |
|
555 | | - // This mapping table should match the discriminants of |
556 | | - // `rustdoc::html::item_type::ItemType` type in Rust. |
557 | | - var itemTypes = ["mod", |
558 | | - "externcrate", |
559 | | - "import", |
560 | | - "struct", |
561 | | - "enum", |
562 | | - "fn", |
563 | | - "type", |
564 | | - "static", |
565 | | - "trait", |
566 | | - "impl", |
567 | | - "tymethod", |
568 | | - "method", |
569 | | - "structfield", |
570 | | - "variant", |
571 | | - "macro", |
572 | | - "primitive", |
573 | | - "associatedtype", |
574 | | - "constant"]; |
575 | | - |
576 | 591 | function itemTypeFromName(typename) { |
577 | 592 | for (var i = 0; i < itemTypes.length; ++i) { |
578 | 593 | if (itemTypes[i] === typename) return i; |
|
590 | 605 | // (String) name, |
591 | 606 | // (String) full path or empty string for previous path, |
592 | 607 | // (String) description, |
593 | | - // (optional Number) the parent path index to `paths`] |
| 608 | + // (Number | null) the parent path index to `paths`] |
| 609 | + // (Object | null) the type of the function (if any) |
594 | 610 | var items = rawSearchIndex[crate].items; |
595 | 611 | // an array of [(Number) item type, |
596 | 612 | // (String) name] |
|
615 | 631 | var rawRow = items[i]; |
616 | 632 | var row = {crate: crate, ty: rawRow[0], name: rawRow[1], |
617 | 633 | path: rawRow[2] || lastPath, desc: rawRow[3], |
618 | | - parent: paths[rawRow[4]]}; |
| 634 | + parent: paths[rawRow[4]], type: rawRow[5]}; |
619 | 635 | searchIndex.push(row); |
620 | 636 | if (typeof row.name === "string") { |
621 | 637 | var word = row.name.toLowerCase(); |
|
708 | 724 |
|
709 | 725 | window.initSearch = initSearch; |
710 | 726 |
|
| 727 | + // delayed sidebar rendering. |
| 728 | + function initSidebarItems(items) { |
| 729 | + var sidebar = $('.sidebar'); |
| 730 | + var current = window.sidebarCurrent; |
| 731 | + |
| 732 | + function block(shortty, longty) { |
| 733 | + var filtered = items[shortty]; |
| 734 | + if (!filtered) return; |
| 735 | + |
| 736 | + var div = $('<div>').attr('class', 'block ' + shortty); |
| 737 | + div.append($('<h2>').text(longty)); |
| 738 | + |
| 739 | + for (var i = 0; i < filtered.length; ++i) { |
| 740 | + var item = filtered[i]; |
| 741 | + var name = item[0]; |
| 742 | + var desc = item[1]; // can be null |
| 743 | + |
| 744 | + var klass = shortty; |
| 745 | + if (name === current.name && shortty == current.ty) { |
| 746 | + klass += ' current'; |
| 747 | + } |
| 748 | + var path; |
| 749 | + if (shortty === 'mod') { |
| 750 | + path = name + '/index.html'; |
| 751 | + } else { |
| 752 | + path = shortty + '.' + name + '.html'; |
| 753 | + } |
| 754 | + div.append($('<a>', {'href': current.relpath + path, |
| 755 | + 'title': desc, |
| 756 | + 'class': klass}).text(name)); |
| 757 | + } |
| 758 | + sidebar.append(div); |
| 759 | + } |
| 760 | + |
| 761 | + block("mod", "Modules"); |
| 762 | + block("struct", "Structs"); |
| 763 | + block("enum", "Enums"); |
| 764 | + block("trait", "Traits"); |
| 765 | + block("fn", "Functions"); |
| 766 | + block("macro", "Macros"); |
| 767 | + } |
| 768 | + |
| 769 | + window.initSidebarItems = initSidebarItems; |
| 770 | + |
711 | 771 | window.register_implementors = function(imp) { |
712 | 772 | var list = $('#implementors-list'); |
713 | 773 | var libs = Object.getOwnPropertyNames(imp); |
|
0 commit comments