sajari-website
Advanced tools
Comparing version 0.5.4 to 0.5.5
{ | ||
"name": "sajari-website", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"description": "Website extensions for the Sajari API. Automatically index site content, add user profiles, render search and recommendations, etc.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -36,5 +36,2 @@ require("./utils/polyfills"); | ||
// Initialize a blank api, we'll enable shortly | ||
var api; | ||
// Initialize DOM functionality | ||
@@ -112,2 +109,58 @@ var dom = new(require("./utils/dom"))(opts); | ||
/** | ||
* Initialize a blank api queue, once initialized the queue will be cleared | ||
*/ | ||
var apiStack = []; | ||
var api = { | ||
pixel: function(data, dest) { | ||
apiStack.push(['pixel', data, dest]); | ||
}, | ||
search: function(data, success, failure) { | ||
apiStack.push(['search', data, success, failure]); | ||
}, | ||
autocomplete: function(data, success, failure) { | ||
apiStack.push(['autocomplete', data, success, failure]); | ||
}, | ||
best: function(data, success, failure) { | ||
apiStack.push(['best', data, success, failure]); | ||
}, | ||
popular: function(data, success, failure) { | ||
apiStack.push(['popular', data, success, failure]); | ||
}, | ||
recent: function(data, success, failure) { | ||
apiStack.push(['recent', data, success, failure]); | ||
}, | ||
related: function(data, success, failure) { | ||
apiStack.push(['related', data, success, failure]); | ||
} | ||
} | ||
/** | ||
* Initialize the API, clear the API stack and replace the stack with the API | ||
*/ | ||
function apiInitialize(options) { | ||
if (options.company === undefined || options.collection === undefined) { | ||
log("company and collection cannot be undefined..."); | ||
return false; | ||
} | ||
// We have a company and a domain so we can install the API | ||
// This replaces the stack shoving queue that was here previously | ||
api = new API(opts.company, opts.collection, { | ||
jsonp: true | ||
}); | ||
log("API stack: ", api); | ||
// Clear the API stack | ||
var r; | ||
while (r = apiStack.shift()) { | ||
var fn = r.shift(); | ||
if (api[fn] !== undefined) { | ||
api[fn].apply(api, r); | ||
} | ||
} | ||
return true; | ||
} | ||
/** | ||
* Render the results into the page | ||
@@ -685,12 +738,4 @@ */ | ||
if (opts.company === undefined || opts.collection === undefined) { | ||
log("company and collection cannot be undefined..."); | ||
return; | ||
} | ||
if (!apiInitialize(opts)) return; | ||
// We have a company and a domain so we can install the API | ||
api = new API(opts.company, opts.collection, { | ||
jsonp: true | ||
}); | ||
// Find and Install the Search Results DIV. If it does not exist, create an overlay block to handle results instead | ||
@@ -742,3 +787,5 @@ if (!dom.hasNode('search-results')) { | ||
if (!dom.hasNode('noindex')) { | ||
stack.push(['index']); | ||
setTimeout(function() { | ||
stack.push(['index']); | ||
}, 500); | ||
} | ||
@@ -922,2 +969,3 @@ | ||
(function() { | ||
apiInitialize(opts); | ||
loaded(window, function() { | ||
@@ -924,0 +972,0 @@ if (opts.scanOnLoad) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64418
1697