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) }