把前端从CircuitVerse中拆了出来

This commit is contained in:
zhbaor 2022-01-23 17:33:42 +08:00
commit 5bf1284599
2182 changed files with 189323 additions and 0 deletions

30
public/js/search.js Normal file
View file

@ -0,0 +1,30 @@
/* jshint esversion: 6 */
$(document).ready(() => {
// Highlight searched text
var searchText = $('.navbar-search-bar-input').val().trim();
if (searchText !== '') {
$('.search-container').find('.search-project-name, .search-project-description p').each(function highlight() {
// Loop over each result
var text = $(this).html();
var currentPos = 0;
loop = true;
while (loop && currentPos < text.length) { // Loop over all text and highlight any occurences of the search term
var occurence = text.toLowerCase().indexOf(searchText.toLowerCase(), currentPos);
if (occurence === -1) {
loop = false;
} else {
text = `${text.substring(0, occurence)}<span class="search-match">${text.substring(occurence, occurence + searchText.length)}</span>${text.substring(occurence + searchText.length)}`;
}
currentPos += 34 + searchText.length;
}
$(this).html(text);
});
}
});