2014-01-10 04:59:53 +00:00
|
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
2013-09-19 05:18:38 +00:00
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
|
/*jslint browser: true, es5: true */
|
2014-04-09 16:27:35 +00:00
|
|
|
|
/*globals $: true, rootPath: true */
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2014-01-10 04:59:53 +00:00
|
|
|
|
(function() {
|
2013-09-19 05:18:38 +00:00
|
|
|
|
"use strict";
|
|
|
|
|
|
2015-03-05 07:35:43 +00:00
|
|
|
|
// This mapping table should match the discriminants of
|
|
|
|
|
// `rustdoc::html::item_type::ItemType` type in Rust.
|
|
|
|
|
var itemTypes = ["mod",
|
|
|
|
|
"externcrate",
|
|
|
|
|
"import",
|
|
|
|
|
"struct",
|
|
|
|
|
"enum",
|
|
|
|
|
"fn",
|
|
|
|
|
"type",
|
|
|
|
|
"static",
|
|
|
|
|
"trait",
|
|
|
|
|
"impl",
|
|
|
|
|
"tymethod",
|
|
|
|
|
"method",
|
|
|
|
|
"structfield",
|
|
|
|
|
"variant",
|
|
|
|
|
"macro",
|
|
|
|
|
"primitive",
|
|
|
|
|
"associatedtype",
|
2015-05-08 22:03:42 +00:00
|
|
|
|
"constant",
|
2016-08-10 18:00:17 +00:00
|
|
|
|
"associatedconstant",
|
|
|
|
|
"union"];
|
2015-03-05 07:35:43 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
function hasClass(elem, className) {
|
|
|
|
|
if (elem && className && elem.className) {
|
|
|
|
|
var elemClass = elem.className;
|
|
|
|
|
var start = elemClass.indexOf(className);
|
|
|
|
|
if (start == -1) {
|
|
|
|
|
return false;
|
|
|
|
|
} else if (elemClass.length == className.length) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
if (start > 0 && elemClass[start - 1] != ' ') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var end = start + className.length;
|
|
|
|
|
if (end < elemClass.length && elemClass[end] != ' ') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addClass(elem, className) {
|
|
|
|
|
if (elem && className && !hasClass(elem, className)) {
|
|
|
|
|
if (elem.className && elem.className.length > 0) {
|
|
|
|
|
elem.className += ' ' + className;
|
|
|
|
|
} else {
|
|
|
|
|
elem.className = className;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeClass(elem, className) {
|
|
|
|
|
if (elem && className && elem.className) {
|
|
|
|
|
elem.className = (" " + elem.className + " ").replace(" " + className + " ", " ")
|
|
|
|
|
.trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onEach(arr, func) {
|
|
|
|
|
if (arr && arr.length > 0 && func) {
|
|
|
|
|
for (var i = 0; i < arr.length; i++) {
|
|
|
|
|
func(arr[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isHidden(elem) {
|
|
|
|
|
return (elem.offsetParent === null)
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 12:15:35 +00:00
|
|
|
|
// used for special search precedence
|
|
|
|
|
var TY_PRIMITIVE = itemTypes.indexOf("primitive");
|
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
onEach(document.getElementsByClassName('js-only'), function(e) {
|
|
|
|
|
removeClass(e, 'js-only');
|
|
|
|
|
});
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2014-01-23 01:44:27 +00:00
|
|
|
|
function getQueryStringParams() {
|
|
|
|
|
var params = {};
|
|
|
|
|
window.location.search.substring(1).split("&").
|
|
|
|
|
map(function(s) {
|
|
|
|
|
var pair = s.split("=");
|
|
|
|
|
params[decodeURIComponent(pair[0])] =
|
2014-03-16 08:08:56 +00:00
|
|
|
|
typeof pair[1] === "undefined" ?
|
|
|
|
|
null : decodeURIComponent(pair[1]);
|
2014-01-23 01:44:27 +00:00
|
|
|
|
});
|
|
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function browserSupportsHistoryApi() {
|
2015-09-14 11:52:32 +00:00
|
|
|
|
return document.location.protocol != "file:" &&
|
|
|
|
|
window.history && typeof window.history.pushState === "function";
|
2014-01-23 01:44:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 18:56:47 +00:00
|
|
|
|
function highlightSourceLines(ev) {
|
2013-10-02 17:32:13 +00:00
|
|
|
|
var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
|
|
|
|
|
if (match) {
|
|
|
|
|
from = parseInt(match[1], 10);
|
|
|
|
|
to = Math.min(50000, parseInt(match[2] || match[1], 10));
|
|
|
|
|
from = Math.min(from, to);
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var elem = document.getElementById(from);
|
|
|
|
|
if (!elem) {
|
2013-10-02 17:32:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
if (ev === null) {
|
|
|
|
|
var x = document.getElementById(from);
|
|
|
|
|
if (x) {
|
|
|
|
|
x.scrollIntoView();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
onEach(document.getElementsByClassName('line-numbers'), function(e) {
|
|
|
|
|
onEach(e.getElementsByTagName('span'), function(i_e) {
|
|
|
|
|
removeClass(i_e, 'line-highlighted');
|
|
|
|
|
});
|
|
|
|
|
})
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (i = from; i <= to; ++i) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
addClass(document.getElementById(i), 'line-highlighted');
|
2013-10-02 17:32:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-19 18:56:47 +00:00
|
|
|
|
highlightSourceLines(null);
|
2017-04-14 14:37:09 +00:00
|
|
|
|
window.onhashchange = highlightSourceLines;
|
2013-10-02 17:32:13 +00:00
|
|
|
|
|
2015-07-07 14:15:22 +00:00
|
|
|
|
// Gets the human-readable string for the virtual-key code of the
|
|
|
|
|
// given KeyboardEvent, ev.
|
2015-06-30 07:32:15 +00:00
|
|
|
|
//
|
2015-07-07 14:15:22 +00:00
|
|
|
|
// This function is meant as a polyfill for KeyboardEvent#key,
|
|
|
|
|
// since it is not supported in Trident. We also test for
|
|
|
|
|
// KeyboardEvent#keyCode because the handleShortcut handler is
|
|
|
|
|
// also registered for the keydown event, because Blink doesn't fire
|
|
|
|
|
// keypress on hitting the Escape key.
|
2015-06-30 07:32:15 +00:00
|
|
|
|
//
|
2015-07-07 14:15:22 +00:00
|
|
|
|
// So I guess you could say things are getting pretty interoperable.
|
|
|
|
|
function getVirtualKey(ev) {
|
|
|
|
|
if ("key" in ev && typeof ev.key != "undefined")
|
|
|
|
|
return ev.key;
|
|
|
|
|
|
|
|
|
|
var c = ev.charCode || ev.keyCode;
|
|
|
|
|
if (c == 27)
|
|
|
|
|
return "Escape";
|
|
|
|
|
return String.fromCharCode(c);
|
2015-06-30 07:32:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-07 14:15:22 +00:00
|
|
|
|
function handleShortcut(ev) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
if (document.activeElement.tagName === "INPUT")
|
2013-09-19 05:18:38 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-11-05 10:39:02 +00:00
|
|
|
|
// Don't interfere with browser shortcuts
|
|
|
|
|
if (ev.ctrlKey || ev.altKey || ev.metaKey)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var help = document.getElementById("help");
|
2015-07-07 14:15:22 +00:00
|
|
|
|
switch (getVirtualKey(ev)) {
|
|
|
|
|
case "Escape":
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var search = document.getElementById("search");
|
|
|
|
|
if (!hasClass(help, "hidden")) {
|
2015-07-07 14:15:22 +00:00
|
|
|
|
ev.preventDefault();
|
2017-04-14 14:37:09 +00:00
|
|
|
|
addClass(help, "hidden");
|
|
|
|
|
removeClass(document.body, "blur");
|
|
|
|
|
} else if (!hasClass(search, "hidden")) {
|
2015-07-07 14:15:22 +00:00
|
|
|
|
ev.preventDefault();
|
2017-04-14 14:37:09 +00:00
|
|
|
|
addClass(search, "hidden");
|
|
|
|
|
removeClass(document.getElementById("main"), "hidden");
|
2015-04-11 22:32:53 +00:00
|
|
|
|
}
|
2015-07-07 14:15:22 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "s":
|
|
|
|
|
case "S":
|
|
|
|
|
ev.preventDefault();
|
2015-07-08 13:52:58 +00:00
|
|
|
|
focusSearchBar();
|
2015-07-07 14:15:22 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2016-05-23 01:11:15 +00:00
|
|
|
|
case "+":
|
|
|
|
|
ev.preventDefault();
|
2016-05-21 02:21:35 +00:00
|
|
|
|
toggleAllDocs();
|
|
|
|
|
break;
|
|
|
|
|
|
2015-07-07 14:15:22 +00:00
|
|
|
|
case "?":
|
2017-04-14 14:37:09 +00:00
|
|
|
|
if (ev.shiftKey && hasClass(help, "hidden")) {
|
2015-07-07 14:15:22 +00:00
|
|
|
|
ev.preventDefault();
|
2017-04-14 14:37:09 +00:00
|
|
|
|
removeClass(help, "hidden");
|
|
|
|
|
addClass(document.body, "blur");
|
2013-09-27 18:06:07 +00:00
|
|
|
|
}
|
2015-07-07 14:15:22 +00:00
|
|
|
|
break;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
2015-07-07 14:15:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
document.onkeypress = handleShortcut;
|
|
|
|
|
document.onkeydown = handleShortcut;
|
|
|
|
|
document.onclick = function(ev) {
|
|
|
|
|
if (hasClass(ev.target, 'collapse-toggle')) {
|
|
|
|
|
collapseDocs(ev.target);
|
|
|
|
|
} else if (hasClass(ev.target.parentNode, 'collapse-toggle')) {
|
|
|
|
|
collapseDocs(ev.target.parentNode);
|
|
|
|
|
} else if (ev.target.tagName === 'SPAN' && hasClass(ev.target.parentNode, 'line-numbers')) {
|
|
|
|
|
var prev_id = 0;
|
|
|
|
|
|
|
|
|
|
function set_fragment(name) {
|
|
|
|
|
if (browserSupportsHistoryApi()) {
|
|
|
|
|
history.replaceState(null, null, '#' + name);
|
|
|
|
|
window.hashchange();
|
|
|
|
|
} else {
|
|
|
|
|
location.replace('#' + name);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var cur_id = parseInt(ev.target.id, 10);
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
if (ev.shiftKey && prev_id) {
|
|
|
|
|
if (prev_id > cur_id) {
|
|
|
|
|
var tmp = prev_id;
|
|
|
|
|
prev_id = cur_id;
|
|
|
|
|
cur_id = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_fragment(prev_id + '-' + cur_id);
|
|
|
|
|
} else {
|
|
|
|
|
prev_id = cur_id;
|
|
|
|
|
|
|
|
|
|
set_fragment(cur_id);
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
} else if (!hasClass(document.getElementById("help"), "hidden")) {
|
|
|
|
|
addClass(document.getElementById("help"), "hidden");
|
|
|
|
|
removeClass(document.body, "blur");
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
};
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var x = document.getElementsByClassName('version-selector');
|
|
|
|
|
if (x.length > 0) {
|
|
|
|
|
x[0].onchange = function() {
|
|
|
|
|
var i, match,
|
|
|
|
|
url = document.location.href,
|
|
|
|
|
stripped = '',
|
|
|
|
|
len = rootPath.match(/\.\.\//g).length + 1;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
|
match = url.match(/\/[^\/]*$/);
|
|
|
|
|
if (i < len - 1) {
|
|
|
|
|
stripped = match[0] + stripped;
|
|
|
|
|
}
|
|
|
|
|
url = url.substring(0, url.length - match[0].length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url += '/' + document.getElementsByClassName('version-selector')[0].value + stripped;
|
|
|
|
|
|
|
|
|
|
document.location.href = url;
|
|
|
|
|
};
|
|
|
|
|
}
|
2015-07-07 14:15:22 +00:00
|
|
|
|
|
2014-07-03 21:07:16 +00:00
|
|
|
|
/**
|
2014-07-03 22:28:22 +00:00
|
|
|
|
* A function to compute the Levenshtein distance between two strings
|
|
|
|
|
* Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported
|
|
|
|
|
* Full License can be found at http://creativecommons.org/licenses/by-sa/3.0/legalcode
|
2014-09-06 00:35:19 +00:00
|
|
|
|
* This code is an unmodified version of the code written by Marco de Wit
|
2014-07-03 22:28:22 +00:00
|
|
|
|
* and was found at http://stackoverflow.com/a/18514751/745719
|
2014-07-03 21:07:16 +00:00
|
|
|
|
*/
|
|
|
|
|
var levenshtein = (function() {
|
|
|
|
|
var row2 = [];
|
|
|
|
|
return function(s1, s2) {
|
|
|
|
|
if (s1 === s2) {
|
|
|
|
|
return 0;
|
2015-05-22 12:14:28 +00:00
|
|
|
|
}
|
|
|
|
|
var s1_len = s1.length, s2_len = s2.length;
|
|
|
|
|
if (s1_len && s2_len) {
|
|
|
|
|
var i1 = 0, i2 = 0, a, b, c, c2, row = row2;
|
|
|
|
|
while (i1 < s1_len) {
|
|
|
|
|
row[i1] = ++i1;
|
|
|
|
|
}
|
|
|
|
|
while (i2 < s2_len) {
|
|
|
|
|
c2 = s2.charCodeAt(i2);
|
|
|
|
|
a = i2;
|
|
|
|
|
++i2;
|
|
|
|
|
b = i2;
|
|
|
|
|
for (i1 = 0; i1 < s1_len; ++i1) {
|
|
|
|
|
c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0);
|
|
|
|
|
a = row[i1];
|
|
|
|
|
b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c);
|
|
|
|
|
row[i1] = b;
|
2014-07-03 21:07:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-22 12:14:28 +00:00
|
|
|
|
return b;
|
2014-07-03 21:07:16 +00:00
|
|
|
|
}
|
2015-05-22 12:14:28 +00:00
|
|
|
|
return s1_len + s2_len;
|
2014-07-03 21:07:16 +00:00
|
|
|
|
};
|
|
|
|
|
})();
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2014-03-16 08:08:56 +00:00
|
|
|
|
function initSearch(rawSearchIndex) {
|
|
|
|
|
var currentResults, index, searchIndex;
|
2014-07-03 21:07:16 +00:00
|
|
|
|
var MAX_LEV_DISTANCE = 3;
|
2014-03-16 08:08:56 +00:00
|
|
|
|
var params = getQueryStringParams();
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2014-02-21 07:15:08 +00:00
|
|
|
|
// Populate search bar with query string search term when provided,
|
|
|
|
|
// but only if the input bar is empty. This avoid the obnoxious issue
|
|
|
|
|
// where you start trying to do a search, and the index loads, and
|
|
|
|
|
// suddenly your search is gone!
|
2017-04-14 14:37:09 +00:00
|
|
|
|
if (document.getElementsByClassName("search-input")[0].value === "") {
|
|
|
|
|
document.getElementsByClassName("search-input")[0].value = params.search || '';
|
2014-02-21 07:15:08 +00:00
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2014-01-10 04:59:53 +00:00
|
|
|
|
/**
|
|
|
|
|
* Executes the query and builds an index of results
|
|
|
|
|
* @param {[Object]} query [The user query]
|
|
|
|
|
* @param {[type]} max [The maximum results returned]
|
2014-03-16 08:08:56 +00:00
|
|
|
|
* @param {[type]} searchWords [The list of search words to query
|
|
|
|
|
* against]
|
2014-01-10 04:59:53 +00:00
|
|
|
|
* @return {[type]} [A search index of results]
|
|
|
|
|
*/
|
2013-09-19 05:18:38 +00:00
|
|
|
|
function execQuery(query, max, searchWords) {
|
|
|
|
|
var valLower = query.query.toLowerCase(),
|
|
|
|
|
val = valLower,
|
2014-04-09 07:49:31 +00:00
|
|
|
|
typeFilter = itemTypeFromName(query.type),
|
2013-09-19 05:18:38 +00:00
|
|
|
|
results = [],
|
2014-01-10 04:59:53 +00:00
|
|
|
|
split = valLower.split("::");
|
|
|
|
|
|
2015-05-22 12:14:28 +00:00
|
|
|
|
// remove empty keywords
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (var j = 0; j < split.length; ++j) {
|
2014-01-10 04:59:53 +00:00
|
|
|
|
split[j].toLowerCase();
|
|
|
|
|
if (split[j] === "") {
|
|
|
|
|
split.splice(j, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2015-08-04 15:40:23 +00:00
|
|
|
|
function typePassesFilter(filter, type) {
|
|
|
|
|
// No filter
|
|
|
|
|
if (filter < 0) return true;
|
|
|
|
|
|
|
|
|
|
// Exact match
|
|
|
|
|
if (filter === type) return true;
|
|
|
|
|
|
|
|
|
|
// Match related items
|
|
|
|
|
var name = itemTypes[type];
|
|
|
|
|
switch (itemTypes[filter]) {
|
|
|
|
|
case "constant":
|
|
|
|
|
return (name == "associatedconstant");
|
|
|
|
|
case "fn":
|
|
|
|
|
return (name == "method" || name == "tymethod");
|
|
|
|
|
case "type":
|
|
|
|
|
return (name == "primitive");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// No match
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
|
// quoted values mean literal search
|
2014-04-08 17:47:52 +00:00
|
|
|
|
var nSearchWords = searchWords.length;
|
2014-03-16 08:08:56 +00:00
|
|
|
|
if ((val.charAt(0) === "\"" || val.charAt(0) === "'") &&
|
|
|
|
|
val.charAt(val.length - 1) === val.charAt(0))
|
|
|
|
|
{
|
2013-09-19 05:18:38 +00:00
|
|
|
|
val = val.substr(1, val.length - 2);
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (var i = 0; i < nSearchWords; ++i) {
|
2014-04-08 17:47:52 +00:00
|
|
|
|
if (searchWords[i] === val) {
|
2013-09-19 05:18:38 +00:00
|
|
|
|
// filter type: ... queries
|
2015-08-04 15:40:23 +00:00
|
|
|
|
if (typePassesFilter(typeFilter, searchIndex[i].ty)) {
|
2014-04-08 17:47:52 +00:00
|
|
|
|
results.push({id: i, index: -1});
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (results.length === max) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-25 23:03:06 +00:00
|
|
|
|
// searching by type
|
|
|
|
|
} else if (val.search("->") > -1) {
|
|
|
|
|
var trimmer = function (s) { return s.trim(); };
|
|
|
|
|
var parts = val.split("->").map(trimmer);
|
|
|
|
|
var input = parts[0];
|
|
|
|
|
// sort inputs so that order does not matter
|
2016-02-13 20:11:08 +00:00
|
|
|
|
var inputs = input.split(",").map(trimmer).sort().toString();
|
2015-02-25 23:03:06 +00:00
|
|
|
|
var output = parts[1];
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < nSearchWords; ++i) {
|
|
|
|
|
var type = searchIndex[i].type;
|
|
|
|
|
if (!type) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sort index inputs so that order does not matter
|
|
|
|
|
var typeInputs = type.inputs.map(function (input) {
|
|
|
|
|
return input.name;
|
|
|
|
|
}).sort();
|
|
|
|
|
|
|
|
|
|
// allow searching for void (no output) functions as well
|
|
|
|
|
var typeOutput = type.output ? type.output.name : "";
|
2016-02-13 20:11:08 +00:00
|
|
|
|
if ((inputs === "*" || inputs === typeInputs.toString()) &&
|
|
|
|
|
(output === "*" || output == typeOutput)) {
|
2015-02-25 23:03:06 +00:00
|
|
|
|
results.push({id: i, index: -1, dontValidate: true});
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
} else {
|
|
|
|
|
// gather matching search results up to a certain maximum
|
|
|
|
|
val = val.replace(/\_/g, "");
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (var i = 0; i < split.length; ++i) {
|
|
|
|
|
for (var j = 0; j < nSearchWords; ++j) {
|
|
|
|
|
var lev_distance;
|
2014-04-08 17:47:52 +00:00
|
|
|
|
if (searchWords[j].indexOf(split[i]) > -1 ||
|
|
|
|
|
searchWords[j].indexOf(val) > -1 ||
|
|
|
|
|
searchWords[j].replace(/_/g, "").indexOf(val) > -1)
|
2014-03-16 08:08:56 +00:00
|
|
|
|
{
|
2014-01-10 04:59:53 +00:00
|
|
|
|
// filter type: ... queries
|
2015-08-04 15:40:23 +00:00
|
|
|
|
if (typePassesFilter(typeFilter, searchIndex[j].ty)) {
|
2014-07-03 21:07:16 +00:00
|
|
|
|
results.push({
|
|
|
|
|
id: j,
|
|
|
|
|
index: searchWords[j].replace(/_/g, "").indexOf(val),
|
|
|
|
|
lev: 0,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (
|
2014-09-06 00:35:19 +00:00
|
|
|
|
(lev_distance = levenshtein(searchWords[j], val)) <=
|
2014-07-03 21:07:16 +00:00
|
|
|
|
MAX_LEV_DISTANCE) {
|
2015-08-04 15:40:23 +00:00
|
|
|
|
if (typePassesFilter(typeFilter, searchIndex[j].ty)) {
|
2014-07-03 21:07:16 +00:00
|
|
|
|
results.push({
|
|
|
|
|
id: j,
|
|
|
|
|
index: 0,
|
|
|
|
|
// we want lev results to go lower than others
|
|
|
|
|
lev: lev_distance,
|
|
|
|
|
});
|
2014-01-10 04:59:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (results.length === max) {
|
|
|
|
|
break;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-10 04:59:53 +00:00
|
|
|
|
|
2014-04-08 17:47:52 +00:00
|
|
|
|
var nresults = results.length;
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (var i = 0; i < nresults; ++i) {
|
2014-04-08 17:47:52 +00:00
|
|
|
|
results[i].word = searchWords[results[i].id];
|
|
|
|
|
results[i].item = searchIndex[results[i].id] || {};
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
// if there are no results then return to default and fail
|
|
|
|
|
if (results.length === 0) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 12:14:28 +00:00
|
|
|
|
results.sort(function sortResults(aaa, bbb) {
|
2014-04-14 18:39:59 +00:00
|
|
|
|
var a, b;
|
|
|
|
|
|
2014-07-03 21:07:16 +00:00
|
|
|
|
// Sort by non levenshtein results and then levenshtein results by the distance
|
|
|
|
|
// (less changes required to match means higher rankings)
|
|
|
|
|
a = (aaa.lev);
|
|
|
|
|
b = (bbb.lev);
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return a - b; }
|
2014-07-03 21:07:16 +00:00
|
|
|
|
|
2014-04-14 18:39:59 +00:00
|
|
|
|
// sort by crate (non-current crate goes later)
|
|
|
|
|
a = (aaa.item.crate !== window.currentCrate);
|
|
|
|
|
b = (bbb.item.crate !== window.currentCrate);
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return a - b; }
|
2014-04-14 18:39:59 +00:00
|
|
|
|
|
|
|
|
|
// sort by exact match (mismatch goes later)
|
|
|
|
|
a = (aaa.word !== valLower);
|
|
|
|
|
b = (bbb.word !== valLower);
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return a - b; }
|
2014-04-14 18:39:59 +00:00
|
|
|
|
|
|
|
|
|
// sort by item name length (longer goes later)
|
|
|
|
|
a = aaa.word.length;
|
|
|
|
|
b = bbb.word.length;
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return a - b; }
|
2014-04-14 18:39:59 +00:00
|
|
|
|
|
|
|
|
|
// sort by item name (lexicographically larger goes later)
|
|
|
|
|
a = aaa.word;
|
|
|
|
|
b = bbb.word;
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return (a > b ? +1 : -1); }
|
2014-04-14 18:39:59 +00:00
|
|
|
|
|
|
|
|
|
// sort by index of keyword in item name (no literal occurrence goes later)
|
|
|
|
|
a = (aaa.index < 0);
|
|
|
|
|
b = (bbb.index < 0);
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return a - b; }
|
2014-04-14 18:39:59 +00:00
|
|
|
|
// (later literal occurrence, if any, goes later)
|
|
|
|
|
a = aaa.index;
|
|
|
|
|
b = bbb.index;
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return a - b; }
|
|
|
|
|
|
2015-05-22 12:15:35 +00:00
|
|
|
|
// special precedence for primitive pages
|
|
|
|
|
if ((aaa.item.ty === TY_PRIMITIVE) && (bbb.item.ty !== TY_PRIMITIVE)) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2015-09-27 09:18:36 +00:00
|
|
|
|
if ((bbb.item.ty === TY_PRIMITIVE) && (aaa.item.ty !== TY_PRIMITIVE)) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2014-04-14 18:39:59 +00:00
|
|
|
|
|
|
|
|
|
// sort by description (no description goes later)
|
|
|
|
|
a = (aaa.item.desc === '');
|
|
|
|
|
b = (bbb.item.desc === '');
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return a - b; }
|
2014-04-14 18:39:59 +00:00
|
|
|
|
|
|
|
|
|
// sort by type (later occurrence in `itemTypes` goes later)
|
|
|
|
|
a = aaa.item.ty;
|
|
|
|
|
b = bbb.item.ty;
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return a - b; }
|
2014-04-14 18:39:59 +00:00
|
|
|
|
|
|
|
|
|
// sort by path (lexicographically larger goes later)
|
|
|
|
|
a = aaa.item.path;
|
|
|
|
|
b = bbb.item.path;
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (a !== b) { return (a > b ? +1 : -1); }
|
2014-04-14 18:39:59 +00:00
|
|
|
|
|
|
|
|
|
// que sera, sera
|
|
|
|
|
return 0;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
});
|
2014-04-14 18:39:59 +00:00
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
|
// remove duplicates, according to the data provided
|
2014-04-08 17:47:52 +00:00
|
|
|
|
for (var i = results.length - 1; i > 0; i -= 1) {
|
|
|
|
|
if (results[i].word === results[i - 1].word &&
|
2014-04-14 18:39:59 +00:00
|
|
|
|
results[i].item.ty === results[i - 1].item.ty &&
|
2014-12-04 04:52:23 +00:00
|
|
|
|
results[i].item.path === results[i - 1].item.path &&
|
|
|
|
|
(results[i].item.parent || {}).name === (results[i - 1].item.parent || {}).name)
|
2014-03-16 08:08:56 +00:00
|
|
|
|
{
|
2014-04-08 17:47:52 +00:00
|
|
|
|
results[i].id = -1;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (var i = 0; i < results.length; ++i) {
|
2014-01-10 04:59:53 +00:00
|
|
|
|
var result = results[i],
|
2014-04-08 17:47:52 +00:00
|
|
|
|
name = result.item.name.toLowerCase(),
|
|
|
|
|
path = result.item.path.toLowerCase(),
|
2014-04-09 16:27:35 +00:00
|
|
|
|
parent = result.item.parent;
|
2014-01-10 04:59:53 +00:00
|
|
|
|
|
2015-02-25 23:03:06 +00:00
|
|
|
|
// this validation does not make sense when searching by types
|
|
|
|
|
if (result.dontValidate) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 04:59:53 +00:00
|
|
|
|
var valid = validateResult(name, path, split, parent);
|
|
|
|
|
if (!valid) {
|
2014-04-08 17:47:52 +00:00
|
|
|
|
result.id = -1;
|
2014-01-10 04:59:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 04:59:53 +00:00
|
|
|
|
/**
|
2014-03-16 08:08:56 +00:00
|
|
|
|
* Validate performs the following boolean logic. For example:
|
|
|
|
|
* "File::open" will give IF A PARENT EXISTS => ("file" && "open")
|
|
|
|
|
* exists in (name || path || parent) OR => ("file" && "open") exists in
|
|
|
|
|
* (name || path )
|
|
|
|
|
*
|
|
|
|
|
* This could be written functionally, but I wanted to minimise
|
|
|
|
|
* functions on stack.
|
2014-01-10 04:59:53 +00:00
|
|
|
|
*
|
|
|
|
|
* @param {[string]} name [The name of the result]
|
|
|
|
|
* @param {[string]} path [The path of the result]
|
|
|
|
|
* @param {[string]} keys [The keys to be used (["file", "open"])]
|
|
|
|
|
* @param {[object]} parent [The parent of the result]
|
|
|
|
|
* @return {[boolean]} [Whether the result is valid or not]
|
|
|
|
|
*/
|
|
|
|
|
function validateResult(name, path, keys, parent) {
|
2015-05-22 12:14:28 +00:00
|
|
|
|
for (var i = 0; i < keys.length; ++i) {
|
2014-07-03 21:07:16 +00:00
|
|
|
|
// each check is for validation so we negate the conditions and invalidate
|
2014-09-06 00:35:19 +00:00
|
|
|
|
if (!(
|
2014-07-03 21:07:16 +00:00
|
|
|
|
// check for an exact name match
|
|
|
|
|
name.toLowerCase().indexOf(keys[i]) > -1 ||
|
|
|
|
|
// then an exact path match
|
|
|
|
|
path.toLowerCase().indexOf(keys[i]) > -1 ||
|
|
|
|
|
// next if there is a parent, check for exact parent match
|
2014-09-06 00:35:19 +00:00
|
|
|
|
(parent !== undefined &&
|
2014-07-03 21:07:16 +00:00
|
|
|
|
parent.name.toLowerCase().indexOf(keys[i]) > -1) ||
|
|
|
|
|
// lastly check to see if the name was a levenshtein match
|
2014-09-06 00:35:19 +00:00
|
|
|
|
levenshtein(name.toLowerCase(), keys[i]) <=
|
2014-07-03 21:07:16 +00:00
|
|
|
|
MAX_LEV_DISTANCE)) {
|
|
|
|
|
return false;
|
2014-01-10 04:59:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-03 21:07:16 +00:00
|
|
|
|
return true;
|
2014-01-10 04:59:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
|
function getQuery() {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var matches, type, query, raw =
|
|
|
|
|
document.getElementsByClassName('search-input')[0].value;
|
2014-08-09 13:38:10 +00:00
|
|
|
|
query = raw;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2015-08-04 15:40:23 +00:00
|
|
|
|
matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i);
|
2013-09-19 05:18:38 +00:00
|
|
|
|
if (matches) {
|
2015-08-04 15:40:23 +00:00
|
|
|
|
type = matches[1].replace(/^const$/, 'constant');
|
2013-09-19 05:18:38 +00:00
|
|
|
|
query = query.substring(matches[0].length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
2014-08-09 13:38:10 +00:00
|
|
|
|
raw: raw,
|
2013-09-19 05:18:38 +00:00
|
|
|
|
query: query,
|
|
|
|
|
type: type,
|
2015-05-22 12:14:28 +00:00
|
|
|
|
id: query + type
|
2013-09-19 05:18:38 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initSearchNav() {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var hoverTimeout;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var click_func = function(e) {
|
|
|
|
|
var el = e.target;
|
|
|
|
|
// to retrieve the real "owner" of the event.
|
|
|
|
|
while (el.tagName !== 'TR') {
|
|
|
|
|
el = el.parentNode;
|
|
|
|
|
}
|
|
|
|
|
var dst = e.target.getElementsByTagName('a');
|
|
|
|
|
if (dst.length < 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dst = dst[0];
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (window.location.pathname === dst.pathname) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
addClass(document.getElementById('search'), 'hidden');
|
|
|
|
|
removeClass(document.getElementById('main'), 'hidden');
|
2014-08-31 21:11:42 +00:00
|
|
|
|
document.location.href = dst.href;
|
2013-09-27 18:06:07 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
};
|
|
|
|
|
var mouseover_func = function(e) {
|
|
|
|
|
var el = e.target;
|
|
|
|
|
// to retrieve the real "owner" of the event.
|
|
|
|
|
while (el.tagName !== 'TR') {
|
|
|
|
|
el = el.parentNode;
|
|
|
|
|
}
|
2013-09-19 05:18:38 +00:00
|
|
|
|
clearTimeout(hoverTimeout);
|
2014-01-10 04:59:53 +00:00
|
|
|
|
hoverTimeout = setTimeout(function() {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
onEach(document.getElementsByClassName('search-results'), function(e) {
|
|
|
|
|
onEach(e.getElementsByClassName('result'), function(i_e) {
|
|
|
|
|
removeClass(i_e, 'highlighted');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
addClass(el, 'highlighted');
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}, 20);
|
2017-04-14 14:37:09 +00:00
|
|
|
|
};
|
|
|
|
|
onEach(document.getElementsByClassName('search-results'), function(e) {
|
|
|
|
|
onEach(e.getElementsByClassName('result'), function(i_e) {
|
|
|
|
|
i_e.onclick = click_func;
|
|
|
|
|
i_e.onmouseover = mouseover_func;
|
|
|
|
|
});
|
2013-09-19 05:18:38 +00:00
|
|
|
|
});
|
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var search_input = document.getElementsByClassName('search-input')[0];
|
|
|
|
|
search_input.onkeydown = null;
|
|
|
|
|
search_input.onkeydown = function(e) {
|
|
|
|
|
var actives = [];
|
|
|
|
|
onEach(document.getElementsByClassName('search-results'), function(e) {
|
|
|
|
|
onEach(document.getElementsByClassName('highlighted'), function(e) {
|
|
|
|
|
actives.push(e);
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
2014-06-18 18:25:04 +00:00
|
|
|
|
if (e.which === 38) { // up
|
2017-04-14 14:37:09 +00:00
|
|
|
|
if (!actives.length || !actives[0].previousElementSibling) {
|
2013-09-19 05:18:38 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
addClass(actives[0].previousElementSibling, 'highlighted');
|
|
|
|
|
removeClass(actives[0], 'highlighted');
|
2014-06-18 18:25:04 +00:00
|
|
|
|
} else if (e.which === 40) { // down
|
2017-04-14 14:37:09 +00:00
|
|
|
|
if (!actives.length) {
|
|
|
|
|
var results = document.getElementsByClassName('search-results');
|
|
|
|
|
if (results.length > 0) {
|
|
|
|
|
var res = results[0].getElementsByClassName('result');
|
|
|
|
|
if (res.length > 0) {
|
|
|
|
|
addClass(res[0], 'highlighted');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (actives[0].nextElementSibling) {
|
|
|
|
|
addClass(actives[0].nextElementSibling, 'highlighted');
|
|
|
|
|
removeClass(actives[0], 'highlighted');
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
2014-06-18 18:25:04 +00:00
|
|
|
|
} else if (e.which === 13) { // return
|
2017-04-14 14:37:09 +00:00
|
|
|
|
if (actives.length) {
|
|
|
|
|
document.location.href = actives[0].getElementsByTagName('a')[0].href;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
} else if (actives.length > 0) {
|
|
|
|
|
removeClass(actives[0], 'highlighted');
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
};
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 09:32:41 +00:00
|
|
|
|
function escape(content) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
let h1 = document.createElement('h1');
|
|
|
|
|
h1.textContent = content;
|
|
|
|
|
return h1.innerHTML;
|
2014-05-02 09:32:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
|
function showResults(results) {
|
|
|
|
|
var output, shown, query = getQuery();
|
|
|
|
|
|
|
|
|
|
currentResults = query.id;
|
2014-05-02 09:32:41 +00:00
|
|
|
|
output = '<h1>Results for ' + escape(query.query) +
|
|
|
|
|
(query.type ? ' (type: ' + escape(query.type) + ')' : '') + '</h1>';
|
2013-09-19 05:18:38 +00:00
|
|
|
|
output += '<table class="search-results">';
|
|
|
|
|
|
|
|
|
|
if (results.length > 0) {
|
|
|
|
|
shown = [];
|
|
|
|
|
|
2014-01-10 04:59:53 +00:00
|
|
|
|
results.forEach(function(item) {
|
2014-08-31 21:11:42 +00:00
|
|
|
|
var name, type, href, displayPath;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
|
|
|
|
if (shown.indexOf(item) !== -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shown.push(item);
|
|
|
|
|
name = item.name;
|
2014-04-09 07:49:31 +00:00
|
|
|
|
type = itemTypes[item.ty];
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
|
|
|
|
if (type === 'mod') {
|
2014-08-31 21:11:42 +00:00
|
|
|
|
displayPath = item.path + '::';
|
|
|
|
|
href = rootPath + item.path.replace(/::/g, '/') + '/' +
|
|
|
|
|
name + '/index.html';
|
2015-09-27 09:18:36 +00:00
|
|
|
|
} else if (type === "primitive") {
|
|
|
|
|
displayPath = "";
|
|
|
|
|
href = rootPath + item.path.replace(/::/g, '/') +
|
|
|
|
|
'/' + type + '.' + name + '.html';
|
2016-02-16 19:00:57 +00:00
|
|
|
|
} else if (type === "externcrate") {
|
|
|
|
|
displayPath = "";
|
|
|
|
|
href = rootPath + name + '/index.html';
|
2013-09-19 05:18:38 +00:00
|
|
|
|
} else if (item.parent !== undefined) {
|
2014-04-09 16:27:35 +00:00
|
|
|
|
var myparent = item.parent;
|
2013-09-27 17:40:41 +00:00
|
|
|
|
var anchor = '#' + type + '.' + name;
|
2016-08-13 14:54:14 +00:00
|
|
|
|
var parentType = itemTypes[myparent.ty];
|
|
|
|
|
if (parentType === "primitive") {
|
|
|
|
|
displayPath = myparent.name + '::';
|
|
|
|
|
} else {
|
|
|
|
|
displayPath = item.path + '::' + myparent.name + '::';
|
|
|
|
|
}
|
2014-08-31 21:11:42 +00:00
|
|
|
|
href = rootPath + item.path.replace(/::/g, '/') +
|
2016-08-13 14:54:14 +00:00
|
|
|
|
'/' + parentType +
|
2014-08-31 21:11:42 +00:00
|
|
|
|
'.' + myparent.name +
|
|
|
|
|
'.html' + anchor;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
} else {
|
2014-08-31 21:11:42 +00:00
|
|
|
|
displayPath = item.path + '::';
|
|
|
|
|
href = rootPath + item.path.replace(/::/g, '/') +
|
|
|
|
|
'/' + type + '.' + name + '.html';
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-31 21:11:42 +00:00
|
|
|
|
output += '<tr class="' + type + ' result"><td>' +
|
|
|
|
|
'<a href="' + href + '">' +
|
|
|
|
|
displayPath + '<span class="' + type + '">' +
|
|
|
|
|
name + '</span></a></td><td>' +
|
|
|
|
|
'<a href="' + href + '">' +
|
2016-12-12 18:39:36 +00:00
|
|
|
|
'<span class="desc">' + escape(item.desc) +
|
2014-08-31 21:11:42 +00:00
|
|
|
|
' </span></a></td></tr>';
|
2013-09-19 05:18:38 +00:00
|
|
|
|
});
|
|
|
|
|
} else {
|
2013-09-27 17:40:41 +00:00
|
|
|
|
output += 'No results :( <a href="https://duckduckgo.com/?q=' +
|
2014-01-10 04:59:53 +00:00
|
|
|
|
encodeURIComponent('rust ' + query.query) +
|
|
|
|
|
'">Try on DuckDuckGo?</a>';
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output += "</p>";
|
2017-04-14 14:37:09 +00:00
|
|
|
|
addClass(document.getElementById('main'), 'hidden');
|
|
|
|
|
var search = document.getElementById('search');
|
|
|
|
|
removeClass(search, 'hidden');
|
|
|
|
|
search.innerHTML = output;
|
|
|
|
|
var tds = search.getElementsByTagName('td');
|
|
|
|
|
var td_width = 0;
|
|
|
|
|
if (tds.length > 0) {
|
|
|
|
|
td_width = tds[0].offsetWidth;
|
|
|
|
|
}
|
|
|
|
|
var width = search.offsetWidth - 40 - td_width;
|
|
|
|
|
onEach(search.getElementsByClassName('desc'), function(e) {
|
|
|
|
|
e.style.width = width + 'px';
|
|
|
|
|
});
|
2013-09-19 05:18:38 +00:00
|
|
|
|
initSearchNav();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function search(e) {
|
2014-01-10 04:59:53 +00:00
|
|
|
|
var query,
|
|
|
|
|
filterdata = [],
|
|
|
|
|
obj, i, len,
|
2013-09-19 05:18:38 +00:00
|
|
|
|
results = [],
|
|
|
|
|
maxResults = 200,
|
|
|
|
|
resultIndex;
|
2014-01-23 01:44:27 +00:00
|
|
|
|
var params = getQueryStringParams();
|
2013-09-19 05:18:38 +00:00
|
|
|
|
|
|
|
|
|
query = getQuery();
|
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!query.query || query.id === currentResults) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-18 15:11:44 +00:00
|
|
|
|
// Update document title to maintain a meaningful browser history
|
2017-04-14 14:37:09 +00:00
|
|
|
|
document.title = "Results for " + query.query + " - Rust";
|
2015-06-18 15:11:44 +00:00
|
|
|
|
|
2014-03-16 08:08:56 +00:00
|
|
|
|
// Because searching is incremental by character, only the most
|
|
|
|
|
// recent search query is added to the browser history.
|
2014-01-23 01:44:27 +00:00
|
|
|
|
if (browserSupportsHistoryApi()) {
|
|
|
|
|
if (!history.state && !params.search) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
history.pushState(query, "", "?search=" + encodeURIComponent(query.raw));
|
2014-01-23 01:44:27 +00:00
|
|
|
|
} else {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
history.replaceState(query, "", "?search=" + encodeURIComponent(query.raw));
|
2014-01-23 01:44:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-19 05:18:38 +00:00
|
|
|
|
resultIndex = execQuery(query, 20000, index);
|
|
|
|
|
len = resultIndex.length;
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (i = 0; i < len; ++i) {
|
2014-04-08 17:47:52 +00:00
|
|
|
|
if (resultIndex[i].id > -1) {
|
|
|
|
|
obj = searchIndex[resultIndex[i].id];
|
2013-09-19 05:18:38 +00:00
|
|
|
|
filterdata.push([obj.name, obj.ty, obj.path, obj.desc]);
|
|
|
|
|
results.push(obj);
|
|
|
|
|
}
|
|
|
|
|
if (results.length >= maxResults) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showResults(results);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 07:49:31 +00:00
|
|
|
|
function itemTypeFromName(typename) {
|
|
|
|
|
for (var i = 0; i < itemTypes.length; ++i) {
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (itemTypes[i] === typename) { return i; }
|
2014-04-09 07:49:31 +00:00
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-16 08:08:56 +00:00
|
|
|
|
function buildIndex(rawSearchIndex) {
|
|
|
|
|
searchIndex = [];
|
|
|
|
|
var searchWords = [];
|
|
|
|
|
for (var crate in rawSearchIndex) {
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (!rawSearchIndex.hasOwnProperty(crate)) { continue; }
|
2014-03-16 08:08:56 +00:00
|
|
|
|
|
2016-02-16 19:00:57 +00:00
|
|
|
|
searchWords.push(crate);
|
|
|
|
|
searchIndex.push({
|
|
|
|
|
crate: crate,
|
|
|
|
|
ty: 1, // == ExternCrate
|
|
|
|
|
name: crate,
|
|
|
|
|
path: "",
|
|
|
|
|
desc: rawSearchIndex[crate].doc,
|
|
|
|
|
type: null,
|
|
|
|
|
});
|
|
|
|
|
|
2014-04-09 16:27:35 +00:00
|
|
|
|
// an array of [(Number) item type,
|
|
|
|
|
// (String) name,
|
2014-04-09 17:24:00 +00:00
|
|
|
|
// (String) full path or empty string for previous path,
|
2014-04-09 16:27:35 +00:00
|
|
|
|
// (String) description,
|
2015-02-25 23:03:06 +00:00
|
|
|
|
// (Number | null) the parent path index to `paths`]
|
|
|
|
|
// (Object | null) the type of the function (if any)
|
2014-04-09 16:27:35 +00:00
|
|
|
|
var items = rawSearchIndex[crate].items;
|
|
|
|
|
// an array of [(Number) item type,
|
|
|
|
|
// (String) name]
|
|
|
|
|
var paths = rawSearchIndex[crate].paths;
|
|
|
|
|
|
|
|
|
|
// convert `paths` into an object form
|
|
|
|
|
var len = paths.length;
|
|
|
|
|
for (var i = 0; i < len; ++i) {
|
|
|
|
|
paths[i] = {ty: paths[i][0], name: paths[i][1]};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// convert `items` into an object form, and construct word indices.
|
|
|
|
|
//
|
2014-03-16 08:08:56 +00:00
|
|
|
|
// before any analysis is performed lets gather the search terms to
|
|
|
|
|
// search against apart from the rest of the data. This is a quick
|
|
|
|
|
// operation that is cached for the life of the page state so that
|
|
|
|
|
// all other search operations have access to this cached data for
|
|
|
|
|
// faster analysis operations
|
2014-04-09 16:27:35 +00:00
|
|
|
|
var len = items.length;
|
2014-04-09 17:24:00 +00:00
|
|
|
|
var lastPath = "";
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (var i = 0; i < len; ++i) {
|
2014-04-09 16:27:35 +00:00
|
|
|
|
var rawRow = items[i];
|
2014-04-09 08:16:09 +00:00
|
|
|
|
var row = {crate: crate, ty: rawRow[0], name: rawRow[1],
|
2014-04-09 17:24:00 +00:00
|
|
|
|
path: rawRow[2] || lastPath, desc: rawRow[3],
|
2015-02-25 23:03:06 +00:00
|
|
|
|
parent: paths[rawRow[4]], type: rawRow[5]};
|
2014-04-09 08:16:09 +00:00
|
|
|
|
searchIndex.push(row);
|
|
|
|
|
if (typeof row.name === "string") {
|
|
|
|
|
var word = row.name.toLowerCase();
|
2014-03-16 08:08:56 +00:00
|
|
|
|
searchWords.push(word);
|
|
|
|
|
} else {
|
|
|
|
|
searchWords.push("");
|
|
|
|
|
}
|
2014-04-09 17:24:00 +00:00
|
|
|
|
lastPath = row.path;
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return searchWords;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startSearch() {
|
2015-09-29 20:47:01 +00:00
|
|
|
|
var searchTimeout;
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var callback = function() {
|
|
|
|
|
var search_input = document.getElementsByClassName('search-input');
|
|
|
|
|
if (search_input.length < 1) { return; }
|
|
|
|
|
search_input = search_input[0];
|
2015-09-29 20:47:01 +00:00
|
|
|
|
clearTimeout(searchTimeout);
|
2017-04-14 14:37:09 +00:00
|
|
|
|
if (search_input.value.length === 0) {
|
2016-03-17 15:49:15 +00:00
|
|
|
|
if (browserSupportsHistoryApi()) {
|
|
|
|
|
history.replaceState("", "std - Rust", "?search=");
|
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var main = document.getElementById('main');
|
|
|
|
|
if (hasClass(main, 'content')) {
|
|
|
|
|
removeClass(main, 'hidden');
|
|
|
|
|
}
|
|
|
|
|
var search_c = document.getElementById('search');
|
|
|
|
|
if (hasClass(search_c, 'content')) {
|
|
|
|
|
addClass(search_c, 'hidden');
|
|
|
|
|
}
|
2015-09-29 20:47:01 +00:00
|
|
|
|
} else {
|
|
|
|
|
searchTimeout = setTimeout(search, 500);
|
2015-10-01 18:30:35 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
};
|
|
|
|
|
var search_input = document.getElementsByClassName("search-input")[0];
|
|
|
|
|
search_input.onkeyup = callback;
|
|
|
|
|
search_input.oninput = callback;
|
|
|
|
|
document.getElementsByClassName("search-form")[0].onsubmit = function(e){
|
2015-09-29 20:47:01 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
clearTimeout(searchTimeout);
|
|
|
|
|
search();
|
2017-04-14 14:37:09 +00:00
|
|
|
|
};
|
|
|
|
|
search_input.onchange = function(e) {
|
2015-09-29 20:47:01 +00:00
|
|
|
|
// Do NOT e.preventDefault() here. It will prevent pasting.
|
|
|
|
|
clearTimeout(searchTimeout);
|
|
|
|
|
// zero-timeout necessary here because at the time of event handler execution the
|
|
|
|
|
// pasted content is not in the input field yet. Shouldn’t make any difference for
|
|
|
|
|
// change, though.
|
|
|
|
|
setTimeout(search, 0);
|
2017-04-14 14:37:09 +00:00
|
|
|
|
};
|
|
|
|
|
search_input.onpaste = search_input.onchange;
|
2014-03-16 08:08:56 +00:00
|
|
|
|
|
|
|
|
|
// Push and pop states are used to add search results to the browser
|
|
|
|
|
// history.
|
2014-01-23 01:44:27 +00:00
|
|
|
|
if (browserSupportsHistoryApi()) {
|
2015-07-02 03:28:54 +00:00
|
|
|
|
// Store the previous <title> so we can revert back to it later.
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var previousTitle = document.title;
|
2015-07-02 03:28:54 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
window.onpopstate = function(e) {
|
2014-01-23 01:44:27 +00:00
|
|
|
|
var params = getQueryStringParams();
|
2014-03-16 08:08:56 +00:00
|
|
|
|
// When browsing back from search results the main page
|
|
|
|
|
// visibility must be reset.
|
2014-01-23 01:44:27 +00:00
|
|
|
|
if (!params.search) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var main = document.getElementById('main');
|
|
|
|
|
if (hasClass(main, 'content')) {
|
|
|
|
|
removeClass(main, 'hidden');
|
|
|
|
|
}
|
|
|
|
|
var search = document.getElementById('search');
|
|
|
|
|
if (hasClass(main, 'content')) {
|
|
|
|
|
addClass(main, 'hidden');
|
|
|
|
|
}
|
2014-01-23 01:44:27 +00:00
|
|
|
|
}
|
2015-07-02 03:28:54 +00:00
|
|
|
|
// Revert to the previous title manually since the History
|
|
|
|
|
// API ignores the title parameter.
|
2017-04-14 14:37:09 +00:00
|
|
|
|
document.title = previousTitle;
|
2014-03-16 08:08:56 +00:00
|
|
|
|
// When browsing forward to search results the previous
|
|
|
|
|
// search will be repeated, so the currentResults are
|
|
|
|
|
// cleared to ensure the search is successful.
|
2014-01-23 01:44:27 +00:00
|
|
|
|
currentResults = null;
|
2014-02-21 07:15:08 +00:00
|
|
|
|
// Synchronize search bar with query string state and
|
2014-04-28 20:52:54 +00:00
|
|
|
|
// perform the search. This will empty the bar if there's
|
|
|
|
|
// nothing there, which lets you really go back to a
|
|
|
|
|
// previous state with nothing in the bar.
|
2017-04-14 14:37:09 +00:00
|
|
|
|
document.getElementsByClassName('search-input')[0].value = params.search;
|
2014-03-16 08:08:56 +00:00
|
|
|
|
// Some browsers fire 'onpopstate' for every page load
|
|
|
|
|
// (Chrome), while others fire the event only when actually
|
|
|
|
|
// popping a state (Firefox), which is why search() is
|
|
|
|
|
// called both here and at the end of the startSearch()
|
|
|
|
|
// function.
|
2014-01-23 01:44:27 +00:00
|
|
|
|
search();
|
2017-04-14 14:37:09 +00:00
|
|
|
|
};
|
2014-01-23 01:44:27 +00:00
|
|
|
|
}
|
|
|
|
|
search();
|
2013-09-19 05:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-16 08:08:56 +00:00
|
|
|
|
index = buildIndex(rawSearchIndex);
|
2013-09-19 05:18:38 +00:00
|
|
|
|
startSearch();
|
|
|
|
|
|
2014-03-16 08:08:56 +00:00
|
|
|
|
// Draw a convenient sidebar of known crates if we have a listing
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (rootPath === '../') {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var sidebar = document.getElementsByClassName('sidebar')[0];
|
|
|
|
|
var div = document.createElement('div');
|
|
|
|
|
div.className = 'block crate';
|
|
|
|
|
div.innerHTML = '<h3>Crates</h3>';
|
|
|
|
|
var ul = document.createElement('ul');
|
|
|
|
|
div.appendChild(ul);
|
2014-03-16 08:08:56 +00:00
|
|
|
|
|
|
|
|
|
var crates = [];
|
|
|
|
|
for (var crate in rawSearchIndex) {
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (!rawSearchIndex.hasOwnProperty(crate)) { continue; }
|
2014-03-16 08:08:56 +00:00
|
|
|
|
crates.push(crate);
|
|
|
|
|
}
|
|
|
|
|
crates.sort();
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (var i = 0; i < crates.length; ++i) {
|
2014-03-16 08:08:56 +00:00
|
|
|
|
var klass = 'crate';
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (crates[i] === window.currentCrate) {
|
2014-03-16 08:08:56 +00:00
|
|
|
|
klass += ' current';
|
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var link = document.createElement('a');
|
|
|
|
|
link.href = '../' + crates[i] + '/index.html';
|
|
|
|
|
link.title = rawSearchIndex[crates[i]].doc;
|
|
|
|
|
link.className = klass;
|
|
|
|
|
link.textContent = crates[i];
|
|
|
|
|
|
|
|
|
|
var li = document.createElement('li');
|
|
|
|
|
li.appendChild(link);
|
|
|
|
|
ul.appendChild(li);
|
2014-03-16 08:08:56 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
sidebar.appendChild(div);
|
2014-03-16 08:08:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-04 19:24:20 +00:00
|
|
|
|
|
2014-03-16 08:08:56 +00:00
|
|
|
|
window.initSearch = initSearch;
|
2014-05-21 23:41:58 +00:00
|
|
|
|
|
2015-03-05 07:35:43 +00:00
|
|
|
|
// delayed sidebar rendering.
|
|
|
|
|
function initSidebarItems(items) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var sidebar = document.getElementsByClassName('sidebar')[0];
|
2015-03-05 07:35:43 +00:00
|
|
|
|
var current = window.sidebarCurrent;
|
|
|
|
|
|
|
|
|
|
function block(shortty, longty) {
|
|
|
|
|
var filtered = items[shortty];
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (!filtered) { return; }
|
2015-03-05 07:35:43 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var div = document.createElement('div');
|
|
|
|
|
div.className = 'block ' + shortty;
|
|
|
|
|
var h3 = document.createElement('h3');
|
|
|
|
|
h3.textContent = longty;
|
|
|
|
|
div.appendChild(h3);
|
|
|
|
|
var ul = document.createElement('ul');
|
2015-03-05 07:35:43 +00:00
|
|
|
|
|
|
|
|
|
for (var i = 0; i < filtered.length; ++i) {
|
|
|
|
|
var item = filtered[i];
|
|
|
|
|
var name = item[0];
|
|
|
|
|
var desc = item[1]; // can be null
|
|
|
|
|
|
|
|
|
|
var klass = shortty;
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (name === current.name && shortty === current.ty) {
|
2015-03-05 07:35:43 +00:00
|
|
|
|
klass += ' current';
|
|
|
|
|
}
|
|
|
|
|
var path;
|
|
|
|
|
if (shortty === 'mod') {
|
|
|
|
|
path = name + '/index.html';
|
|
|
|
|
} else {
|
|
|
|
|
path = shortty + '.' + name + '.html';
|
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var link = document.createElement('a');
|
|
|
|
|
link.href = current.relpath + path;
|
|
|
|
|
link.title = desc;
|
|
|
|
|
link.className = klass;
|
|
|
|
|
link.textContent = name;
|
|
|
|
|
var li = document.createElement('li');
|
|
|
|
|
li.appendChild(link);
|
|
|
|
|
ul.appendChild(li);
|
2015-03-05 07:35:43 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
div.appendChild(ul);
|
|
|
|
|
sidebar.appendChild(div);
|
2015-03-05 07:35:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 22:19:57 +00:00
|
|
|
|
block("primitive", "Primitive Types");
|
2015-03-05 07:35:43 +00:00
|
|
|
|
block("mod", "Modules");
|
2016-06-19 22:19:57 +00:00
|
|
|
|
block("macro", "Macros");
|
2015-03-05 07:35:43 +00:00
|
|
|
|
block("struct", "Structs");
|
|
|
|
|
block("enum", "Enums");
|
2016-06-19 22:19:57 +00:00
|
|
|
|
block("constant", "Constants");
|
|
|
|
|
block("static", "Statics");
|
2015-03-05 07:35:43 +00:00
|
|
|
|
block("trait", "Traits");
|
|
|
|
|
block("fn", "Functions");
|
2016-06-19 22:19:57 +00:00
|
|
|
|
block("type", "Type Definitions");
|
2015-03-05 07:35:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.initSidebarItems = initSidebarItems;
|
|
|
|
|
|
2014-05-21 23:41:58 +00:00
|
|
|
|
window.register_implementors = function(imp) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var list = document.getElementById('implementors-list');
|
2014-05-21 23:41:58 +00:00
|
|
|
|
var libs = Object.getOwnPropertyNames(imp);
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (var i = 0; i < libs.length; ++i) {
|
2015-05-22 12:14:28 +00:00
|
|
|
|
if (libs[i] === currentCrate) { continue; }
|
2014-05-28 00:52:40 +00:00
|
|
|
|
var structs = imp[libs[i]];
|
2014-07-03 21:07:16 +00:00
|
|
|
|
for (var j = 0; j < structs.length; ++j) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var code = document.createElement('code');
|
|
|
|
|
code.innerHTML = structs[j];
|
|
|
|
|
|
|
|
|
|
var x = code.getElementsByTagName('a');
|
|
|
|
|
for (var i = 0; i < x.length; i++) {
|
|
|
|
|
var href = x[i].href;
|
2015-01-07 04:48:06 +00:00
|
|
|
|
if (href && href.indexOf('http') !== 0) {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
x[i].href = rootPath + href;
|
2014-06-01 17:17:30 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
var li = document.createElement('li');
|
|
|
|
|
li.appendChild(code);
|
|
|
|
|
list.appendChild(li);
|
2014-05-21 23:41:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if (window.pending_implementors) {
|
|
|
|
|
window.register_implementors(window.pending_implementors);
|
|
|
|
|
}
|
2014-05-24 03:17:27 +00:00
|
|
|
|
|
2015-05-07 07:53:21 +00:00
|
|
|
|
function labelForToggleButton(sectionIsCollapsed) {
|
|
|
|
|
if (sectionIsCollapsed) {
|
|
|
|
|
// button will expand the section
|
|
|
|
|
return "+";
|
|
|
|
|
}
|
2015-05-22 12:14:28 +00:00
|
|
|
|
// button will collapse the section
|
|
|
|
|
// note that this text is also set in the HTML template in render.rs
|
|
|
|
|
return "\u2212"; // "\u2212" is '−' minus sign
|
2015-05-07 07:53:21 +00:00
|
|
|
|
}
|
2015-05-07 08:17:10 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
function onEveryMatchingChild(elem, className, func) {
|
|
|
|
|
if (elem && className && func) {
|
|
|
|
|
for (var i = 0; i < elem.childNodes.length; i++) {
|
|
|
|
|
if (hasClass(elem.childNodes[i], className)) {
|
|
|
|
|
func(elem.childNodes[i]);
|
|
|
|
|
} else {
|
|
|
|
|
onEveryMatchingChild(elem.childNodes[i], className, func);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-21 02:21:35 +00:00
|
|
|
|
function toggleAllDocs() {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var toggle = document.getElementById("toggle-all-docs");
|
|
|
|
|
if (hasClass(toggle, "will-expand")) {
|
|
|
|
|
removeClass(toggle, "will-expand");
|
|
|
|
|
onEveryMatchingChild(toggle, "inner", function(e) {
|
|
|
|
|
e.innerHTML = labelForToggleButton(false);
|
|
|
|
|
});
|
|
|
|
|
toggle.title = "collapse all docs";
|
|
|
|
|
onEach(document.getElementsByClassName("docblock"), function(e) {
|
|
|
|
|
e.style.display = 'block';
|
|
|
|
|
});
|
|
|
|
|
onEach(document.getElementsByClassName("toggle-label"), function(e) {
|
|
|
|
|
e.style.display = 'none';
|
|
|
|
|
});
|
|
|
|
|
onEach(document.getElementsByClassName("toggle-wrapper"), function(e) {
|
|
|
|
|
removeClass(e, "collapsed");
|
|
|
|
|
});
|
|
|
|
|
onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
|
|
|
|
|
onEveryMatchingChild(e, "inner", function(i_e) {
|
|
|
|
|
i_e.innerHTML = labelForToggleButton(false);
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-05-07 07:53:21 +00:00
|
|
|
|
} else {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
addClass(toggle, "will-expand");
|
|
|
|
|
onEveryMatchingChild(toggle, "inner", function(e) {
|
|
|
|
|
e.innerHTML = labelForToggleButton(true);
|
|
|
|
|
});
|
|
|
|
|
toggle.title = "expand all docs";
|
|
|
|
|
onEach(document.getElementsByClassName("docblock"), function(e) {
|
|
|
|
|
e.style.display = 'none';
|
|
|
|
|
});
|
|
|
|
|
onEach(document.getElementsByClassName("toggle-label"), function(e) {
|
|
|
|
|
e.style.display = 'inline-block';
|
|
|
|
|
});
|
|
|
|
|
onEach(document.getElementsByClassName("toggle-wrapper"), function(e) {
|
|
|
|
|
addClass(e, "collapsed");
|
|
|
|
|
});
|
|
|
|
|
onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
|
|
|
|
|
onEveryMatchingChild(e, "inner", function(i_e) {
|
|
|
|
|
i_e.innerHTML = labelForToggleButton(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-04-22 16:50:19 +00:00
|
|
|
|
}
|
2016-05-21 02:21:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
function collapseDocs(toggle) {
|
|
|
|
|
if (!toggle || !toggle.parentNode) {
|
|
|
|
|
return;
|
2015-04-22 17:32:59 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var relatedDoc = toggle.parentNode.nextElementSibling;
|
|
|
|
|
if (hasClass(relatedDoc, "stability")) {
|
|
|
|
|
relatedDoc = relatedDoc.nextElementSibling;
|
|
|
|
|
}
|
|
|
|
|
if (hasClass(relatedDoc, "docblock")) {
|
|
|
|
|
if (!isHidden(relatedDoc)) {
|
|
|
|
|
relatedDoc.style.display = 'none';
|
|
|
|
|
onEach(toggle.childNodes, function(e) {
|
|
|
|
|
if (hasClass(e, 'toggle-label')) {
|
|
|
|
|
e.style.display = 'inline-block';
|
|
|
|
|
}
|
|
|
|
|
if (hasClass(e, 'inner')) {
|
|
|
|
|
e.innerHTML = labelForToggleButton(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
addClass(toggle.parentNode, 'collapsed');
|
2014-07-31 01:31:34 +00:00
|
|
|
|
} else {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
relatedDoc.style.display = 'block';
|
|
|
|
|
removeClass(toggle.parentNode, 'collapsed');
|
|
|
|
|
onEach(toggle.childNodes, function(e) {
|
|
|
|
|
if (hasClass(e, 'toggle-label')) {
|
|
|
|
|
e.style.display = 'none';
|
|
|
|
|
}
|
|
|
|
|
if (hasClass(e, 'inner')) {
|
|
|
|
|
e.innerHTML = labelForToggleButton(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-07-31 01:31:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-06 20:06:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var x = document.getElementById('toggle-all-docs');
|
|
|
|
|
if (x) {
|
|
|
|
|
x.onclick = toggleAllDocs;
|
|
|
|
|
}
|
2016-11-06 20:06:20 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
function insertAfter(newNode, referenceNode) {
|
|
|
|
|
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
|
|
|
|
|
}
|
2014-07-31 01:31:34 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var toggle = document.createElement('a');
|
|
|
|
|
toggle.href = 'javascript:void(0)';
|
|
|
|
|
toggle.className = 'collapse-toggle';
|
|
|
|
|
toggle.innerHTML = "[<span class='inner'>"+labelForToggleButton(false)+"</span>]";
|
2014-07-31 01:31:34 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var func = function(e) {
|
|
|
|
|
var next = e.nextElementSibling;
|
|
|
|
|
if (!next) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (hasClass(next, 'docblock') ||
|
|
|
|
|
(hasClass(next, 'stability') &&
|
|
|
|
|
hasClass(next.nextElementSibling, 'docblock'))) {
|
|
|
|
|
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onEach(document.getElementsByClassName('method'), func);
|
|
|
|
|
onEach(document.getElementsByClassName('impl-items'), function(e) {
|
|
|
|
|
onEach(e.getElementsByClassName('associatedconstant'), func);
|
|
|
|
|
});
|
2014-07-31 01:31:34 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var span = document.createElement('span');
|
|
|
|
|
span.className = 'toggle-label';
|
|
|
|
|
span.style.display = 'none';
|
|
|
|
|
span.innerHTML = ' Expand description';
|
2016-11-11 22:41:00 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var mainToggle = toggle.cloneNode(true);
|
|
|
|
|
mainToggle.appendChild(span);
|
2014-07-31 01:31:34 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
var wrapper = document.createElement('div');
|
|
|
|
|
wrapper.className = 'toggle-wrapper';
|
|
|
|
|
wrapper.appendChild(mainToggle);
|
2014-12-19 18:56:47 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
onEach(document.getElementById('main').getElementsByClassName('docblock'), function(e) {
|
|
|
|
|
if (e.parentNode.id === "main") {
|
|
|
|
|
e.parentNode.insertBefore(wrapper, e);
|
2014-12-19 18:56:47 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
});
|
2014-12-19 18:56:47 +00:00
|
|
|
|
|
2017-04-14 14:37:09 +00:00
|
|
|
|
onEach(document.getElementsByClassName('docblock'), function(e) {
|
|
|
|
|
if (hasClass(e, 'autohide')) {
|
|
|
|
|
var wrap = e.previousElementSibling;
|
|
|
|
|
if (wrap && hasClass(wrap, 'toggle-wrapper')) {
|
|
|
|
|
var toggle = wrap.childNodes[0];
|
|
|
|
|
if (e.childNodes[0].tagName === 'H3') {
|
|
|
|
|
onEach(toggle.getElementsByClassName('toggle-label'), function(i_e) {
|
|
|
|
|
i_e.innerHTML = " Show " + e.childNodes[0].innerHTML;
|
|
|
|
|
});
|
2014-12-19 18:56:47 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
e.style.display = 'none';
|
|
|
|
|
addClass(wrap, 'collapsed');
|
|
|
|
|
onEach(toggle.getElementsByClassName('inner'), function(e) {
|
|
|
|
|
e.innerHTML = labelForToggleButton(true);
|
|
|
|
|
});
|
|
|
|
|
onEach(toggle.getElementsByClassName('toggle-label'), function(e) {
|
|
|
|
|
e.style.display = 'block';
|
|
|
|
|
});
|
2014-12-19 18:56:47 +00:00
|
|
|
|
}
|
2017-04-14 14:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
var span = document.createElement('span');
|
|
|
|
|
span.className = 'toggle-label';
|
|
|
|
|
span.style.display = 'none';
|
|
|
|
|
span.innerHTML = ' Expand attributes';
|
|
|
|
|
toggle.appendChild(span);
|
|
|
|
|
|
|
|
|
|
var wrapper = document.createElement('div');
|
|
|
|
|
wrapper.className = 'toggle-wrapper toggle-attributes';
|
|
|
|
|
wrapper.appendChild(toggle);
|
|
|
|
|
onEach(document.getElementById('main').getElementsByTagName('pre'), function(e) {
|
|
|
|
|
onEach(e.getElementsByClassName('attributes'), function(i_e) {
|
|
|
|
|
i_e.parentNode.insertBefore(wrapper, i_e);
|
|
|
|
|
collapseDocs(i_e.previousSibling.childNodes[0]);
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-01-15 01:09:50 +00:00
|
|
|
|
}());
|
2015-07-14 00:56:31 +00:00
|
|
|
|
|
|
|
|
|
// Sets the focus on the search bar at the top of the page
|
|
|
|
|
function focusSearchBar() {
|
2017-04-14 14:37:09 +00:00
|
|
|
|
document.getElementsByClassName('search-input')[0].focus();
|
2015-07-14 00:56:31 +00:00
|
|
|
|
}
|