mirror of https://github.com/onweru/compose.git

weru
12.21.2020 00900562f8f8c4db0c306653b923061f9dffb0f3
update
2 files modified
30 ■■■■■ changed files
assets/js/functions.js 4 ●●●● patch | view | raw | blame | history
assets/js/search.js 26 ●●●●● patch | view | raw | blame | history
assets/js/functions.js
@@ -111,10 +111,6 @@
  let c = context.innerHTML;
  let index = c.indexOf(text);
  if(index >= 0) {
    const cc = `${c.charAt(0)}${c.substring(1,c.length)}`;
    index = cc.indexOf(Text);
  }
  if (index >= 0) {
    let stop = index + text.length;
    let s = c.substring(index,stop);
    let before = c.substring(0,index);
assets/js/search.js
@@ -11,8 +11,6 @@
const searchKeys = ['title', 'link', 'body', 'id'];
const searchOptions = {
  ignoreLocation: true,
  includeScore: true,
  includeMatches: true,
  keys: searchKeys,
  threshold: 0.1
};
@@ -49,12 +47,17 @@
  if (searchField) {
    searchField.addEventListener('input', function() {
      const searchTerm = this.value.trim().replaceAll(" ", " +").toLowerCase();
      const searchTerm = this.value.trim().toLowerCase();
      if(searchTerm.length >= 3) {
        let rawResults = index.search(searchTerm);
        rawResults = rawResults.map(function(result){
          return result.item;
          const matches = result.matches;
          const resultItem = result.item;
          resultItem.matches = matches;
          return resultItem;
        });
        console.log(JSON.stringify(rawResults));
        console.log(rawResults);
        if(rawResults.length) {
@@ -89,11 +92,14 @@
function findQuery(query = 'query') {
  const urlParams = new URLSearchParams(window.location.search);
  if(urlParams.has(query)){
    const searchTerm = urlParams.get(query);
    window.find(searchTerm);
    return searchTerm;
    let c = urlParams.get(query);
    window.find(c);
    cc = `${c.charAt(0).toUpperCase()}${c.substring(1,c.length)}`;
    window.find(cc);
    console.log(c.length);
    return [c, cc];
  }
  return "";
  return ["",""];
}
let main = elem('main');
@@ -101,6 +107,8 @@
  main = elem('.main');
}
const searchQuery = findQuery();
wrapText(searchQuery,main,'mark');
console.log(searchQuery);
wrapText(searchQuery[0],main,'mark');
wrapText(searchQuery[1],main,'mark');
window.addEventListener('load', () => search());