mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-18 02:56:39 +00:00
Redirect to first term when pressing enter on docs search
This commit is contained in:
parent
e71c556ca7
commit
6839bfcc2d
@ -1,7 +1,7 @@
|
|||||||
root = document.getElementById("main_div");
|
root = document.getElementById("main_div");
|
||||||
root.innerHTML = `
|
root.innerHTML = `
|
||||||
<!-- You can append '?q=query' to the URL to default to a search -->
|
<!-- You can append '?q=query' to the URL to default to a search -->
|
||||||
<input id="searchBox" type="text" onkeyup="updateSearch()"
|
<input id="searchBox" type="text" onkeydown="updateSearch(event)"
|
||||||
placeholder="Search for requests and types…" />
|
placeholder="Search for requests and types…" />
|
||||||
|
|
||||||
<div id="searchDiv">
|
<div id="searchDiv">
|
||||||
@ -11,17 +11,17 @@ root.innerHTML = `
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<details open><summary class="title">Methods (<span id="methodsCount">0</span>)</summary>
|
<details id="methods" open><summary class="title">Methods (<span id="methodsCount">0</span>)</summary>
|
||||||
<ul id="methodsList" class="together">
|
<ul id="methodsList" class="together">
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details open><summary class="title">Types (<span id="typesCount">0</span>)</summary>
|
<details id="types" open><summary class="title">Types (<span id="typesCount">0</span>)</summary>
|
||||||
<ul id="typesList" class="together">
|
<ul id="typesList" class="together">
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details><summary class="title">Constructors (<span id="constructorsCount">0</span>)</summary>
|
<details id="constructors"><summary class="title">Constructors (<span id="constructorsCount">0</span>)</summary>
|
||||||
<ul id="constructorsList" class="together">
|
<ul id="constructorsList" class="together">
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
@ -35,12 +35,15 @@ searchDiv = document.getElementById("searchDiv");
|
|||||||
searchBox = document.getElementById("searchBox");
|
searchBox = document.getElementById("searchBox");
|
||||||
|
|
||||||
// Search lists
|
// Search lists
|
||||||
|
methodsDetails = document.getElementById("methods");
|
||||||
methodsList = document.getElementById("methodsList");
|
methodsList = document.getElementById("methodsList");
|
||||||
methodsCount = document.getElementById("methodsCount");
|
methodsCount = document.getElementById("methodsCount");
|
||||||
|
|
||||||
|
typesDetails = document.getElementById("types");
|
||||||
typesList = document.getElementById("typesList");
|
typesList = document.getElementById("typesList");
|
||||||
typesCount = document.getElementById("typesCount");
|
typesCount = document.getElementById("typesCount");
|
||||||
|
|
||||||
|
constructorsDetails = document.getElementById("constructors");
|
||||||
constructorsList = document.getElementById("constructorsList");
|
constructorsList = document.getElementById("constructorsList");
|
||||||
constructorsCount = document.getElementById("constructorsCount");
|
constructorsCount = document.getElementById("constructorsCount");
|
||||||
|
|
||||||
@ -153,46 +156,55 @@ function buildList(countSpan, resultList, foundElements) {
|
|||||||
resultList.innerHTML = result;
|
resultList.innerHTML = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateSearch() {
|
function updateSearch(event) {
|
||||||
if (searchBox.value) {
|
var query = searchBox.value.toLowerCase();
|
||||||
contentDiv.style.display = "none";
|
if (!query) {
|
||||||
searchDiv.style.display = "";
|
|
||||||
|
|
||||||
var query = searchBox.value.toLowerCase();
|
|
||||||
|
|
||||||
var foundRequests = getSearchArray(requests, requestsu, query);
|
|
||||||
var foundTypes = getSearchArray(types, typesu, query);
|
|
||||||
var foundConstructors = getSearchArray(
|
|
||||||
constructors, constructorsu, query
|
|
||||||
);
|
|
||||||
|
|
||||||
buildList(methodsCount, methodsList, foundRequests);
|
|
||||||
buildList(typesCount, typesList, foundTypes);
|
|
||||||
buildList(constructorsCount, constructorsList, foundConstructors);
|
|
||||||
|
|
||||||
// Now look for exact matches
|
|
||||||
var original = requests.concat(constructors);
|
|
||||||
var originalu = requestsu.concat(constructorsu);
|
|
||||||
var destination = [];
|
|
||||||
var destinationu = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < original.length; ++i) {
|
|
||||||
if (original[i].toLowerCase().replace("request", "") == query) {
|
|
||||||
destination.push(original[i]);
|
|
||||||
destinationu.push(originalu[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (destination.length == 0) {
|
|
||||||
exactMatch.style.display = "none";
|
|
||||||
} else {
|
|
||||||
exactMatch.style.display = "";
|
|
||||||
buildList(null, exactList, [destination, destinationu]);
|
|
||||||
return destinationu[0];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
contentDiv.style.display = "";
|
contentDiv.style.display = "";
|
||||||
searchDiv.style.display = "none";
|
searchDiv.style.display = "none";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
contentDiv.style.display = "none";
|
||||||
|
searchDiv.style.display = "";
|
||||||
|
|
||||||
|
var foundRequests = getSearchArray(requests, requestsu, query);
|
||||||
|
var foundTypes = getSearchArray(types, typesu, query);
|
||||||
|
var foundConstructors = getSearchArray(constructors, constructorsu, query);
|
||||||
|
|
||||||
|
if (event && event.keyCode == 13) {
|
||||||
|
if (methodsDetails.open && foundRequests[1].length) {
|
||||||
|
window.location = foundRequests[1][0];
|
||||||
|
} else if (typesDetails.open && foundTypes[1].length) {
|
||||||
|
window.location = foundTypes[1][0];
|
||||||
|
} else if (constructorsDetails.open && foundConstructors[1].length) {
|
||||||
|
window.location = foundConstructors[1][0];
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildList(methodsCount, methodsList, foundRequests);
|
||||||
|
buildList(typesCount, typesList, foundTypes);
|
||||||
|
buildList(constructorsCount, constructorsList, foundConstructors);
|
||||||
|
|
||||||
|
// Now look for exact matches
|
||||||
|
var original = requests.concat(constructors);
|
||||||
|
var originalu = requestsu.concat(constructorsu);
|
||||||
|
var destination = [];
|
||||||
|
var destinationu = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < original.length; ++i) {
|
||||||
|
if (original[i].toLowerCase().replace("request", "") == query) {
|
||||||
|
destination.push(original[i]);
|
||||||
|
destinationu.push(originalu[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (destination.length == 0) {
|
||||||
|
exactMatch.style.display = "none";
|
||||||
|
} else {
|
||||||
|
exactMatch.style.display = "";
|
||||||
|
buildList(null, exactList, [destination, destinationu]);
|
||||||
|
return destinationu[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user