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

Commit 199991c

Browse files
committed
convert JSONLoader to Singleton
1 parent 81309d9 commit 199991c

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

dest/jekyll-search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/JSONLoader.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
module.exports = function JSONLoader(){
2-
this.load = function(location,callback){
3-
var xhr = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP")
4-
xhr.open("GET", location, true)
1+
module.exports = {
2+
load: load
3+
}
4+
5+
function load(location,callback){
6+
var xhr = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP")
7+
xhr.open("GET", location, true)
58

6-
xhr.onreadystatechange = function(){
7-
if ( xhr.status==200 && xhr.readyState==4 ){
8-
try{
9-
callback(null, JSON.parse(xhr.responseText) )
10-
}catch(err){
11-
callback(err, null)
12-
}
9+
xhr.onreadystatechange = function(){
10+
if ( xhr.status==200 && xhr.readyState==4 ){
11+
try{
12+
callback(null, JSON.parse(xhr.responseText) )
13+
}catch(err){
14+
callback(err, null)
1315
}
1416
}
15-
16-
xhr.send()
1717
}
18+
19+
xhr.send()
1820
}

src/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
var searcher = require('./Searcher')
55
var templater = require('./Templater')
66
var store = require('./Store')
7-
var JSONLoader = require('./JSONLoader')
8-
9-
var jsonLoader
7+
var jsonLoader = require('./JSONLoader')
108

119
var requiredOptions = [
1210
'searchInput',
@@ -28,7 +26,6 @@
2826
window.SimpleJekyllSearch = function SimpleJekyllSearch(_opt){
2927
opt = validateOptions(_opt)
3028
searcher.setOptions(_opt)
31-
jsonLoader = new JSONLoader()
3229

3330
isJSON(opt.json) ?
3431
initWithJSON(opt.json) :

0 commit comments

Comments
 (0)