From 642ba8d1d61bf115e369889cde92e501f13fd66c Mon Sep 17 00:00:00 2001 From: Christian Fei Date: Mon, 10 Aug 2015 22:29:00 +0200 Subject: [PATCH] cleanup --- src/Templater.js | 14 +++++++------- src/index.js | 8 +++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Templater.js b/src/Templater.js index 5abd14b..6b0d022 100644 --- a/src/Templater.js +++ b/src/Templater.js @@ -3,16 +3,16 @@ module.exports = { setOptions: setOptions } -var opt = {} -opt.templatePattern = /\{(.*?)\}/g +var options = {} +options.templatePattern = /\{(.*?)\}/g -function setOptions(_opt){ - opt = _opt || {} - opt.templatePattern = _opt.templatePattern || /\{(.*?)\}/g +function setOptions(_options){ + options = _options || {} + options.templatePattern = _options.templatePattern || /\{(.*?)\}/g } -function compile(t, data){ - return t.replace(opt.templatePattern, function(match, prop) { +function compile(template, data){ + return template.replace(options.templatePattern, function(match, prop) { return data[prop] || match }) } diff --git a/src/index.js b/src/index.js index db39c98..4e6a2e0 100644 --- a/src/index.js +++ b/src/index.js @@ -72,16 +72,14 @@ function registerInput(){ options.searchInput.addEventListener('keyup', function(e){ - if( e.target.value.length == 0 ){ - emptyResultsContainer() - return + emptyResultsContainer() + if( e.target.value.length > 0 ){ + render( repository.search(e.target.value) ) } - render( repository.search(e.target.value) ) }) } function render(results){ - emptyResultsContainer() if( results.length == 0 ){ return appendToResultsContainer(options.noResultsText) }