diff --git a/dest/jekyll-search.js b/dest/jekyll-search.js index f61e1bc..3d9721a 100644 --- a/dest/jekyll-search.js +++ b/dest/jekyll-search.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)}}module.exports=new LiteralSearchStrategy},{}],4:[function(require,module,exports){function search(data,crit){return crit?findMatches(data,crit,opt.searchStrategy,opt):[]}function setOptions(_opt){opt=_opt||{},opt.fuzzy=_opt.fuzzy||!1,opt.limit=_opt.limit||10,opt.searchStrategy=require(_opt.fuzzy?"./SearchStrategies/fuzzy":"./SearchStrategies/literal")}function findMatches(store,crit,strategy,opt){for(var matches=[],data=store.get(),i=0;i{title}',noResultsText:"No results found",limit:10,fuzzy:!1,exclude:[]};window.SimpleJekyllSearch=function(_opt){opt=validateOptions(_opt),searcher.setOptions(_opt),jsonLoader=new JSONLoader,isJSON(opt.json)?initWithJSON(opt.json):initWithURL(opt.json)},window.SimpleJekyllSearch.init=window.SimpleJekyllSearch}(window,document)},{"./JSONLoader":1,"./Searcher":4,"./Store":5,"./Templater":6}]},{},[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)}}module.exports=new LiteralSearchStrategy},{}],4:[function(require,module,exports){function search(data,crit){return crit?findMatches(data,crit,opt.searchStrategy,opt):[]}function setOptions(_opt){opt=_opt||{},opt.fuzzy=_opt.fuzzy||!1,opt.limit=_opt.limit||10,opt.searchStrategy=require(_opt.fuzzy?"./SearchStrategies/fuzzy":"./SearchStrategies/literal")}function findMatches(store,crit,strategy,opt){for(var matches=[],data=store.get(),i=0;i{title}',noResultsText:"No results found",limit:10,fuzzy:!1,exclude:[]};window.SimpleJekyllSearch=function(_opt){opt=validateOptions(_opt),searcher.setOptions(_opt),isJSON(opt.json)?initWithJSON(opt.json):initWithURL(opt.json)},window.SimpleJekyllSearch.init=window.SimpleJekyllSearch}(window,document)},{"./JSONLoader":1,"./Searcher":4,"./Store":5,"./Templater":6}]},{},[7]); \ No newline at end of file diff --git a/src/JSONLoader.js b/src/JSONLoader.js index e1b18b1..7ae3e1e 100644 --- a/src/JSONLoader.js +++ b/src/JSONLoader.js @@ -1,18 +1,20 @@ -module.exports = function JSONLoader(){ - this.load = function(location,callback){ - var xhr = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") - xhr.open("GET", location, true) +module.exports = { + load: load +} + +function load(location,callback){ + var xhr = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") + xhr.open("GET", location, true) - xhr.onreadystatechange = function(){ - if ( xhr.status==200 && xhr.readyState==4 ){ - try{ - callback(null, JSON.parse(xhr.responseText) ) - }catch(err){ - callback(err, null) - } + xhr.onreadystatechange = function(){ + if ( xhr.status==200 && xhr.readyState==4 ){ + try{ + callback(null, JSON.parse(xhr.responseText) ) + }catch(err){ + callback(err, null) } } - - xhr.send() } + + xhr.send() } diff --git a/src/index.js b/src/index.js index 0997f2f..7f437fb 100644 --- a/src/index.js +++ b/src/index.js @@ -4,9 +4,7 @@ var searcher = require('./Searcher') var templater = require('./Templater') var store = require('./Store') - var JSONLoader = require('./JSONLoader') - - var jsonLoader + var jsonLoader = require('./JSONLoader') var requiredOptions = [ 'searchInput', @@ -28,7 +26,6 @@ window.SimpleJekyllSearch = function SimpleJekyllSearch(_opt){ opt = validateOptions(_opt) searcher.setOptions(_opt) - jsonLoader = new JSONLoader() isJSON(opt.json) ? initWithJSON(opt.json) :