This commit is contained in:
GitJournal 2024-01-10 15:14:43 +08:00
parent 88fbe61b3e
commit 2bcd460f2d
1 changed files with 409 additions and 386 deletions

View File

@ -189,6 +189,8 @@
.right-half { .right-half {
/*padding-left: 10px;*/ /*padding-left: 10px;*/
padding-right: 10px; padding-right: 10px;
overflow-y:auto;
overflow-x:auto;
} }
.left-half { .left-half {
@ -245,20 +247,27 @@
display: flex; display: flex;
border: 1px solid #ccc; border: 1px solid #ccc;
/* justify-content: space-between; */ /* justify-content: space-between; */
/* flex-direction: column; */ flex-direction: row;
height:min-content;
/* align-items: flex-start; */ /* align-items: flex-start; */
} }
.left-half { .left-half {
flex: 1; flex: 1;
/* align-self: stretch; */ /* align-self: stretch; */
height: 100%;
overflow-x: auto; overflow-x: auto;
/* overflow-y: auto; */
} }
.right-half { .right-half {
flex: 1; flex: 1;
/* height:100%; */
/* align-self: stretch; */ /* align-self: stretch; */
overflow-x: auto; overflow-x:auto;
overflow-y:scroll;
} }
.right-half { .right-half {
@ -294,7 +303,9 @@
/* useless now */ /* useless now */
pre { pre {
overflow-x: auto; overflow-x:visible!important;
overflow-y:visible!important;
/* overflow-x: auto; */
white-space: pre-wrap; white-space: pre-wrap;
white-space: -moz-pre-wrap; white-space: -moz-pre-wrap;
white-space: -pre-wrap; white-space: -pre-wrap;
@ -387,427 +398,439 @@
<body> <body>
<div> <div>
<!-- <div style="max-width: 980px; margin:0 auto;"> --> <!-- <div style="max-width: 980px; margin:0 auto;"> -->
<div id="progress-overlay"> <div id="progress-overlay">
<div id="progress-bar"> <div id="progress-bar">
<div class="progress"></div> <div class="progress"></div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/prismjs@v1.x/components/prism-core.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs@v1.x/plugins/autoloader/prism-autoloader.min.js"></script>
<header class="container">
<h2>Document Index<span class="repository-url"> of:
<span id="partial-repository-url"></span></span>
<div style="float: right;">
<a id="github-link" class="github-icon"><i class="fab fa-github"></i></a>
<a id="brief-link" href="tree.html"><i class="bi bi-text-right"></i></a>
</div> </div>
</h2> </div>
<!-- <div class="search-input-container"> --> <script src="https://cdn.jsdelivr.net/npm/prismjs@v1.x/components/prism-core.min.js"></script>
<input type="text" id="searchInput" placeholder="Search..."> <script src="https://cdn.jsdelivr.net/npm/prismjs@v1.x/plugins/autoloader/prism-autoloader.min.js"></script>
</header> <header class="container">
<ul id="searchResults"></ul> <h2>Document Index<span class="repository-url"> of:
<script type="text/javascript" defer> <span id="partial-repository-url"></span></span>
// TODO: paging <div style="float: right;">
const RESULT_LIMIT = 15; <a id="github-link" class="github-icon"><i class="fab fa-github"></i></a>
// const RESULT_LIMIT = 50; <a id="brief-link" href="tree.html"><i class="bi bi-text-right"></i></a>
const progressOverlay = document.getElementById('progress-overlay'); </div>
const progressBar = document.querySelector('.progress'); </h2>
var isDebugMode = false; <!-- <div class="search-input-container"> -->
function navigateToPage(base_filepath, language_id, project_id, detail_filepath = "") { <input type="text" id="searchInput" placeholder="Search...">
// Use a relative path to navigate to a specific page </header>
let page_param = "codeview.html"; <ul id="searchResults"></ul>
let file_param = 'src' + base_filepath; <script type="text/javascript" defer>
file_param = encodeURIComponent(file_param); // TODO: paging
let language_param = language_id const RESULT_LIMIT = 15;
let jump_link = `${page_param}?file=${file_param}&language=${language_id}&project=${project_id}`; // const RESULT_LIMIT = 50;
if (detail_filepath !== "") { const progressOverlay = document.getElementById('progress-overlay');
let location_range = detail_filepath.slice(base_filepath.length + 1); const progressBar = document.querySelector('.progress');
let location_param = `mycode.${location_range}`; var isDebugMode = false;
jump_link = `${jump_link}#${location_param}`; function navigateToPage(base_filepath, language_id, project_id, detail_filepath = "") {
} // Use a relative path to navigate to a specific page
window.location.href = jump_link; let page_param = "codeview.html";
} let file_param = 'src' + base_filepath;
/*async function waitForDOMContentLoaded() { file_param = encodeURIComponent(file_param);
return new Promise(resolve => { let language_param = language_id
if (document.readyState === 'loading') { let jump_link = `${page_param}?file=${file_param}&language=${language_id}&project=${project_id}`;
document.addEventListener('DOMContentLoaded', resolve); if (detail_filepath !== "") {
} else { let location_range = detail_filepath.slice(base_filepath.length + 1);
resolve(); let location_param = `mycode.${location_range}`;
jump_link = `${jump_link}#${location_param}`;
} }
}); window.location.href = jump_link;
} }
*/ /*async function waitForDOMContentLoaded() {
return new Promise(resolve => {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', resolve);
} else {
resolve();
}
});
}
*/
// Sample data for demonstration // Sample data for demonstration
// async function async_main() { // async function async_main() {
function async_main() { function async_main() {
//const metadata_req = await fetch("metadata.json")// load from server
//const metadata = JSON.parse(await metadata_req.text())
var xhr = new XMLHttpRequest();
xhr.open('GET', "metadata.json", false); // The third parameter is set to false for synchronous request
xhr.send(null);
const metadata = JSON.parse(xhr.responseText);
const github_url = metadata.url.full;
const project_id = metadata.project_name;
const github_partial_url = metadata.url.partial;
const file_mapping = metadata.file_mapping
const split_count = metadata.split_count
var data_var = {}
for (let i = 0; i < split_count; i++) {
//let data_req = await fetch(`data/${i}.json`)// load from server
//let data_part = JSON.parse(await data_req.text())
//const metadata_req = await fetch("metadata.json")// load from server
//const metadata = JSON.parse(await metadata_req.text())
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('GET', `data/${i}.json`, false); // The third parameter is set to false for synchronous request xhr.open('GET', "metadata.json", false); // The third parameter is set to false for synchronous request
xhr.send(null); xhr.send(null);
let data_part = JSON.parse(xhr.responseText); const metadata = JSON.parse(xhr.responseText);
//data_var = { ...data_part, ...data_var } const github_url = metadata.url.full;
data_var = Object.assign(data_var, data_part) const project_id = metadata.project_name;
const progressPercentage = ((i + 1) / split_count) * 100; const github_partial_url = metadata.url.partial;
progressBar.style.width = `${progressPercentage}%`; const file_mapping = metadata.file_mapping
} const split_count = metadata.split_count
progressOverlay.style.display = 'none';
var data_var = {}
for (let i = 0; i < split_count; i++) {
//let data_req = await fetch(`data/${i}.json`)// load from server
//let data_part = JSON.parse(await data_req.text())
const data = data_var // obviously not constant. var xhr = new XMLHttpRequest();
xhr.open('GET', `data/${i}.json`, false); // The third parameter is set to false for synchronous request
xhr.send(null);
let data_part = JSON.parse(xhr.responseText);
const data_total_length = Object.keys(data).length; //data_var = { ...data_part, ...data_var }
// debugger data_var = Object.assign(data_var, data_part)
var sourceCodePaths_v = []; const progressPercentage = ((i + 1) / split_count) * 100;
var sourceCodeIndexRanges_v = {}; progressBar.style.width = `${progressPercentage}%`;
const file_total_count = Object.keys(file_mapping).length;
for (let i = 0; i < file_total_count; i++) {
sourceCodePaths_v.push(file_mapping[i].filepath)
const entry_left = file_mapping[i].entry_id
var entry_right;
if ((i + 1) > (file_total_count - 1)) {
entry_right = data_total_length
} }
else { progressOverlay.style.display = 'none';
// console.log(i, i + 1, file_total_count)
entry_right = file_mapping[i + 1].entry_id
}
if (entry_right == entry_left) {
console.log(i, i + 1, file_total_count, entry_left, entry_right);
debugger
}
sourceCodeIndexRanges_v[file_mapping[i].filepath] = {
left: entry_left,
right: entry_right
}
}
const sourceCodePaths = sourceCodePaths_v;
const sourceCodeIndexRanges = sourceCodeIndexRanges_v;
// Create a new FlexSearch instance with the required configuration
const doc = new FlexSearch.Document({
tokenize: "full",
document: {
id: "id",
index: ["content"]
}
});
// Add the data to the search index const data = data_var // obviously not constant.
Object.keys(data).forEach(id => {
doc.add(id, data[id]);
});
const englishSymbols = ["!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "@", "[", "\\", "]", "^", "_", "`", "{", "|", "}", "~"];
function replaceAll(inputString, searchValue, replaceValue) { const data_total_length = Object.keys(data).length;
return inputString.split(searchValue).join(replaceValue); // debugger
} var sourceCodePaths_v = [];
function getSubTerms(it) { var sourceCodeIndexRanges_v = {};
var m_str = it const file_total_count = Object.keys(file_mapping).length;
for (const sym of englishSymbols) { for (let i = 0; i < file_total_count; i++) {
m_str = replaceAll(m_str, sym, " "); sourceCodePaths_v.push(file_mapping[i].filepath)
} const entry_left = file_mapping[i].entry_id
return m_str.split(" "); var entry_right;
} if ((i + 1) > (file_total_count - 1)) {
entry_right = data_total_length
const searchInputElem = document.getElementById('searchInput');
var isSearchRunning = false;
var hasInputEvent = false;
var lastInputEventTime = new Date().getTime();
function searchInputEventListener() {
function capitalizeFirstLetter(text) {
return text.charAt(0).toUpperCase() + text.slice(1);
}
function mutateText(text) {
var lowerText = text.toLowerCase()
var upperText = text.toUpperCase()
var lowerCapitalized = capitalizeFirstLetter(lowerText)
return [text, lowerText, upperText, lowerCapitalized]
}
const searchTerm = searchInputElem.value;
const searchSubTerms = getSubTerms(searchTerm);
function getHighlightTerms(msubterms) {
var ret = []
for (var it of msubterms) {
if (it.length > 0) {
for (var mut of mutateText(it)) {
if (ret.indexOf(mut) == -1) {
ret.push(mut);
}
}
}
} }
return ret; else {
} // console.log(i, i + 1, file_total_count)
entry_right = file_mapping[i + 1].entry_id
// Display the search results }
const searchResults = document.getElementById('searchResults'); if (entry_right == entry_left) {
searchResults.innerHTML = ''; console.log(i, i + 1, file_total_count, entry_left, entry_right);
if (searchTerm.length == 0) { return } debugger
var isFileSearch = false; }
sourceCodeIndexRanges_v[file_mapping[i].filepath] = {
if (searchTerm.startsWith("/")) { left: entry_left,
if (sourceCodePaths.indexOf(searchTerm) != -1) { isFileSearch = true; } right: entry_right
}
var searchHighlightTerms;
var results;
if (isFileSearch) {
searchHighlightTerms = [];
const queryFileRange = sourceCodeIndexRanges[searchTerm];
var results_v = [];
var ids = []
for (var i = queryFileRange.left; i < queryFileRange.right; i++) {
ids.push(i);
} }
var it = { field: 'content', result: ids }
results_v.push(it)
results = results_v;
} else {
searchHighlightTerms = getHighlightTerms(searchSubTerms);
results = doc.search(searchTerm, RESULT_LIMIT); // Limiting to 5 results for demonstration
} }
// console.log(isFileSearch,results); const sourceCodePaths = sourceCodePaths_v;
const sourceCodeIndexRanges = sourceCodeIndexRanges_v;
const detail_types = ["code", "comment"]; // Create a new FlexSearch instance with the required configuration
const doc = new FlexSearch.Document({
var searchResultItems = {}; tokenize: "full",
var searchResultItemIds = []; document: {
results.forEach(result => { id: "id",
const field = result.field; // "content" index: ["content"]
const ids = result.result; }
ids.forEach(id => {
id = id - 0 // to integer.
const data_type = data[id].type;
const file_id = data[id].file_id;
if (searchResultItems[file_id] === undefined) {
searchResultItemIds.push(file_id);
const file_metadata = file_mapping[file_id];
const entry_id = file_metadata.entry_id;
const summary = data[entry_id + 1].content;
const filepath = file_metadata.filepath;
const language_id = file_metadata.language_id;
searchResultItems[file_id] = { "header": { "summary": summary, "filepath": filepath }, "pairs": {}, "language_id": language_id };
}
if (detail_types.indexOf(data_type) != -1) {
const pair_id = ((data_type === "code") ? id : (id - 1));
if (searchResultItems[file_id].pairs[pair_id] === undefined) {
// console.log(pair_id, pair_id+1, data_type, data[pair_id].location)
let mit = { "left": data[pair_id].content, "right": data[pair_id + 1].content, "location": data[pair_id].location, "hit": [data_type] }
// let mit = { "left": data[pair_id].content, "right": data[pair_id - 1].content, "location": data[pair_id].location }
// console.log(mit)
searchResultItems[file_id].pairs[pair_id] = mit;
}
else {
searchResultItems[file_id].pairs[pair_id].hit.push(data_type)
}
}
// listItem.textContent = `[${field}][${data_type}] ${data[id][field]}`;
// searchResults.appendChild(listItem);
});
}); });
for (var file_id of searchResultItemIds) {
const it = searchResultItems[file_id];
const item = document.createElement('li');
//const item = document.createElement('div');
item.className = "searchItem";
const search_header = document.createElement('div');
search_header.className = "searchItemInfo";
const location_p = document.createElement('p');
location_p.className = "monospace-text codelink";
location_p.innerHTML = (it.header.filepath.slice(1));
location_p.setAttribute('onclick', `navigateToPage(${JSON.stringify(it.header.filepath)}, ${JSON.stringify(it.language_id)}, ${JSON.stringify(project_id)})`) // Add the data to the search index
search_header.appendChild(location_p); Object.keys(data).forEach(id => {
doc.add(id, data[id]);
});
const englishSymbols = ["!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "@", "[", "\\", "]", "^", "_", "`", "{", "|", "}", "~"];
var skip_summary = false; function replaceAll(inputString, searchValue, replaceValue) {
return inputString.split(searchValue).join(replaceValue);
if (Object.keys(it.pairs).length == 1) { }
if (it.pairs[Object.keys(it.pairs)[0]].right == it.header.summary) { function getSubTerms(it) {
skip_summary = true; var m_str = it
} for (const sym of englishSymbols) {
m_str = replaceAll(m_str, sym, " ");
} }
if (!skip_summary) { return m_str.split(" ");
const summary_p = document.createElement('p');
summary_p.innerHTML = (it.header.summary);
search_header.appendChild(summary_p);
}
//search_header.setAttribute('onclick', `navigateToPage(${JSON.stringify(it.header.filepath)}, ${JSON.stringify(it.language_id)})`)
item.appendChild(search_header);
for (var pair_id in it.pairs) {
const pair_container = document.createElement('div');
pair_container.className = "search-container";
const pair = it.pairs[pair_id];
const pair_item = document.createElement('div');
const pair_left = document.createElement('div');
pair_left.className = "left-half";
const code_location_p = document.createElement('p');
code_location_p.className = "monospace-text codelink";
code_location_p.innerHTML = (pair.location.slice(1));
code_location_p.setAttribute('onclick', `navigateToPage(${JSON.stringify(it.header.filepath)}, ${JSON.stringify(it.language_id)}, ${JSON.stringify(project_id)}, ${JSON.stringify(pair.location)})`)
pair_left.appendChild(code_location_p);
// const comment_p = document.createElement('pre');
const comment_p = document.createElement('p');
comment_p.setAttribute('style', 'white-space: pre-line;');
comment_p.innerHTML = (pair.right);
pair_left.appendChild(comment_p);
const pair_right = document.createElement('div');
pair_right.className = "right-half";
const code_pre = document.createElement('pre');
const code_code = document.createElement('code');
code_code.className = `language-${it.language_id}`
// Set the "data-dependencies" attribute
// code_code.setAttribute('data-dependencies', it.language_id+"!");
code_code.textContent = pair.left;
code_pre.appendChild(code_code);
//code_pre.className = "monospace-text";
//code_pre.innerHTML = highlightTerm(pair.left);
pair_right.appendChild(code_pre);
pair_container.appendChild(pair_right);
pair_container.appendChild(pair_left); // comment
// if (pair.hit.indexOf("code") != -1) {
// }// code
//pair_container.setAttribute('onclick', `navigateToPage(${JSON.stringify(it.header.filepath)}, ${JSON.stringify(it.language_id)}, ${JSON.stringify(pair.location)})`)
item.appendChild(pair_container);
}
//li_elem = document.createElement('li');
//li_elem.appendChild(item);
//searchResults.appendChild(li_elem);
searchResults.appendChild(item);
} }
Prism.highlightAllUnder(searchResults); const searchInputElem = document.getElementById('searchInput');
// let's try understand that. var isSearchRunning = false;
const markInstance = new Mark(document.getElementById('searchResults')); var hasInputEvent = false;
markInstance.unmark(); // Clear previous marks var lastInputEventTime = new Date().getTime();
markInstance.mark(searchHighlightTerms); function searchInputEventListener() {
}
function capitalizeFirstLetter(text) {
return text.charAt(0).toUpperCase() + text.slice(1);
}
function mutateText(text) {
var lowerText = text.toLowerCase()
var upperText = text.toUpperCase()
var lowerCapitalized = capitalizeFirstLetter(lowerText)
return [text, lowerText, upperText, lowerCapitalized]
}
function getQueryParams() { const searchTerm = searchInputElem.value;
var search = window.location.search.substring(1); // Remove leading '?' const searchSubTerms = getSubTerms(searchTerm);
var queryParams = {}; function getHighlightTerms(msubterms) {
search.split('&').forEach(function (pair) { var ret = []
var parts = pair.split('='); for (var it of msubterms) {
var key = decodeURIComponent(parts[0]); if (it.length > 0) {
var value = decodeURIComponent(parts[1]); for (var mut of mutateText(it)) {
queryParams[key] = value; if (ret.indexOf(mut) == -1) {
}); ret.push(mut);
return queryParams;
}
// Event listener for the search input
function registerSearchEventListener() {
// this is never called
document.getElementById("partial-repository-url").innerText = github_partial_url;
document.getElementById("github-link").setAttribute("href", github_url);
// get query parameters.
// function keyPressListener(event) {
// if (event.key === 'Enter') {
// searchInputEventListener();
// }
// }
// searchInputElem.addEventListener('keypress',
// // searchInputElem.addEventListener('input',
// // searchInputEventListener
// keyPressListener
// );
setInterval(() => {
if (hasInputEvent) {
let currentTime = new Date().getTime();
if ((currentTime - lastInputEventTime) > 500) // .5 sec
{
hasInputEvent = false;
if (!isSearchRunning) {
isSearchRunning = true;
try {
searchInputEventListener();
} catch (error) {
// Print exception info
console.error(error);
if (isDebugMode) {
// Show alert window in debug mode
console.log(error.message);
alert("An error occurred when searching: " + error.message);
} else {
// Raise exception when not in debug mode
throw error;
} }
} }
isSearchRunning = false;
} }
} }
return ret;
} }
}, 100)
searchInputElem.addEventListener('input', () => { // Display the search results
hasInputEvent = true; const searchResults = document.getElementById('searchResults');
lastInputEventTime = new Date().getTime(); searchResults.innerHTML = '';
}) if (searchTerm.length == 0) { return }
var isFileSearch = false;
if (searchTerm.startsWith("/")) {
if (sourceCodePaths.indexOf(searchTerm) != -1) { isFileSearch = true; }
}
var searchHighlightTerms;
var results;
if (isFileSearch) {
searchHighlightTerms = [];
const queryFileRange = sourceCodeIndexRanges[searchTerm];
var results_v = [];
var ids = []
for (var i = queryFileRange.left; i < queryFileRange.right; i++) {
ids.push(i);
}
var it = { field: 'content', result: ids }
results_v.push(it)
results = results_v;
} else {
searchHighlightTerms = getHighlightTerms(searchSubTerms);
results = doc.search(searchTerm, RESULT_LIMIT); // Limiting to 5 results for demonstration
}
// console.log(isFileSearch,results);
const detail_types = ["code", "comment"];
var searchResultItems = {};
var searchResultItemIds = [];
var leftElements = [];
var rightElements = [];
results.forEach(result => {
const field = result.field; // "content"
const ids = result.result;
ids.forEach(id => {
id = id - 0 // to integer.
const data_type = data[id].type;
const file_id = data[id].file_id;
if (searchResultItems[file_id] === undefined) {
searchResultItemIds.push(file_id);
const file_metadata = file_mapping[file_id];
const entry_id = file_metadata.entry_id;
const summary = data[entry_id + 1].content;
const filepath = file_metadata.filepath;
const language_id = file_metadata.language_id;
searchResultItems[file_id] = { "header": { "summary": summary, "filepath": filepath }, "pairs": {}, "language_id": language_id };
}
if (detail_types.indexOf(data_type) != -1) {
const pair_id = ((data_type === "code") ? id : (id - 1));
if (searchResultItems[file_id].pairs[pair_id] === undefined) {
// console.log(pair_id, pair_id+1, data_type, data[pair_id].location)
let mit = { "left": data[pair_id].content, "right": data[pair_id + 1].content, "location": data[pair_id].location, "hit": [data_type] }
// let mit = { "left": data[pair_id].content, "right": data[pair_id - 1].content, "location": data[pair_id].location }
// console.log(mit)
searchResultItems[file_id].pairs[pair_id] = mit;
}
else {
searchResultItems[file_id].pairs[pair_id].hit.push(data_type)
}
}
// listItem.textContent = `[${field}][${data_type}] ${data[id][field]}`;
// searchResults.appendChild(listItem);
});
});
for (var file_id of searchResultItemIds) {
const it = searchResultItems[file_id];
const item = document.createElement('li');
//const item = document.createElement('div');
item.className = "searchItem";
const search_header = document.createElement('div');
search_header.className = "searchItemInfo";
const location_p = document.createElement('p');
location_p.className = "monospace-text codelink";
location_p.innerHTML = (it.header.filepath.slice(1));
location_p.setAttribute('onclick', `navigateToPage(${JSON.stringify(it.header.filepath)}, ${JSON.stringify(it.language_id)}, ${JSON.stringify(project_id)})`)
search_header.appendChild(location_p);
var skip_summary = false;
if (Object.keys(it.pairs).length == 1) {
if (it.pairs[Object.keys(it.pairs)[0]].right == it.header.summary) {
skip_summary = true;
}
}
if (!skip_summary) {
const summary_p = document.createElement('p');
summary_p.innerHTML = (it.header.summary);
search_header.appendChild(summary_p);
}
//search_header.setAttribute('onclick', `navigateToPage(${JSON.stringify(it.header.filepath)}, ${JSON.stringify(it.language_id)})`)
function setTextAndTriggerInputEvent(queryString) { item.appendChild(search_header);
searchInputElem.value = queryString; // Set text into the input box
// searchInputElem.dispatchEvent(new Event('keypress')); // Fire an input event for (var pair_id in it.pairs) {
// var enterKeyEvent = new KeyboardEvent('keypress', { const pair_container = document.createElement('div');
// key: 'Enter' pair_container.className = "search-container";
// }); const pair = it.pairs[pair_id];
// searchInputElem.dispatchEvent(enterKeyEvent); const pair_item = document.createElement('div');
hasInputEvent = true; const pair_left = document.createElement('div');
} pair_left.className = "left-half";
function displayFile(file_path) { const code_location_p = document.createElement('p');
// TODO: handle file query string code_location_p.className = "monospace-text codelink";
code_location_p.innerHTML = (pair.location.slice(1));
code_location_p.setAttribute('onclick', `navigateToPage(${JSON.stringify(it.header.filepath)}, ${JSON.stringify(it.language_id)}, ${JSON.stringify(project_id)}, ${JSON.stringify(pair.location)})`)
pair_left.appendChild(code_location_p);
// const comment_p = document.createElement('pre');
const comment_p = document.createElement('p');
comment_p.setAttribute('style', 'white-space: pre-line;');
comment_p.innerHTML = (pair.right);
pair_left.appendChild(comment_p);
const pair_right = document.createElement('div');
pair_right.className = "right-half";
const code_pre = document.createElement('pre');
const code_code = document.createElement('code');
code_code.className = `language-${it.language_id}`
// Set the "data-dependencies" attribute
// code_code.setAttribute('data-dependencies', it.language_id+"!");
code_code.textContent = pair.left;
code_pre.appendChild(code_code);
//code_pre.className = "monospace-text";
//code_pre.innerHTML = highlightTerm(pair.left);
pair_right.appendChild(code_pre);
leftElements.push(pair_left);
rightElements.push(pair_right);
pair_container.appendChild(pair_left); // comment
pair_container.appendChild(pair_right);
// if (pair.hit.indexOf("code") != -1) {
// }// code
//pair_container.setAttribute('onclick', `navigateToPage(${JSON.stringify(it.header.filepath)}, ${JSON.stringify(it.language_id)}, ${JSON.stringify(pair.location)})`)
item.appendChild(pair_container);
}
//li_elem = document.createElement('li');
//li_elem.appendChild(item);
//searchResults.appendChild(li_elem);
searchResults.appendChild(item);
}
Prism.highlightAllUnder(searchResults);
// let's try understand that.
const markInstance = new Mark(document.getElementById('searchResults'));
markInstance.unmark(); // Clear previous marks
markInstance.mark(searchHighlightTerms);
for (let i in leftElements) {
let leftHeight = leftElements[i].clientHeight;
let rightHeight = rightElements[i].clientHeight;
if (leftHeight < rightHeight){
rightElements[i].style.height = leftHeight+"px";
}
}
} }
//const queryParams = new URLSearchParams(window.location.search);
const queryParams = getQueryParams(window.location.search); function getQueryParams() {
const query_from_url = queryParams.q; var search = window.location.search.substring(1); // Remove leading '?'
const file_path_from_url = queryParams.file; var queryParams = {};
isDebugMode = queryParams.debug == 'true'; search.split('&').forEach(function (pair) {
if (isDebugMode) { console.log("You are in debug mode.") } var parts = pair.split('=');
if (query_from_url != null || query_from_url != undefined) { var key = decodeURIComponent(parts[0]);
setTextAndTriggerInputEvent(query_from_url) var value = decodeURIComponent(parts[1]);
} else if (file_path_from_url != null || file_path_from_url != undefined) { queryParams[key] = value;
displayFile(file_path_from_url) });
return queryParams;
} }
// Event listener for the search input
function registerSearchEventListener() {
// this is never called
document.getElementById("partial-repository-url").innerText = github_partial_url;
document.getElementById("github-link").setAttribute("href", github_url);
// get query parameters.
// function keyPressListener(event) {
// if (event.key === 'Enter') {
// searchInputEventListener();
// }
// }
// searchInputElem.addEventListener('keypress',
// // searchInputElem.addEventListener('input',
// // searchInputEventListener
// keyPressListener
// );
setInterval(() => {
if (hasInputEvent) {
let currentTime = new Date().getTime();
if ((currentTime - lastInputEventTime) > 500) // .5 sec
{
hasInputEvent = false;
if (!isSearchRunning) {
isSearchRunning = true;
try {
searchInputEventListener();
} catch (error) {
// Print exception info
console.error(error);
if (isDebugMode) {
// Show alert window in debug mode
console.log(error.message);
alert("An error occurred when searching: " + error.message);
} else {
// Raise exception when not in debug mode
throw error;
}
}
isSearchRunning = false;
}
}
}
}, 100)
searchInputElem.addEventListener('input', () => {
hasInputEvent = true;
lastInputEventTime = new Date().getTime();
})
function setTextAndTriggerInputEvent(queryString) {
searchInputElem.value = queryString; // Set text into the input box
// searchInputElem.dispatchEvent(new Event('keypress')); // Fire an input event
// var enterKeyEvent = new KeyboardEvent('keypress', {
// key: 'Enter'
// });
// searchInputElem.dispatchEvent(enterKeyEvent);
hasInputEvent = true;
}
function displayFile(file_path) {
// TODO: handle file query string
}
//const queryParams = new URLSearchParams(window.location.search);
const queryParams = getQueryParams(window.location.search);
const query_from_url = queryParams.q;
const file_path_from_url = queryParams.file;
isDebugMode = queryParams.debug == 'true';
if (isDebugMode) { console.log("You are in debug mode.") }
if (query_from_url != null || query_from_url != undefined) {
setTextAndTriggerInputEvent(query_from_url)
} else if (file_path_from_url != null || file_path_from_url != undefined) {
displayFile(file_path_from_url)
}
}
//document.addEventListener('DOMContentLoaded', registerSearchEventListener);
// waitForDOMContentLoaded();
registerSearchEventListener()
// console.log("event listener registered")
} }
async_main()
//document.addEventListener('DOMContentLoaded', registerSearchEventListener); </script>
// waitForDOMContentLoaded();
registerSearchEventListener()
// console.log("event listener registered")
}
async_main()
</script>
</div> </div>
</body> </body>