L = ""; if (this.value.trim().length > 1) { // perform local searching datas.forEach(function(data) { var isMatch = false; var content_index = []; var data_title = data.title.trim().toLowerCase(); var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase(); var data_url = decodeURIComponent(data.url); var index_title = -1; var index_content = -1; var first_occur = -1; // only match artiles with not empty titles and contents if(data_title != '') { keywords.forEach(function(keyword, i) { index_title = data_title.indexOf(keyword); index_content = data_content.indexOf(keyword); if( index_title >= 0 || index_content >= 0 ){ isMatch = true; if (i == 0) { first_occur = index_content; } } }); } // show search results if (isMatch) { matchcounts += 1; str += "
  • "+ data_title +""; var content = data.content.trim().replace(/<[^>]+>/g,""); if (first_occur >= 0) { // cut out 100 characters var start = first_occur - 20; var end = first_occur + 80; if(start < 0){ start = 0; } if(start == 0){ end = 50; } if(end > content.length){ end = content.length; } var match_content = content.substring(start, end); // highlight all keywords keywords.forEach(function(keyword){ var regS = new RegExp(keyword, "gi"); match_content = match_content.replace(regS, ""+keyword+""); }); str += "

    " + match_content +"...

    " } str += "
  • "; } })}; str += ""; if (matchcounts == 0) { str = '
    ' } if (keywords == "") { str = '
    ' } $resultContent.innerHTML = str; }); proceedsearch(); } });} // handle and trigger popup window; $('.popup-trigger').click(function(e) { e.stopPropagation(); if (isfetched == false) { searchFunc(path, 'local-search-input', 'local-search-result'); } else { proceedsearch(); }; }); $('.popup-btn-close').click(function(e){ $('.popup').hide(); $(".local-search-pop-overlay").remove(); $('body').css('overflow', ''); }); $('.popup').click(function(e){ e.stopPropagation(); });