| // Generated by CoffeeScript 1.9.3 |
| (function() { |
| var ACTIVITIES, ELEMENTS, default_msg, defaults, extend, getCookie, getParameterByName, setCookie, userale, |
| slice = [].slice, |
| indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; |
| |
| ACTIVITIES = ['ADD', 'REMOVE', 'CREATE', 'DELETE', 'SELECT', 'DESELECT', 'ENTER', 'LEAVE', 'INSPECT', 'ALTER', 'HIDE', 'SHOW', 'OPEN', 'CLOSE', 'PERFORM']; |
| |
| ELEMENTS = ['BUTTON', 'CANVAS', 'CHECKBOX', 'COMBOBOX', 'DATAGRID', 'DIALOG_BOX', 'DROPDOWNLIST', 'FRAME', 'ICON', 'INFOBAR', 'LABEL', 'LINK', 'LISTBOX', 'LISTITEM', 'MAP', 'MENU', 'MODALWINDOW', 'PALETTEWINDOW', 'PANEL', 'PROGRESSBAR', 'RADIOBUTTON', 'SLIDER', 'SPINNER', 'STATUSBAR', 'TAB', 'TABLE', 'TAG', 'TEXTBOX', 'THROBBER', 'TOAST', 'TOOLBAR', 'TOOLTIP', 'TREEVIEW', 'WINDOW', 'WORKSPACE', 'OTHER']; |
| |
| extend = function() { |
| var j, key, len, object, objects, out, value; |
| objects = 1 <= arguments.length ? slice.call(arguments, 0) : []; |
| out = {}; |
| for (j = 0, len = objects.length; j < len; j++) { |
| object = objects[j]; |
| for (key in object) { |
| value = object[key]; |
| out[key] = value; |
| } |
| } |
| return out; |
| }; |
| |
| getParameterByName = function(name) { |
| var regex, results; |
| name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); |
| regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); |
| results = regex.exec(location.search); |
| return results = results ? decodeURIComponent(results[1].replace(/\+/g, " ")) : ""; |
| }; |
| |
| defaults = { |
| loggingUrl: '', |
| toolName: 'UNK', |
| toolVersion: 'UNK', |
| workerUrl: 'userale-worker.js', |
| debug: true, |
| sendLogs: true, |
| elementGroups: [] |
| }; |
| |
| default_msg = { |
| activity: '', |
| action: '', |
| elementId: '', |
| elementType: '', |
| elementGroup: '', |
| elementSub: '', |
| source: '', |
| tags: [], |
| meta: {} |
| }; |
| |
| setCookie = function(cname, cvalue, exdays) { |
| var d, expires; |
| d = new Date(); |
| d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); |
| expires = "expires=" + d.toUTCString(); |
| return document.cookie = cname + "=" + cvalue + "; " + expires; |
| }; |
| |
| getCookie = function(name) { |
| var c, ca, i, nameEQ; |
| nameEQ = name + "="; |
| ca = document.cookie.split(";"); |
| i = 0; |
| while (i < ca.length) { |
| c = ca[i]; |
| while (c.charAt(0) === " ") { |
| c = c.substring(1, c.length); |
| } |
| if (c.indexOf(nameEQ) === 0) { |
| return c.substring(nameEQ.length, c.length).replace(/"/g, ''); |
| } |
| i++; |
| } |
| return ""; |
| }; |
| |
| userale = (function() { |
| function userale(options) { |
| this.options = extend(defaults, options); |
| if (this.options.elementGroups.constructor === !Array) { |
| this.options.elementGroups = [this.options.elementGroups]; |
| } |
| this.options.version = '3.0.1'; |
| this.worker = new Worker(this.options.workerUrl); |
| this.worker.postMessage({ |
| cmd: 'setLoggingUrl', |
| msg: this.options.loggingUrl |
| }); |
| this.debug(this.options.debug); |
| this.sendLogs(this.options.sendLogs); |
| } |
| |
| userale.prototype.register = function() { |
| if (getParameterByName('USID')) { |
| this.options.sessionID = getParameterByName('USID'); |
| setCookie('USID', this.options.sessionID, 2); |
| console.info('USERALE: SESSION ID FOUND IN URL - ' + this.options.sessionID); |
| } else if (getCookie('USID')) { |
| this.options.sessionID = getCookie('USID'); |
| console.info('USERALE: SESSION ID FOUND IN COOKIE - ' + this.options.sessionID); |
| } else { |
| this.options.sessionID = this.options.toolName.slice(0, 3).toUpperCase() + new Date().getTime(); |
| setCookie('USID', this.options.sessionID, 2); |
| console.warn('USERALE: NO SESSION ID, MAKING ONE UP. You can pass one in as url parameter (127.0.0.1?USID=12345)'); |
| } |
| if (getParameterByName('client')) { |
| this.options.client = getParameterByName('client'); |
| setCookie('USERALECLIENT', this.options.client, 2); |
| console.info('USERALE: CLIENT FOUND IN URL - ' + this.options.client); |
| } else if (getCookie('USERALECLIENT')) { |
| this.options.client = getCookie('USERALECLIENT'); |
| console.info('USERALE: CLIENT FOUND IN COOKIE - ' + this.options.client); |
| } else { |
| this.options.client = 'UNK'; |
| setCookie('USERALECLIENT', this.options.client, 2); |
| console.warn('USERALE: NO CLIENT, MAKING ONE UP. You can pass one in as url parameter (127.0.0.1?client=roger)'); |
| } |
| this.worker.postMessage({ |
| cmd: 'sendBuffer', |
| msg: '' |
| }); |
| window.onload = (function(_this) { |
| return function() { |
| var msg; |
| msg = { |
| activity: 'show', |
| action: 'onload', |
| elementId: 'window', |
| elementType: 'window', |
| elementGroup: 'top', |
| source: 'user' |
| }; |
| return _this.log(msg); |
| }; |
| })(this); |
| window.onbeforeunload = (function(_this) { |
| return function() { |
| var msg; |
| msg = { |
| activity: 'hide', |
| action: 'onbeforeunload', |
| elementId: 'window', |
| elementType: 'window', |
| elementGroup: 'top', |
| source: 'user' |
| }; |
| return _this.log(msg); |
| }; |
| })(this); |
| window.onfocus = (function(_this) { |
| return function() { |
| var msg; |
| msg = { |
| activity: 'show', |
| action: 'onfocus', |
| elementId: 'window', |
| elementType: 'window', |
| elementGroup: 'top', |
| source: 'user' |
| }; |
| return _this.log(msg); |
| }; |
| })(this); |
| return window.onblur = (function(_this) { |
| return function() { |
| var msg; |
| msg = { |
| activity: 'hide', |
| action: 'onblur', |
| elementId: 'window', |
| elementType: 'window', |
| elementGroup: 'top', |
| source: 'user' |
| }; |
| return _this.log(msg); |
| }; |
| })(this); |
| }; |
| |
| userale.prototype.log = function(msg) { |
| var activities, activity, j, key, len, value, x; |
| msg = extend(default_msg, msg); |
| for (key in msg) { |
| value = msg[key]; |
| if (key === 'elementType') { |
| value = value.toUpperCase(); |
| if (indexOf.call(ELEMENTS, value) < 0) { |
| console.warn("USERALE: Unrecognized element - " + value); |
| } else if ((value === 'OTHER') && (msg.meta.element == null)) { |
| console.warn("USERALE: Element type set to 'other', but 'element' not set in meta object "); |
| } |
| msg.elementType = msg.elementType.toUpperCase(); |
| } |
| if (key === 'elementGroup') { |
| if ((value === !'top') && (indexOf.call(this.options.elementGroups, value) < 0)) { |
| console.warn(value + " is NOT in element groups"); |
| } |
| } |
| if (key === 'activity') { |
| activities = (function() { |
| var j, len, ref, results1; |
| ref = value.split('_'); |
| results1 = []; |
| for (j = 0, len = ref.length; j < len; j++) { |
| x = ref[j]; |
| results1.push(x.toUpperCase()); |
| } |
| return results1; |
| })(); |
| for (j = 0, len = activities.length; j < len; j++) { |
| activity = activities[j]; |
| if (indexOf.call(ACTIVITIES, activity) < 0) { |
| console.warn("USERALE: Unrecognized activity - " + activity); |
| } |
| } |
| msg[key] = activities; |
| } |
| if (key === 'source') { |
| value = value.toUpperCase(); |
| if (value !== 'USER' && value !== 'SYSTEM' && value !== 'UNK') { |
| console.warn("USERALE: Unrecognized source - " + value); |
| msg[key] = null; |
| } else { |
| msg[key] = value.toUpperCase(); |
| } |
| } |
| } |
| msg.timestamp = new Date().toJSON(); |
| msg.client = this.options.client; |
| msg.toolName = this.options.toolName; |
| msg.toolVersion = this.options.toolVersion; |
| msg.sessionID = this.options.sessionID; |
| msg.language = 'JavaScript'; |
| msg.useraleVersion = this.options.version; |
| return this.worker.postMessage({ |
| cmd: 'sendMsg', |
| msg: msg |
| }); |
| }; |
| |
| userale.prototype.debug = function(onOff) { |
| this.options.debug = onOff; |
| return this.worker.postMessage({ |
| cmd: 'setEcho', |
| msg: onOff |
| }); |
| }; |
| |
| userale.prototype.sendLogs = function(onOff) { |
| this.options.sendLogs = onOff; |
| return this.worker.postMessage({ |
| cmd: 'setTesting', |
| msg: !onOff |
| }); |
| }; |
| |
| return userale; |
| |
| })(); |
| |
| this.userale = userale; |
| |
| }).call(this); |