Skip to content

Commit

Permalink
Merge pull request #1 from issartdeveloper/master
Browse files Browse the repository at this point in the history
 ISS Art fork
  • Loading branch information
adrienmo authored Jun 17, 2016
2 parents ae119fe + bdde92b commit c2a70b7
Show file tree
Hide file tree
Showing 38 changed files with 1,366 additions and 5,511 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
index.html
test.html
testpage2.html
testpage1.html
testpages/*
testpages/*
node_modules/**
build/**
75 changes: 75 additions & 0 deletions app/Cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
define(["./base64"], function(base64) {

var _options = {};
function options() {
return _options;
}

function _topDomain(domain) {
return domain.split('.').slice(-2).join('.');
}


function init(opts) {
_options.expirationDays = opts.expirationDays || _options.expirationDays;
var domain = (opts.domain !== undefined) ? opts.domain : _topDomain(window.location.hostname);
_options.domain = domain || null;
}

function get(name) {
try {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"));
var value = matches ? decodeURIComponent(matches[1]) : undefined;
if (value) {
return JSON.parse(base64.decode(value));
}
return null;
} catch (e) {
return null;
}
};


function set(name, value) {
try {
_set(name, base64.encode(JSON.stringify(value)));
} catch (e) {
}
}


function _set(name, value) {
var expires = value !== null ? _options.expirationDays : -1 ;
if (expires) {
var date = new Date();
date.setTime(date.getTime() + (expires * 24 * 60 * 60 * 1000));
expires = date;
}
var cookie = name + '=' + value;
if (expires) {
cookie += '; expires=' + expires.toUTCString();
}
cookie += '; path=/';
if (_options.domain) {
cookie += '; domain=' + _options.domain;
}
document.cookie = cookie;
}

function remove(name) {
try {
_set(name, null);
} catch (e) {
}
}


return {
options: options,
get: get,
set: set,
remove: remove,
init: init
};
});
19 changes: 19 additions & 0 deletions app/DefaultOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
define(function() {
return {
apiEndpoint: 'https://api.tongrd.com/v2/events',
cookieExpirationDays: 365 * 5,
cookieName: 'tongdao_id',
domain: undefined,
includeUtm: false,
language: require('./Language').getLanguage(),
optOut: false,
platform: 'Web',
sessionTimeout: 30 * 60 * 1000,
unsentKey: 'tongdao_unsent',
unsentIdentifyKey: 'tongdao_unsent_identify',
uploadBatchSize: 100,
eventUploadThreshold: 30,
eventUploadPeriodMillis: 30 * 1000,
changeUrlDetectionMillis: 500
}
});
8 changes: 8 additions & 0 deletions app/Language.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define(function() {
return {
getLanguage: function getLanguage() {
return (navigator && ((navigator.languages && navigator.languages[0]) ||
navigator.language || navigator.userLanguage)) || undefined;
}
};
});
43 changes: 43 additions & 0 deletions app/Request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
define(function() {

var Request = function(url, data, appKey, async) {
this.url = url;
this.data = data || {};
this.appKey = appKey;
this.async = async;
};

Request.prototype.post = function(callback) {
var isIE = window.XDomainRequest ? true : false;
var data = JSON.stringify(this.data);
if (isIE) {
var xdr = new window.XDomainRequest();
xdr.open('POST', this.url, this.async);
xdr.onload = function() {
callback(200, xdr.responseText);
};
xdr.onerror = function () {
if (xdr.responseText === 'Request Entity Too Large') {
callback(413, xdr.responseText);
} else {
callback(500, xdr.responseText);
}
};
xdr.ontimeout = function () {};
xdr.onprogress = function() {};
xdr.send(data);
} else {
var xhr = new XMLHttpRequest();
xhr.open('POST', this.url, this.async);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
callback(xhr.status, xhr.responseText);
}
};
xhr.setRequestHeader('X-APP-KEY', this.appKey);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(data);
}
}
return Request;
});
43 changes: 43 additions & 0 deletions app/TdOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
define(function() {

function TdOrder() {
}

TdOrder.prototype.setOrderId = function(id) {
this['!order_id'] = id;
};

TdOrder.prototype.setCurrency = function(currency) {
this['!currency'] = currency;
};

TdOrder.prototype.setTotal = function(total) {
this['!total'] = total;
};

TdOrder.prototype.setRevenue = function(revenue) {
this['!revenue'] = revenue;
};

TdOrder.prototype.setOrderLines = function(orderLines) {
this['!order_lines'] = orderLines;
};

TdOrder.prototype.setShipping = function(shipping) {
this['!shipping'] = shipping;
};

TdOrder.prototype.setTax = function(tax) {
this['!tax'] = tax;
};

TdOrder.prototype.setDiscount = function(discount) {
this['!discount'] = discount;
};

TdOrder.prototype.setCouponId = function(couponId) {
this['!coupon_id'] = couponId;
};

return TdOrder;
});
15 changes: 15 additions & 0 deletions app/TdOrderLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
define(function() {

function TdOrderLine() {
}

TdOrderLine.prototype.setProduct = function(product) {
this['!product'] = product;
};

TdOrderLine.prototype.setQuantity = function(quantity) {
this['!quantity'] = quantity;
};

return TdOrderLine;
});
31 changes: 31 additions & 0 deletions app/TdProduct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
define(function() {

function TdProduct() {
}

TdProduct.prototype.setId = function(id) {
this['!id'] = id;
};

TdProduct.prototype.setCurrency = function(currency) {
this['!currency'] = currency;
};

TdProduct.prototype.setSku = function(sku) {
this['!sku'] = sku;
};

TdProduct.prototype.setName = function(name) {
this['!name'] = name;
};

TdProduct.prototype.setPrice = function(price) {
this['!price'] = price;
};

TdProduct.prototype.setCategory = function(category) {
this['!category'] = category;
};

return TdProduct;
});
Loading

0 comments on commit c2a70b7

Please sign in to comment.