$(document).ready(function () { // Popup Window; var isfetched = false; // Search DB path; // TO-DO Seems not found best way var pre_sch_path = window.location.href.indexOf('/en/') > -1 ? '/en/' : "/" var search_path = "2021/searchindex.xml"; var path = pre_sch_path + search_path; // monitor main search box; function proceedsearch() { $("body").append('
').css('overflow', 'hide'); $('.popup').fadeIn('slow'); } // search function; var searchFunc = function(path, search_id, content_id) { 'use strict'; $.ajax({ url: path, dataType: "text", async: true, success: function( xmlResponse ) { // get the contents from search data isfetched = true; $('.popup').detach().appendTo('.header-inner'); var datas = $( "entry", xmlResponse ).map(function() { return { title: $( "title", this ).text(), content: $("content",this).text(), url: $( "url" , this).text() }; }).get(); var $input = document.getElementById(search_id); var $resultContent = document.getElementById(content_id); $input.addEventListener('input', function(){ var matchcounts = 0; var str='"; var rs_cnt = "
找到 "+matchcounts if (pre_sch_path == '/') { rs_cnt += " 个入围项目" } else { rs_cnt += " results found!" } rs_cnt += "

" str = rs_cnt + str if (matchcounts == 0) { str = '
' } if (keywords == "") { str = '
' } $resultContent.innerHTML = str; }); proceedsearch(); } }); } // handle and trigger popup window; $('.popup-trigger').click(function(e) { e.stopPropagation(); //TODO why here need timeout, couldn't understand it. setTimeout(() => $('#local-search-input').focus(), 500); if (isfetched == false) { searchFunc(path, 'local-search-input', 'local-search-result'); } else { proceedsearch(); }; }); $('.popup-btn-close').click(function(e){ $('.popup').fadeOut('slow'); $(".popoverlay").remove(); $('body').css('overflow', ''); }); $('.popup').click(function(e){ e.stopPropagation(); }); });