-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearcher.js
56 lines (44 loc) · 1.74 KB
/
searcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var dlgArea = document.getElementById("searchResultDlg");
var searchInput = document.getElementById("searchInput");
var searchResultDlgContent = document.getElementById("searchResultDlgContent");
var dataArray = [];
function initDataArray(){
var allNodes = document.getElementsByTagName("code");
for(var i = 0; i < allNodes.length; i++){
if (allNodes[i].parentElement.localName == "pre"){
dataArray[i] = [allNodes[i].parentElement.previousSibling.nodeValue.trim(), allNodes[i].innerHTML, allNodes[i].parentElement.parentElement.previousElementSibling.innerHTML];
}
}
}
function searchAndDisplay(value){
var indexToDisplay = [];
for (var i in dataArray){
if(dataArray[i][0].indexOf(value) != -1 || dataArray[i][1].indexOf(value) != -1){
indexToDisplay.push(i);
}
}
if(indexToDisplay.length == 0){
searchResultDlgContent.innerHTML = "There is no matched data to display :(";
return;
}
var finalOutput = "";
for (var j in indexToDisplay){
var tempOutput = "";
tempOutput = "<div class='resultBlock'><div class='tabName'>" + dataArray[indexToDisplay[j]][2] + "</div><div class='title'>" + dataArray[indexToDisplay[j]][0] + "</div><div class='content'><pre><code>" + dataArray[indexToDisplay[j]][1] + "</code></pre></div></div>";
finalOutput += tempOutput;
}
searchResultDlgContent.innerHTML = finalOutput;
}
function onCloseDlg() {
dlgArea.style.display = "none";
searchInput.value = "";
}
function onTypeSearchInput(event){
var value = searchInput.value;
if(value.length > 0 ){
searchAndDisplay(value);
dlgArea.style.display = "flex";
}else{
dlgArea.style.display = "none";
}
}