Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Added jshint node package and made appropriate changes
  • Loading branch information
draperlab committed Aug 12, 2014
1 parent 365d175 commit 8a3bcb507232696577ebfc226275d98de821da0d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
@@ -0,0 +1 @@
node_modules/
@@ -14,7 +14,7 @@
function activityLogger(webWorkerURL) {
'use strict';

var draperLog = {version: "2.1.1"}; // semver
var draperLog = {version: "2.1.1"}; // semver

draperLog.worker = new Worker(webWorkerURL);

@@ -50,25 +50,25 @@ function activityLogger(webWorkerURL) {

draperLog.url = url;
draperLog.componentName = componentName;
draperLog.componentVersion = componentVersion;
draperLog.componentVersion = componentVersion;

// get session id from url
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

draperLog.sessionID = getParameterByName('USID');
draperLog.clientHostname = getParameterByName('client')
draperLog.clientHostname = getParameterByName('client');

if (!draperLog.sessionID) {
draperLog.sessionID = draperLog.componentName.slice(0,3) + new Date().getTime()
draperLog.sessionID = draperLog.componentName.slice(0,3) + new Date().getTime();
}

if (!draperLog.clientHostname) {
draperLog.clientHostname = 'UNK'
draperLog.clientHostname = 'UNK';
}

// set the logging URL on the Web Worker
@@ -84,21 +84,21 @@ function activityLogger(webWorkerURL) {
console.log('DRAPER LOG: (TESTING) Registered Activity Logger ' + draperLog.sessionID);
} else {
console.log('DRAPER LOG: Registered Activity Logger ' + draperLog.sessionID);
}
}
}

draperLog.worker.postMessage({
cmd: 'sendBuffer',
msg: ''
});

window.onbeforeunload = function(){
draperLog.logUserActivity(
'window closing',
'window_closed',
draperLog.WF_OTHER
)
);

draperLog.worker.postMessage({
cmd: 'sendBuffer',
msg: ''
@@ -110,16 +110,16 @@ function activityLogger(webWorkerURL) {
'window gained focus',
'window_focus',
draperLog.WF_OTHER
)
}
);
};

window.onblur = function() {
draperLog.logUserActivity(
'window lost focus',
'window_blur',
draperLog.WF_OTHER
)
}
);
};

return draperLog;
};
@@ -9,19 +9,19 @@ function timerMethod() {

if (logBuffer.length) {
if (echo) {
console.log(msg + 'sent ' + logBuffer.length + ' logs to - ' + loggingUrl)
console.log(msg + 'sent ' + logBuffer.length + ' logs to - ' + loggingUrl);
}
if (!testing) {
XHR(loggingUrl + '/send_log', logBuffer, function(d) {
logBuffer = [];
})
});
} else {
logBuffer = [];
}
}
} else {
if (echo) {
console.log(msg + 'no log sent, buffer empty.')
}
console.log(msg + 'no log sent, buffer empty.');
}
}
}

@@ -34,13 +34,13 @@ self.addEventListener('message', function(e) {
loggingUrl = data.msg;
break;
case 'sendMsg':
logBuffer.push(data.msg)
logBuffer.push(data.msg);
break;
case 'setTesting':
if (data.msg) {
var msg = 'DRAPER LOG: (TESTING) ';
msg = 'DRAPER LOG: (TESTING) ';
} else {
var msg = 'DRAPER LOG: ';
msg = 'DRAPER LOG: ';
}
testing = data.msg;
break;
@@ -50,28 +50,28 @@ self.addEventListener('message', function(e) {
case 'sendBuffer':
sendBuffer();
break;
};
}
}, false);


function sendBuffer() {
// method to force send the buffer
timerMethod();
if (echo) {
console.log(msg + ' buffer sent')
}
console.log(msg + ' buffer sent');
}
}
//simple XHR request in pure raw JavaScript
function XHR(url, log, callback) {
var xhr;

if(typeof XMLHttpRequest !== 'undefined') xhr = new XMLHttpRequest();
else {
var versions = ["MSXML2.XmlHttp.5.0",
var versions = ["MSXML2.XmlHttp.5.0",
"MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.2.0",
"Microsoft.XmlHttp"]
"Microsoft.XmlHttp"];

for(var i = 0, len = versions.length; i < len; i++) {
try {
@@ -81,24 +81,24 @@ function XHR(url, log, callback) {
catch(e){}
} // end for
}

xhr.onreadystatechange = ensureReadiness;

function ensureReadiness() {
if(xhr.readyState < 4) {
return;
}

if(xhr.status !== 200) {
return;
}

// all is well
// all is well
if(xhr.readyState === 4) {
callback(xhr);
}
}
}

xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify(log));
@@ -0,0 +1,12 @@
{
"name": "user-ale",
"version": "0.0.1",
"description": "User Activity Logging Engine",
"main": "draper.activity_logger-2.1.1.js",
"dependencies": {
"jshint": "^2.5.3"
},
"devDependencies": {},
"author": "Draper Laboratory",
"license": "ISC"
}

0 comments on commit 8a3bcb5

Please sign in to comment.