From 27b329218ed98abad4c48ae77a553483fb0f908a Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 20 Nov 2015 22:30:58 +0100 Subject: [PATCH] more function split up --- _src/_assets/js/_search.js | 40 ++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/_src/_assets/js/_search.js b/_src/_assets/js/_search.js index 30616203..c3c00752 100644 --- a/_src/_assets/js/_search.js +++ b/_src/_assets/js/_search.js @@ -11,34 +11,27 @@ var Search = (function(w, d) { _private = { searchShow: function() { + + var body = $('body'); + searchlink.on('click', function(e) { e.preventDefault(); - SimpleJekyllSearch({ - searchInput: document.getElementById('search-input'), - resultsContainer: document.getElementById('search-results'), - json: '/search.json', - searchResultTemplate: '
  • {title}
  • ', - fuzzy: false - }); - // show search field searcharea .removeClass('ready bounceOutUp') .addClass('ready slideDown') .on('animationend webkitAnimationEnd oAnimationEnd', function(){ - $('body').addClass('search-open'); + body.addClass('search-open'); }); + searchfield.focus(); - // hide menu too just in case - if ($('body').hasClass('menu-open')) { - $('body').removeClass('menu-open'); - } + _private.searchSimpleJekyllSearch(); - // show search results upon typing - if (searchfield.val().length) { - searchpop.removeClass('hide'); + // hide menu too just in case + if (body.hasClass('menu-open')) { + body.removeClass('menu-open'); } // bind the hide controls @@ -61,13 +54,25 @@ var Search = (function(w, d) { // and dont close thepop now e.stopPropagation(); }); + }, - // finally show popup upon first keypress + searchResultsShow: function() { + // show popup upon first keypress searchfield.on('keyup', function() { searchpop.removeClass('hide'); }); }, + searchSimpleJekyllSearch: function() { + SimpleJekyllSearch({ + searchInput: document.getElementById('search-input'), + resultsContainer: document.getElementById('search-results'), + json: '/search.json', + searchResultTemplate: '
  • {title}
  • ', + fuzzy: false + }); + }, + searchHide: function() { $('.search-close').on('click', function(e) { e.preventDefault(); @@ -94,6 +99,7 @@ var Search = (function(w, d) { app = { init: function() { _private.searchShow(); + _private.searchResultsShow(); _private.searchHide(); } };