diff --git a/_config.yml b/_config.yml index 28eb7823a..bcea6d489 100755 --- a/_config.yml +++ b/_config.yml @@ -468,6 +468,8 @@ algolia_search: # Local search local_search: enable: false + # show top n results per article, show all results by setting to -1 + top_n_per_article: 1 # External URL with BASE64 encrypt & decrypt # Usage: {% exturl text url "title" %} diff --git a/layout/_third-party/search/localsearch.swig b/layout/_third-party/search/localsearch.swig index 3ff807ec3..39e151870 100644 --- a/layout/_third-party/search/localsearch.swig +++ b/layout/_third-party/search/localsearch.swig @@ -4,18 +4,29 @@ var isfetched = false; // Search DB path; var search_path = "{{ config.search.path }}"; - if (search_path.length == 0) { + if (search_path.length === 0) { search_path = "search.xml"; } var path = "{{ config.root }}" + search_path; // monitor main search box; + var onPopupClose = function (e) { + $('.popup').hide(); + $('#local-search-input').val(''); + $('.search-result-list').remove(); + $(".local-search-pop-overlay").remove(); + $('body').css('overflow', ''); + } + function proceedsearch() { $("body") .append('
') .css('overflow', 'hidden'); + $('.search-popup-overlay').click(onPopupClose); $('.popup').toggle(); + $('#local-search-input').focus(); } + // search function; var searchFunc = function(path, search_id, content_id) { 'use strict'; @@ -37,69 +48,161 @@ var $input = document.getElementById(search_id); var $resultContent = document.getElementById(content_id); $input.addEventListener('input', function(){ - var matchcounts = 0; - var str='"; - if (matchcounts == 0) { str = '
' } - if (keywords == "") { str = '
' } - $resultContent.innerHTML = str; + }); + var searchResultList = '
    '; + resultItems.forEach(function (result, i) { + searchResultList += result.item; + }) + searchResultList += "
"; + $resultContent.innerHTML = searchResultList; + } }); proceedsearch(); } @@ -108,18 +211,14 @@ // handle and trigger popup window; $('.popup-trigger').click(function(e) { e.stopPropagation(); - if (isfetched == false) { + 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-btn-close').click(onPopupClose); $('.popup').click(function(e){ e.stopPropagation(); }); diff --git a/source/css/_common/components/third-party/localsearch.styl b/source/css/_common/components/third-party/localsearch.styl index a253a2ccd..85f43cf9a 100644 --- a/source/css/_common/components/third-party/localsearch.styl +++ b/source/css/_common/components/third-party/localsearch.styl @@ -43,7 +43,6 @@ .search-keyword border-bottom: 1px dashed #f00 - font-size: 14px font-weight: bold color: #f00 @@ -62,7 +61,7 @@ .local-search-input-wrapper display: inline-block - width: calc(100% - 60px) + width: calc(100% - 90px) height: 36px line-height: 36px padding: 0 5px @@ -83,6 +82,8 @@ color: #999 height: 36px width: 18px + padding-left: 10px + padding-right: 10px .search-icon float: left @@ -91,7 +92,6 @@ border-left: 1px solid #eee float: right cursor: pointer - padding-left: 10px #no-result position: absolute