From 8d3e0c29e1bde5df422c6f134b425bcc0143e337 Mon Sep 17 00:00:00 2001 From: Stuart Date: Wed, 13 Feb 2019 13:10:31 -0500 Subject: [PATCH] js syntax fixes --- src/browser.js | 10 +++++----- src/cookie.js | 25 ++++++++++++------------- src/helpers.js | 10 +++++----- src/pixel.js | 20 ++++++++++---------- src/setup.js | 10 +++++----- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/browser.js b/src/browser.js index 6e851fb..4a09b3c 100644 --- a/src/browser.js +++ b/src/browser.js @@ -1,13 +1,13 @@ var Browser = { - nameAndVersion(){ + nameAndVersion() { // http://stackoverflow.com/questions/5916900/how-can-you-detect-the-version-of-a-browser var ua= navigator.userAgent, tem, M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; - if(/trident/i.test(M[1])){ + if (/trident/i.test(M[1])) { tem= /\brv[ :]+(\d+)/g.exec(ua) || []; return 'IE '+(tem[1] || ''); } - if(M[1]=== 'Chrome'){ + if (M[1]=== 'Chrome') { tem= ua.match(/\b(OPR|Edge)\/(\d+)/); if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera'); } @@ -16,11 +16,11 @@ var Browser = { return M.join(' '); }, - isMobile(){ + isMobile() { return 'ontouchstart' in document; }, - userAgent(){ + userAgent() { return window.navigator.userAgent; } } diff --git a/src/cookie.js b/src/cookie.js index 8d48ac1..b9bbd15 100644 --- a/src/cookie.js +++ b/src/cookie.js @@ -1,7 +1,7 @@ //http://www.w3schools.com/js/js_cookies.asp var Cookie = { - prefix(){ + prefix() { return '__' + pixelFuncName + '_'; }, @@ -18,7 +18,7 @@ var Cookie = { get(name) { var name = this.prefix() + name + "="; var ca = document.cookie.split(';'); - for(var i=0; i{return Config.id}, // website Id uid: ()=>{return Cookie.get('uid')}, // user Id @@ -43,23 +43,23 @@ class Pixel { } } - setParam(key, val){ - if(isset(val)){ + setParam(key, val) { + if (isset(val)) { this.params.push(key+'='+val); } else { this.params.push(key+'='); } } - send(){ + send() { window.navigator.sendBeacon ? this.sendBeacon() : this.sendImage(); } - sendBeacon(){ + sendBeacon() { window.navigator.sendBeacon(this.getSourceUrl()); } - sendImage(){ + sendImage() { this.img = document.createElement('img'); this.img.src = this.getSourceUrl(); this.img.style.display = 'none'; @@ -68,7 +68,7 @@ class Pixel { document.getElementsByTagName('body')[0].appendChild(this.img); } - getSourceUrl(){ + getSourceUrl() { return pixelEndpoint + '?' + encodeURI(this.params.join('&')); } } diff --git a/src/setup.js b/src/setup.js index ed8ec4e..d8d7194 100644 --- a/src/setup.js +++ b/src/setup.js @@ -5,7 +5,7 @@ Cookie.setUtms(); // process the queue and future incoming commands pixelFunc.process = function(method, value, optinal) { - if(method == 'init') { + if (method == 'init') { Config.id = value; } else if(method == 'event') { if(value == 'pageload' && !Config.pageLoadOnce){ @@ -20,18 +20,18 @@ pixelFunc.process = function(method, value, optinal) { } // run the queued calls from the snippet to be processed -for(var i = 0, l = pixelFunc.queue.length; i < l; i++) { +for (var i = 0, l = pixelFunc.queue.length; i < l; i++) { pixelFunc.process.apply(pixelFunc, pixelFunc.queue[i]); } window.addEventListener('unload', function() { - if(!Config.pageCloseOnce){ + if (!Config.pageCloseOnce) { Config.pageCloseOnce = true; // set 10 minutes page close cookie // Cookie.throttle('pageclose'); new Pixel('pageclose', now(), function(){ // if a link was clicked in the last 5 seconds that goes to an external host, pass it through as event data - if(isset(Config.externalHost) && (now() - Config.externalHost.time) < 5*1000){ + if (isset(Config.externalHost) && (now() - Config.externalHost.time) < 5*1000) { return Config.externalHost.link; } }); @@ -42,7 +42,7 @@ window.onload = function() { var aTags = document.getElementsByTagName('a'); for (var i = 0, l = aTags.length; i < l; i++) { aTags[i].addEventListener('click', function(e) { - if(Url.externalHost(this)){ + if (Url.externalHost(this)) { Config.externalHost = {link:this.href, time:now()}; } }.bind(aTags[i]));