Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
convert JSONLoader to Singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-fei committed Jun 7, 2015
1 parent 81309d9 commit 199991c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dest/jekyll-search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions src/JSONLoader.js
Original file line number Diff line number Diff line change
@@ -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()
}
5 changes: 1 addition & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -28,7 +26,6 @@
window.SimpleJekyllSearch = function SimpleJekyllSearch(_opt){
opt = validateOptions(_opt)
searcher.setOptions(_opt)
jsonLoader = new JSONLoader()

isJSON(opt.json) ?
initWithJSON(opt.json) :
Expand Down

0 comments on commit 199991c

Please sign in to comment.