mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-15 13:26:32 +00:00
Let constructors be searched on the docs, and allow collapsing types
This commit is contained in:
@@ -19,7 +19,21 @@
|
||||
placeholder="Search for requests and types…" />
|
||||
|
||||
<div id="searchDiv">
|
||||
<table id="searchTable"></table>
|
||||
|
||||
<details open><summary class="title">Methods (<span id="methodsCount">0</span>)</summary>
|
||||
<ul id="methodsList" class="together">
|
||||
</ul>
|
||||
</details>
|
||||
|
||||
<details open><summary class="title">Types (<span id="typesCount">0</span>)</summary>
|
||||
<ul id="typesList" class="together">
|
||||
</ul>
|
||||
</details>
|
||||
|
||||
<details><summary class="title">Constructors (<span id="constructorsCount">0</span>)</summary>
|
||||
<ul id="constructorsList" class="together">
|
||||
</ul>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<div id="contentDiv">
|
||||
@@ -196,19 +210,65 @@ messages = result.messages</pre>
|
||||
contentDiv = document.getElementById("contentDiv");
|
||||
searchDiv = document.getElementById("searchDiv");
|
||||
searchBox = document.getElementById("searchBox");
|
||||
searchTable = document.getElementById("searchTable");
|
||||
|
||||
// Search lists
|
||||
methodsList = document.getElementById("methodsList");
|
||||
methodsCount = document.getElementById("methodsCount");
|
||||
|
||||
typesList = document.getElementById("typesList");
|
||||
typesCount = document.getElementById("typesCount");
|
||||
|
||||
constructorsList = document.getElementById("constructorsList");
|
||||
constructorsCount = document.getElementById("constructorsCount");
|
||||
|
||||
try {
|
||||
requests = [{request_names}];
|
||||
types = [{type_names}];
|
||||
constructors = [{constructor_names}];
|
||||
|
||||
requestsu = [{request_urls}];
|
||||
typesu = [{type_urls}];
|
||||
constructorsu = [{constructor_urls}];
|
||||
} catch (e) {
|
||||
requests = [];
|
||||
types = [];
|
||||
requetsu = [];
|
||||
constructors = [];
|
||||
requestsu = [];
|
||||
typesu = [];
|
||||
constructorsu = [];
|
||||
}
|
||||
|
||||
// Given two input arrays "original" and "original urls" and a query,
|
||||
// return a pair of arrays with matching "query" elements from "original".
|
||||
//
|
||||
// TODO Perhaps return an array of pairs instead a pair of arrays (for cache).
|
||||
function getSearchArray(original, originalu, query) {
|
||||
var destination = [];
|
||||
var destinationu = [];
|
||||
|
||||
for (var i = 0; i < original.length; ++i) {
|
||||
if (original[i].toLowerCase().indexOf(query) != -1) {
|
||||
destination.push(original[i]);
|
||||
destinationu.push(originalu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return [destination, destinationu];
|
||||
}
|
||||
|
||||
// Modify "countSpan" and "resultList" accordingly based on the elements
|
||||
// given as [[elements], [element urls]] (both with the same length)
|
||||
function buildList(countSpan, resultList, foundElements) {
|
||||
var result = "";
|
||||
for (var i = 0; i < foundElements[0].length; ++i) {
|
||||
result += '<li>';
|
||||
result += '<a href="' + foundElements[1][i] + '">';
|
||||
result += foundElements[0][i];
|
||||
result += '</a></li>';
|
||||
}
|
||||
|
||||
countSpan.innerHTML = "" + foundElements[0].length;
|
||||
resultList.innerHTML = result;
|
||||
}
|
||||
|
||||
function updateSearch() {
|
||||
@@ -217,46 +277,16 @@ function updateSearch() {
|
||||
searchDiv.style.display = "";
|
||||
|
||||
var query = searchBox.value.toLowerCase();
|
||||
var foundRequests = [];
|
||||
var foundRequestsu = [];
|
||||
for (var i = 0; i < requests.length; ++i) {
|
||||
if (requests[i].toLowerCase().indexOf(query) != -1) {
|
||||
foundRequests.push(requests[i]);
|
||||
foundRequestsu.push(requestsu[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var foundTypes = [];
|
||||
var foundTypesu = [];
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
if (types[i].toLowerCase().indexOf(query) != -1) {
|
||||
foundTypes.push(types[i]);
|
||||
foundTypesu.push(typesu[i]);
|
||||
}
|
||||
}
|
||||
var foundRequests = getSearchArray(requests, requestsu, query);
|
||||
var foundTypes = getSearchArray(types, typesu, query);
|
||||
var foundConstructors = getSearchArray(
|
||||
constructors, constructorsu, query
|
||||
);
|
||||
|
||||
var top = foundRequests.length > foundTypes.length ?
|
||||
foundRequests.length : foundTypes.length;
|
||||
|
||||
result = "";
|
||||
for (var i = 0; i <= top; ++i) {
|
||||
result += "<tr><td>";
|
||||
|
||||
if (i < foundRequests.length) {
|
||||
result +=
|
||||
'<a href="'+foundRequestsu[i]+'">'+foundRequests[i]+'</a>';
|
||||
}
|
||||
|
||||
result += "</td><td>";
|
||||
|
||||
if (i < foundTypes.length) {
|
||||
result +=
|
||||
'<a href="'+foundTypesu[i]+'">'+foundTypes[i]+'</a>';
|
||||
}
|
||||
|
||||
result += "</td></tr>";
|
||||
}
|
||||
searchTable.innerHTML = result;
|
||||
buildList(methodsCount, methodsList, foundRequests);
|
||||
buildList(typesCount, typesList, foundTypes);
|
||||
buildList(constructorsCount, constructorsList, foundConstructors);
|
||||
} else {
|
||||
contentDiv.style.display = "";
|
||||
searchDiv.style.display = "none";
|
||||
|
||||
Reference in New Issue
Block a user