From 18c0b666630776487e11af16e3e66c285697c5f7 Mon Sep 17 00:00:00 2001 From: Christian Fei Date: Wed, 27 Jan 2016 23:59:40 +0100 Subject: [PATCH] refactored code --- dest/jekyll-search.js | 27 ++++++++++++++----------- dest/jekyll-search.min.js | 2 +- example/js/jekyll-search.js | 35 ++++++++++++++++++++++----------- example/js/jekyll-search.min.js | 2 +- package.json | 2 +- src/index.js | 26 +++++++++++++----------- 6 files changed, 56 insertions(+), 38 deletions(-) diff --git a/dest/jekyll-search.js b/dest/jekyll-search.js index 5d306ad..2eba912 100644 --- a/dest/jekyll-search.js +++ b/dest/jekyll-search.js @@ -315,22 +315,16 @@ function compile(data){ function registerInput(){ options.searchInput.addEventListener('keyup', function(e){ - - // whitelist the following keycodes - var whitelist = [13,16,20,37,38,39,40,91]; - - // if the key pressed isn't whitelisted continue - if( whitelist.indexOf(e.which) === -1 ) { + var key = e.which + var query = e.target.value + if( isWhitelistedKey(key) && isValidQuery(query) ) { emptyResultsContainer(); - if( e.target.value.length > 0 ){ - render( repository.search(e.target.value) ); - } + render( repository.search(query) ); } - }) } - function render(results){ + function render(results) { if( results.length === 0 ){ return appendToResultsContainer(options.noResultsText) } @@ -339,8 +333,17 @@ function compile(data){ } } + function isValidQuery(query) { + return query && query.length > 0 + } + + function isWhitelistedKey(key) { + return [13,16,20,37,38,39,40,91].indexOf(key) === -1 + } + function throwError(message){ throw new Error('SimpleJekyllSearch --- '+ message) } })(window, document); + },{"./JSONLoader":1,"./OptionsValidator":2,"./Repository":3,"./Templater":6,"./utils":8}],8:[function(require,module,exports){ 'use strict' module.exports = { @@ -371,4 +374,4 @@ function isJSON(json){ } },{}]},{},[7]) -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9ob21lL2VsaS9SZXBvc2l0b3JpZXMvU2ltcGxlLUpla3lsbC1TZWFyY2gvbm9kZV9tb2R1bGVzL2d1bHAtYnJvd3NlcmlmeS9ub2RlX21vZHVsZXM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T3B0aW9uc1xufVxuXG5mdW5jdGlvbiBpc0pTT04oanNvbil7XG4gIHRyeXtcbiAgICBpZigganNvbiBpbnN0YW5jZW9mIE9iamVjdCAmJiBKU09OLnBhcnNlKEpTT04uc3RyaW5naWZ5KGpzb24pKSApe1xuICAgICAgcmV0dXJuIHRydWVcbiAgICB9XG4gICAgcmV0dXJuIGZhbHNlXG4gIH1jYXRjaChlKXtcbiAgICByZXR1cm4gZmFsc2VcbiAgfVxufVxuIl19 diff --git a/dest/jekyll-search.min.js b/dest/jekyll-search.min.js index 5405217..c4d5ad8 100644 --- a/dest/jekyll-search.min.js +++ b/dest/jekyll-search.min.js @@ -1 +1 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o=0}this.matches=function(string,crit){return"string"!=typeof string?!1:(string=string.trim(),matchesString(string,crit))}}module.exports=new LiteralSearchStrategy},{}],6:[function(require,module,exports){"use strict";function setOptions(_options){options.pattern=_options.pattern||options.pattern,options.template=_options.template||options.template,"function"==typeof _options.middleware&&(options.middleware=_options.middleware)}function compile(data){return options.template.replace(options.pattern,function(match,prop){var value=options.middleware(prop,data[prop],options.template);return void 0!==value?value:data[prop]||match})}module.exports={compile:compile,setOptions:setOptions};var options={};options.pattern=/\{(.*?)\}/g,options.template="",options.middleware=function(){}},{}],7:[function(require,module,exports){!function(window,document,undefined){"use strict";function initWithJSON(json){repository.put(json),registerInput()}function initWithURL(url){jsonLoader.load(url,function(err,json){err&&throwError("failed to get JSON ("+url+")"),initWithJSON(json)})}function emptyResultsContainer(){options.resultsContainer.innerHTML=""}function appendToResultsContainer(text){options.resultsContainer.innerHTML+=text}function registerInput(){options.searchInput.addEventListener("keyup",function(e){var whitelist=[13,16,20,37,38,39,40,91];-1===whitelist.indexOf(e.which)&&(emptyResultsContainer(),e.target.value.length>0&&render(repository.search(e.target.value)))})}function render(results){if(0===results.length)return appendToResultsContainer(options.noResultsText);for(var i=0;i{title}',templateMiddleware:function(){},noResultsText:"No results found",limit:10,fuzzy:!1,exclude:[]},requiredOptions=["searchInput","resultsContainer","json"],templater=require("./Templater"),repository=require("./Repository"),jsonLoader=require("./JSONLoader"),optionsValidator=require("./OptionsValidator")({required:requiredOptions}),utils=require("./utils");window.SimpleJekyllSearch=function(_options){var errors=optionsValidator.validate(_options);errors.length>0&&throwError("You must specify the following required options: "+requiredOptions),options=utils.merge(options,_options),templater.setOptions({template:options.searchResultTemplate,middleware:options.templateMiddleware}),repository.setOptions({fuzzy:options.fuzzy,limit:options.limit}),utils.isJSON(options.json)?initWithJSON(options.json):initWithURL(options.json)},window.SimpleJekyllSearch.init=window.SimpleJekyllSearch}(window,document)},{"./JSONLoader":1,"./OptionsValidator":2,"./Repository":3,"./Templater":6,"./utils":8}],8:[function(require,module,exports){"use strict";function merge(defaultParams,mergeParams){var mergedOptions={};for(var option in defaultParams)mergedOptions[option]=defaultParams[option],void 0!==mergeParams[option]&&(mergedOptions[option]=mergeParams[option]);return mergedOptions}function isJSON(json){try{return json instanceof Object&&JSON.parse(JSON.stringify(json))?!0:!1}catch(e){return!1}}module.exports={merge:merge,isJSON:isJSON}},{}]},{},[7]); \ No newline at end of file +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o=0}this.matches=function(string,crit){return"string"!=typeof string?!1:(string=string.trim(),matchesString(string,crit))}}module.exports=new LiteralSearchStrategy},{}],6:[function(require,module,exports){"use strict";function setOptions(_options){options.pattern=_options.pattern||options.pattern,options.template=_options.template||options.template,"function"==typeof _options.middleware&&(options.middleware=_options.middleware)}function compile(data){return options.template.replace(options.pattern,function(match,prop){var value=options.middleware(prop,data[prop],options.template);return void 0!==value?value:data[prop]||match})}module.exports={compile:compile,setOptions:setOptions};var options={};options.pattern=/\{(.*?)\}/g,options.template="",options.middleware=function(){}},{}],7:[function(require,module,exports){!function(window,document,undefined){"use strict";function initWithJSON(json){repository.put(json),registerInput()}function initWithURL(url){jsonLoader.load(url,function(err,json){err&&throwError("failed to get JSON ("+url+")"),initWithJSON(json)})}function emptyResultsContainer(){options.resultsContainer.innerHTML=""}function appendToResultsContainer(text){options.resultsContainer.innerHTML+=text}function registerInput(){options.searchInput.addEventListener("keyup",function(e){var key=e.which,query=e.target.value;isWhitelistedKey(key)&&isValidQuery(query)&&(emptyResultsContainer(),render(repository.search(query)))})}function render(results){if(0===results.length)return appendToResultsContainer(options.noResultsText);for(var i=0;i0}function isWhitelistedKey(key){return-1===[13,16,20,37,38,39,40,91].indexOf(key)}function throwError(message){throw new Error("SimpleJekyllSearch --- "+message)}var options={searchInput:null,resultsContainer:null,json:[],searchResultTemplate:'
  • {title}
  • ',templateMiddleware:function(){},noResultsText:"No results found",limit:10,fuzzy:!1,exclude:[]},requiredOptions=["searchInput","resultsContainer","json"],templater=require("./Templater"),repository=require("./Repository"),jsonLoader=require("./JSONLoader"),optionsValidator=require("./OptionsValidator")({required:requiredOptions}),utils=require("./utils");window.SimpleJekyllSearch=function(_options){var errors=optionsValidator.validate(_options);errors.length>0&&throwError("You must specify the following required options: "+requiredOptions),options=utils.merge(options,_options),templater.setOptions({template:options.searchResultTemplate,middleware:options.templateMiddleware}),repository.setOptions({fuzzy:options.fuzzy,limit:options.limit}),utils.isJSON(options.json)?initWithJSON(options.json):initWithURL(options.json)},window.SimpleJekyllSearch.init=window.SimpleJekyllSearch}(window,document)},{"./JSONLoader":1,"./OptionsValidator":2,"./Repository":3,"./Templater":6,"./utils":8}],8:[function(require,module,exports){"use strict";function merge(defaultParams,mergeParams){var mergedOptions={};for(var option in defaultParams)mergedOptions[option]=defaultParams[option],void 0!==mergeParams[option]&&(mergedOptions[option]=mergeParams[option]);return mergedOptions}function isJSON(json){try{return json instanceof Object&&JSON.parse(JSON.stringify(json))?!0:!1}catch(e){return!1}}module.exports={merge:merge,isJSON:isJSON}},{}]},{},[7]); \ No newline at end of file diff --git a/example/js/jekyll-search.js b/example/js/jekyll-search.js index d3a3d77..2eba912 100644 --- a/example/js/jekyll-search.js +++ b/example/js/jekyll-search.js @@ -15,7 +15,7 @@ function load(location,callback){ xhr.open('GET', location, true) xhr.onreadystatechange = function(){ - if ( xhr.status===200 && xhr.readyState===4 ){ + if ( xhr.readyState===4 && xhr.status===200 ){ try{ callback(null, JSON.parse(xhr.responseText) ) }catch(err){ @@ -170,16 +170,18 @@ function isExcluded(term, excludedTerms){ module.exports = new FuzzySearchStrategy() function FuzzySearchStrategy(){ - function fuzzyRegexFromString(string){ - return new RegExp( string.split('').join('.*?'), 'gi') + function makeFuzzy(string){ + string = string.split('').join('.*?') + string = string.replace('??','?') + return new RegExp( string, 'gi') } - this.matches = function(string,crit){ - if( typeof string !== 'string' ){ + this.matches = function(string, crit){ + if( typeof string !== 'string' || typeof crit !== 'string' ){ return false } string = string.trim() - return !!fuzzyRegexFromString(crit).test(string) + return !!makeFuzzy(crit).test(string) } } @@ -313,14 +315,16 @@ function compile(data){ function registerInput(){ options.searchInput.addEventListener('keyup', function(e){ - emptyResultsContainer() - if( e.target.value.length > 0 ){ - render( repository.search(e.target.value) ) + var key = e.which + var query = e.target.value + if( isWhitelistedKey(key) && isValidQuery(query) ) { + emptyResultsContainer(); + render( repository.search(query) ); } }) } - function render(results){ + function render(results) { if( results.length === 0 ){ return appendToResultsContainer(options.noResultsText) } @@ -329,8 +333,17 @@ function compile(data){ } } + function isValidQuery(query) { + return query && query.length > 0 + } + + function isWhitelistedKey(key) { + return [13,16,20,37,38,39,40,91].indexOf(key) === -1 + } + function throwError(message){ throw new Error('SimpleJekyllSearch --- '+ message) } })(window, document); + },{"./JSONLoader":1,"./OptionsValidator":2,"./Repository":3,"./Templater":6,"./utils":8}],8:[function(require,module,exports){ 'use strict' module.exports = { @@ -361,4 +374,4 @@ function isJSON(json){ } },{}]},{},[7]) -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9zYWlwaC9Eb2N1bWVudHMvcGxheWdyb3VuZC9TaW1wbGUtSmVreWxsLVNlYXJjaC9ub2RlX21vZHVsZXMvZ3VscC1icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCIvVXNlcnMvc2FpcGgvRG9jdW1lbnRzL3BsYXlncm91bmQvU2ltcGxlLUpla3lsbC1TZWFyY2gvc3JjL0pTT05Mb2FkZXIuanMiLCIvVXNlcnMvc2FpcGgvRG9jdW1lbnRzL3BsYXlncm91bmQvU2ltcGxlLUpla3lsbC1TZWFyY2gvc3JjL09wdGlvbnNWYWxpZGF0b3IuanMiLCIvVXNlcnMvc2FpcGgvRG9jdW1lbnRzL3BsYXlncm91bmQvU2ltcGxlLUpla3lsbC1TZWFyY2gvc3JjL1JlcG9zaXRvcnkuanMiLCIvVXNlcnMvc2FpcGgvRG9jdW1lbnRzL3BsYXlncm91bmQvU2ltcGxlLUpla3lsbC1TZWFyY2gvc3JjL1NlYXJjaFN0cmF0ZWdpZXMvRnV6enlTZWFyY2hTdHJhdGVneS5qcyIsIi9Vc2Vycy9zYWlwaC9Eb2N1bWVudHMvcGxheWdyb3VuZC9TaW1wbGUtSmVreWxsLVNlYXJjaC9zcmMvU2VhcmNoU3RyYXRlZ2llcy9MaXRlcmFsU2VhcmNoU3RyYXRlZ3kuanMiLCIvVXNlcnMvc2FpcGgvRG9jdW1lbnRzL3BsYXlncm91bmQvU2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b3B0aW9uXVxuICAgIH1cbiAgfVxuICByZXR1cm4gbWVyZ2VkT3B0aW9uc1xufVxuXG5mdW5jdGlvbiBpc0pTT04oanNvbil7XG4gIHRyeXtcbiAgICBpZigganNvbiBpbnN0YW5jZW9mIE9iamVjdCAmJiBKU09OLnBhcnNlKEpTT04uc3RyaW5naWZ5KGpzb24pKSApe1xuICAgICAgcmV0dXJuIHRydWVcbiAgICB9XG4gICAgcmV0dXJuIGZhbHNlXG4gIH1jYXRjaChlKXtcbiAgICByZXR1cm4gZmFsc2VcbiAgfVxufVxuIl19 diff --git a/example/js/jekyll-search.min.js b/example/js/jekyll-search.min.js index d055f30..c4d5ad8 100644 --- a/example/js/jekyll-search.min.js +++ b/example/js/jekyll-search.min.js @@ -1 +1 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o=0}this.matches=function(string,crit){return"string"!=typeof string?!1:(string=string.trim(),matchesString(string,crit))}}module.exports=new LiteralSearchStrategy},{}],6:[function(require,module,exports){"use strict";function setOptions(_options){options.pattern=_options.pattern||options.pattern,options.template=_options.template||options.template,"function"==typeof _options.middleware&&(options.middleware=_options.middleware)}function compile(data){return options.template.replace(options.pattern,function(match,prop){var value=options.middleware(prop,data[prop],options.template);return void 0!==value?value:data[prop]||match})}module.exports={compile:compile,setOptions:setOptions};var options={};options.pattern=/\{(.*?)\}/g,options.template="",options.middleware=function(){}},{}],7:[function(require,module,exports){!function(window,document,undefined){"use strict";function initWithJSON(json){repository.put(json),registerInput()}function initWithURL(url){jsonLoader.load(url,function(err,json){err&&throwError("failed to get JSON ("+url+")"),initWithJSON(json)})}function emptyResultsContainer(){options.resultsContainer.innerHTML=""}function appendToResultsContainer(text){options.resultsContainer.innerHTML+=text}function registerInput(){options.searchInput.addEventListener("keyup",function(e){emptyResultsContainer(),e.target.value.length>0&&render(repository.search(e.target.value))})}function render(results){if(0===results.length)return appendToResultsContainer(options.noResultsText);for(var i=0;i{title}',templateMiddleware:function(){},noResultsText:"No results found",limit:10,fuzzy:!1,exclude:[]},requiredOptions=["searchInput","resultsContainer","json"],templater=require("./Templater"),repository=require("./Repository"),jsonLoader=require("./JSONLoader"),optionsValidator=require("./OptionsValidator")({required:requiredOptions}),utils=require("./utils");window.SimpleJekyllSearch=function(_options){var errors=optionsValidator.validate(_options);errors.length>0&&throwError("You must specify the following required options: "+requiredOptions),options=utils.merge(options,_options),templater.setOptions({template:options.searchResultTemplate,middleware:options.templateMiddleware}),repository.setOptions({fuzzy:options.fuzzy,limit:options.limit}),utils.isJSON(options.json)?initWithJSON(options.json):initWithURL(options.json)},window.SimpleJekyllSearch.init=window.SimpleJekyllSearch}(window,document)},{"./JSONLoader":1,"./OptionsValidator":2,"./Repository":3,"./Templater":6,"./utils":8}],8:[function(require,module,exports){"use strict";function merge(defaultParams,mergeParams){var mergedOptions={};for(var option in defaultParams)mergedOptions[option]=defaultParams[option],void 0!==mergeParams[option]&&(mergedOptions[option]=mergeParams[option]);return mergedOptions}function isJSON(json){try{return json instanceof Object&&JSON.parse(JSON.stringify(json))?!0:!1}catch(e){return!1}}module.exports={merge:merge,isJSON:isJSON}},{}]},{},[7]); \ No newline at end of file +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o=0}this.matches=function(string,crit){return"string"!=typeof string?!1:(string=string.trim(),matchesString(string,crit))}}module.exports=new LiteralSearchStrategy},{}],6:[function(require,module,exports){"use strict";function setOptions(_options){options.pattern=_options.pattern||options.pattern,options.template=_options.template||options.template,"function"==typeof _options.middleware&&(options.middleware=_options.middleware)}function compile(data){return options.template.replace(options.pattern,function(match,prop){var value=options.middleware(prop,data[prop],options.template);return void 0!==value?value:data[prop]||match})}module.exports={compile:compile,setOptions:setOptions};var options={};options.pattern=/\{(.*?)\}/g,options.template="",options.middleware=function(){}},{}],7:[function(require,module,exports){!function(window,document,undefined){"use strict";function initWithJSON(json){repository.put(json),registerInput()}function initWithURL(url){jsonLoader.load(url,function(err,json){err&&throwError("failed to get JSON ("+url+")"),initWithJSON(json)})}function emptyResultsContainer(){options.resultsContainer.innerHTML=""}function appendToResultsContainer(text){options.resultsContainer.innerHTML+=text}function registerInput(){options.searchInput.addEventListener("keyup",function(e){var key=e.which,query=e.target.value;isWhitelistedKey(key)&&isValidQuery(query)&&(emptyResultsContainer(),render(repository.search(query)))})}function render(results){if(0===results.length)return appendToResultsContainer(options.noResultsText);for(var i=0;i0}function isWhitelistedKey(key){return-1===[13,16,20,37,38,39,40,91].indexOf(key)}function throwError(message){throw new Error("SimpleJekyllSearch --- "+message)}var options={searchInput:null,resultsContainer:null,json:[],searchResultTemplate:'
  • {title}
  • ',templateMiddleware:function(){},noResultsText:"No results found",limit:10,fuzzy:!1,exclude:[]},requiredOptions=["searchInput","resultsContainer","json"],templater=require("./Templater"),repository=require("./Repository"),jsonLoader=require("./JSONLoader"),optionsValidator=require("./OptionsValidator")({required:requiredOptions}),utils=require("./utils");window.SimpleJekyllSearch=function(_options){var errors=optionsValidator.validate(_options);errors.length>0&&throwError("You must specify the following required options: "+requiredOptions),options=utils.merge(options,_options),templater.setOptions({template:options.searchResultTemplate,middleware:options.templateMiddleware}),repository.setOptions({fuzzy:options.fuzzy,limit:options.limit}),utils.isJSON(options.json)?initWithJSON(options.json):initWithURL(options.json)},window.SimpleJekyllSearch.init=window.SimpleJekyllSearch}(window,document)},{"./JSONLoader":1,"./OptionsValidator":2,"./Repository":3,"./Templater":6,"./utils":8}],8:[function(require,module,exports){"use strict";function merge(defaultParams,mergeParams){var mergedOptions={};for(var option in defaultParams)mergedOptions[option]=defaultParams[option],void 0!==mergeParams[option]&&(mergedOptions[option]=mergeParams[option]);return mergedOptions}function isJSON(json){try{return json instanceof Object&&JSON.parse(JSON.stringify(json))?!0:!1}catch(e){return!1}}module.exports={merge:merge,isJSON:isJSON}},{}]},{},[7]); \ No newline at end of file diff --git a/package.json b/package.json index d45f267..007f76c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-jekyll-search", - "version": "1.0.9", + "version": "1.1.1", "description": "Simple Jekyll site search using javascript and json", "main": "dest/jekyll-search.js", "scripts": { diff --git a/src/index.js b/src/index.js index 8f9b941..e669489 100644 --- a/src/index.js +++ b/src/index.js @@ -79,22 +79,16 @@ function registerInput(){ options.searchInput.addEventListener('keyup', function(e){ - - // whitelist the following keycodes - var whitelist = [13,16,20,37,38,39,40,91]; - - // if the key pressed isn't whitelisted continue - if( whitelist.indexOf(e.which) === -1 ) { + var key = e.which + var query = e.target.value + if( isWhitelistedKey(key) && isValidQuery(query) ) { emptyResultsContainer(); - if( e.target.value.length > 0 ){ - render( repository.search(e.target.value) ); - } + render( repository.search(query) ); } - }) } - function render(results){ + function render(results) { if( results.length === 0 ){ return appendToResultsContainer(options.noResultsText) } @@ -103,5 +97,13 @@ } } + function isValidQuery(query) { + return query && query.length > 0 + } + + function isWhitelistedKey(key) { + return [13,16,20,37,38,39,40,91].indexOf(key) === -1 + } + function throwError(message){ throw new Error('SimpleJekyllSearch --- '+ message) } -})(window, document); \ No newline at end of file +})(window, document);