Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sajari-website

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sajari-website - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

src/js/website.js

14

gulpfile.js

@@ -46,8 +46,8 @@ var gulp = require('gulp');

gulp.task('widgets', ['compile-templates', 'test', 'lint'], function() {
return browserify('./src/js/widgets.js')
gulp.task('website', ['compile-templates', 'test', 'lint'], function() {
return browserify('./src/js/website.js')
.bundle().on('error', function(e){
console.log(e);
})
.pipe(source('widgets.js')).on('error', function(e){
.pipe(source('website.js')).on('error', function(e){
console.log(e);

@@ -64,6 +64,6 @@ })

gulp.task('compress-widgets', ['compile-templates', 'test'], function() {
return browserify('./src/js/widgets.js')
gulp.task('compress-website', ['compile-templates', 'test'], function() {
return browserify('./src/js/website.js')
.bundle()
.pipe(source('widgets.min.js'))
.pipe(source('website.min.js'))
.pipe(buffer())

@@ -75,3 +75,3 @@ .pipe(uglify())

gulp.task('default', ['compile-templates', 'widgets', 'compress-widgets']);
gulp.task('default', ['compile-templates', 'website', 'compress-website']);

@@ -78,0 +78,0 @@ gulp.task("watch", ['beautify'], function() {

{
"name": "sajari-website",
"version": "0.3.2",
"version": "0.4.0",
"description": "Website extensions for the Sajari API. Automatically index site content, add user profiles, render search and recommendations, etc.",

@@ -57,3 +57,4 @@ "author": {

"dot": "1.0.1",
"sajari": "^0.6.2",
"js-cookie": "^2.1.0",
"sajari": "^0.8.3",
"superagent": "^1.6.1",

@@ -60,0 +61,0 @@ "superagent-jsonp": "0.0.6"

/*
* profile.js - Handles Sajari profile information
*/
var cookie = require("./utils/cookie");
var cookie = require("js-cookie");
var isArray = require('sajari/src/js/utils/isArray.js');
var opts = {
cname: 'sjID',
pname: 'sjPR',
sname: 'sjSE',
clicked: 'sjCL',
expires: 365, // days
domain: window.location.hostname.toLowerCase().replace(/^www(.)/, '')
};
/**

@@ -20,8 +31,9 @@ * Profile constructor

if (this.visitorId === undefined) {
this.visitorId = cookie.get('sjID');
this.visitorId = cookie.get(opts.cname);
if (this.visitorId === undefined) {
this.visitorId = (new Date().getTime()) + '.' + Math.floor(Math.random() * 1000000);
this.setVisitorId(new Date().getTime() + '.' + Math.floor(Math.random() * 1000000));
}
cookie.set('sjID', this.visitorId, 365);
}
this.sequence = getPageSequence();
this.load();
}

@@ -31,7 +43,86 @@

encode: function() {
/**
* Load profile meta data
*/
load: function() {
var p = getSession(opts.pname);
if (p !== null) {
this.meta = p;
}
},
/**
* Save profile meta data
*/
save: function() {
setSession(opts.pname, this.meta);
},
/**
* Set profile meta data
* @param data - object
*/
set: function(data) {
for (var k in data) {
this.meta[k] = data[k];
}
this.save();
},
/**
* Get profile meta data
*/
get: function(key) {
return this.meta.key;
},
/**
* If a user clicks a recommended URL, we store that to not show it again in the near future
*/
addClickedUrl: function(url) {
var u = url.split("?"); // TODO: Might be a problem for sites using query params for real stuff
var arr = getSession(opts.clicked);
if (arr === null) {
arr = [];
}
for (var i = 0; i < arr.length; i++) {
if (arr[i] === u[0]) {
return;
}
}
arr.push(u[0]);
setSession(opts.clicked, arr);
},
/**
* Get the most recent "num" clicked URL's
*/
getClickedUrls: function(num) {
var arr = getSession(opts.clicked);
if (arr !== null) {
return arr.slice(Math.max(arr.length - num, 1));
}
return [];
},
/**
* Encode to args
*/
toArgs: function(data) {
if (data === undefined) {
data = {};
}
for (var key in this.meta) {
var val = this.meta[key];
if (isArray(val)) {
val = val.join(';');
} else if (typeof val === 'object') {
val = JSON.stringify(val);
}
data['meta[' + key + ']'] = val;
}
return data;
},
/**
* Sets a hardcoded visitor identifier

@@ -42,3 +133,7 @@ */

this.visitorId = id + '';
cookie.set('sjID', this.visitorId, 365);
cookie.set(opts.cname, this.visitorId, {
path: '/',
expires: opts.expires,
domain: opts.domain
});
}

@@ -64,2 +159,56 @@ return this.visitorId;

/*
* Contains the page view sequence in this session
*/
function getPageSequence() {
var s = cookie.get(opts.sname);
if (s === undefined) {
s = 0;
}
s++;
cookie.set(opts.sname, s, {
path: '/',
domain: opts.domain
});
return s;
}
/*
* Set data in local storage safely if it exists
*/
function setLocal(name, data) {
if (typeof(Storage) !== "undefined") {
localStorage.setItem(name, JSON.stringify(data));
return true;
}
}
/*
* Retrieve data in local storage safely if it exists
*/
function getLocal(name) {
if (typeof(Storage) !== "undefined") {
return JSON.parse(localStorage.getItem(name));
}
}
/*
* Set data in session storage safely if it exists
*/
function setSession(name, data) {
if (typeof(Storage) !== "undefined") {
sessionStorage.setItem(name, JSON.stringify(data));
return true;
}
}
/*
* Retrieve data in session storage safely if it exists
*/
function getSession(name) {
if (typeof(Storage) !== "undefined") {
return JSON.parse(sessionStorage.getItem(name));
}
}
module.exports = profile;

@@ -31,2 +31,6 @@ /*

} else if (node.attachEvent) {
// IE8/9 compatibility
if (eventType == 'input') {
eventType = 'onpropertychange';
}
node.attachEvent('on' + eventType, function (e) { handler.apply(node, [e]); });

@@ -79,3 +83,2 @@ }

if (attrs.hasOwnProperty(key)) {
console.log(key + " " + attrs[key])
// Propagate relevant data parameters from the query input to the results div

@@ -133,5 +136,9 @@ to.setAttribute(this.prefix+key, attrs[key]);

/**
* Returns an object of the dynamic this.prefix attributes. That is, the non-known DOM targets.
* Returns an object of the dynamic attributes (e.g. custom parameters to send with the request)
* Optionally add a prefix to get only specific params
*/
dynamicAttrs : function(node) {
dynamicAttrs : function(node, prefixSuff) {
if (prefixSuff === undefined) {
prefixSuff = "";
}
var m,

@@ -142,3 +149,3 @@ attrs = {};

if (attrib.specified) {
var reg = new RegExp(this.prefix + "(.+)$", "g");
var reg = new RegExp(this.prefix + prefixSuff + "(.+)$", "g");
m = reg.exec(attrib.name);

@@ -154,2 +161,30 @@ if (m && this.targets.indexOf(m[1]) === -1) {

/**
* Returns all the data-sj-meta params from the DOM. Not the most efficient function
* but stuck with this for now and it only runs once.
*/
dynamicMeta : function(node, attrs) {
var all = document.getElementsByTagName("*");
if (attrs === undefined) {
attrs = {};
}
for (var i=0, max=all.length; i < max; i++) {
var matches = this.dynamicAttrs(all[i], 'meta-');
for (m in matches) {
if (matches[m] !== undefined &&matches[m] !== "") {
attrs[m] = matches[m];
continue;
}
if (all[i].content !== undefined && all[i].content !== "") {
attrs[m] = all[i].content;
continue;
}
if (all[i].innerHTML !== undefined &&all[i].innerHTML !== "") {
attrs[m] = all[i].innerHTML;
}
}
}
return attrs
},
/**
* Returns the URI parameters of dynamic this.prefix attributes

@@ -156,0 +191,0 @@ */

@@ -21,1 +21,66 @@

}
/**
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
* (technically, since host objects have been implementation-dependent,
* at least before ES6, IE hasn't needed to work this way).
* Also works on strings, fixes IE < 9 to allow an explicit undefined
* for the 2nd argument (as in Firefox), and prevents errors when
* called on other DOM objects.
*/
(function () {
'use strict';
var _slice = Array.prototype.slice;
try {
// Can't be used with DOM elements in IE < 9
_slice.call(document.documentElement);
} catch (e) { // Fails in IE < 9
// This will work for genuine arrays, array-like objects,
// NamedNodeMap (attributes, entities, notations),
// NodeList (e.g., getElementsByTagName), HTMLCollection (e.g., childNodes),
// and will not fail on other DOM objects (as do DOM elements in IE < 9)
Array.prototype.slice = function(begin, end) {
// IE < 9 gets unhappy with an undefined end argument
end = (typeof end !== 'undefined') ? end : this.length;
// For native Array objects, we use the native slice function
if (Object.prototype.toString.call(this) === '[object Array]'){
return _slice.call(this, begin, end);
}
// For array like object we handle it ourselves.
var i, cloned = [],
size, len = this.length;
// Handle negative value for "begin"
var start = begin || 0;
start = (start >= 0) ? start : Math.max(0, len + start);
// Handle negative value for "end"
var upTo = (typeof end == 'number') ? Math.min(end, len) : len;
if (end < 0) {
upTo = len + end;
}
// Actual expected size of the slice
size = upTo - start;
if (size > 0) {
cloned = new Array(size);
if (this.charAt) {
for (i = 0; i < size; i++) {
cloned[i] = this.charAt(start + i);
}
} else {
for (i = 0; i < size; i++) {
cloned[i] = this[start + i];
}
}
}
return cloned;
};
}
}());

@@ -6,3 +6,3 @@ (function(){function result(it

/**/) {
var out='';if(it.results.length){if(it.renderType == "search"){out+='<p class="sj-search-info">Showing 1-'+(it.results.length)+' of '+(it.totalmatches)+' results '+(it.formattedMsecs)+' seconds)</p>';if(it.fuzzyStr){out+='<p class="sj-search-info sj-search-fuzzy">Showing results for <strong>'+(it.fuzzyStr)+'</strong></p>';}else if(true){}}var arr1=it.results;if(arr1){var res,index=-1,l1=arr1.length-1;while(index<l1){res=arr1[index+=1];out+='<div class="sj-result-item">';if(it.showThumb){if(res.meta.image){out+='<div class="sj-thumb-wrapper"><div class="sj-result-thumb" style="background-image:url('+(res.meta.image)+'"></div></div>';}else if(true){}}out+='<div class="sj-result-wrapper"><div class="sj-result-title" data-docid="'+(res.docId)+'"> <a class="sj-result-link" href="'+(res.meta.url)+'" onmousedown="SJ.SendClick(\''+(it.queryID)+'\', \''+(index+1)+'\', \'res.meta.injected\', this);">'+(res.meta.title)+'</a></div>';if(it.showDesc){out+='<p class="sj-result-meta"><span class="sj-result-meta-desc">'+(res.meta.description)+'</span></p>';}if(it.showMeta.length){var arr2=it.showMeta;if(arr2){var m,i2=-1,l2=arr2.length-1;while(i2<l2){m=arr2[i2+=1];out+='<p class="sj-result-meta"><span class="sj-result-meta-wrapper" data-sj-meta-key="'+(m)+'"><span class="sj-result-meta-name">'+(m)+'</span> <span class="sj-result-meta-value">'+(res.meta[m])+'</span></span></p>';} } }if(it.showUrl){out+='<p class="sj-result-meta"><span class="sj-result-meta-url">'+(res.meta.url)+'</span></p>';}out+='</div></div>';} } }else if(true){if(it.renderType == "search"){out+='<p class="sj-noresults">No results found.</p>';}if(it.errors){out+='<p class="sj-error">Oops! An error occured while searching. Please try again.</p>';}}return out;
var out='';if(it.results.length){if(it.renderType == "search"){out+='<p class="sj-search-info">Showing 1-'+(it.results.length)+' of '+(it.totalmatches)+' results ('+(it.formattedMsecs)+' seconds)</p>';if(it.fuzzyStr){out+='<p class="sj-search-info sj-search-fuzzy">Showing results for <strong>'+(it.fuzzyStr)+'</strong></p>';}else if(true){}}var arr1=it.results;if(arr1){var res,index=-1,l1=arr1.length-1;while(index<l1){res=arr1[index+=1];out+='<div class="sj-result-item">';if(it.showThumb){if(res.meta.image){out+='<div class="sj-thumb-wrapper"><div class="sj-result-thumb" style="background-image:url('+(res.meta.image)+'"></div></div>';}else if(true){}}out+='<div class="sj-result-wrapper"><div class="sj-result-title" data-docid="'+(res.docId)+'"> <a class="sj-result-link" href="'+(res.meta.url)+'" onmousedown="SJ.SendClick(\''+(it.queryID)+'\', \''+(index+1)+'\', \'res.meta.injected\', this);">'+(res.meta.title)+'</a></div>';if(it.showDesc){out+='<p class="sj-result-meta"><span class="sj-result-meta-desc">'+(res.meta.description)+'</span></p>';}if(it.showMeta.length){var arr2=it.showMeta;if(arr2){var m,i2=-1,l2=arr2.length-1;while(i2<l2){m=arr2[i2+=1];out+='<p class="sj-result-meta"><span class="sj-result-meta-wrapper" data-sj-meta-key="'+(m)+'"><span class="sj-result-meta-name">'+(m)+'</span> <span class="sj-result-meta-value">'+(res.meta[m])+'</span></span></p>';} } }if(it.showUrl){out+='<p class="sj-result-meta"><span class="sj-result-meta-url">'+(res.meta.url)+'</span></p>';}out+='</div></div>';} } }else if(true){if(it.renderType == "search"){out+='<p class="sj-noresults">No results found.</p>';}if(it.errors){out+='<p class="sj-error">Oops! An error occured while searching. Please try again.</p>';}}return out;
}var itself=results;itself.result=result;if(typeof module!=='undefined' && module.exports) module.exports=itself;else if(typeof define==='function')define(function(){return itself;});else {window.render=window.render||{};window.render['results']=itself;}}());

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc