Skip to content

Commit

Permalink
1.1.1 - make sure brand_uid is < 7 chars, fixed lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
javidjamae committed Mar 24, 2016
1 parent e28dd13 commit 8fa2372
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"no-mixed-spaces-and-tabs": 2,
"indent": [2, 2],
"no-unused-vars": 1,
"no-console": 2,
"no-console": [2, { allow: ["warn", "error"] }],
"no-underscore-dangle": 0,
"no-alert": 2,
"semi": 2,
Expand Down
2 changes: 1 addition & 1 deletion dist/tout-js-sdk-embed-code.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions spec/embedcode_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ describe("sdk embed code", function () {
expect(document.getElementById("tout-js-sdk")).toBeNull();
});

it("should bail early if brand uid is > 7 characters", function () {
TOUT.init('12345678');

expect(document.getElementById("tout-js-sdk")).toBeNull();
});

it("should bail early if brand uid is the placeholder string in the documentation", function () {
TOUT.init('PUT_YOUR_BRAND_UID_HERE');

Expand Down
2 changes: 1 addition & 1 deletion spec/support/helper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
TOUT._sdkScriptTagParsedAt = new Date;

// Set an embed code version for debugging purposes
TOUT.EMBED_CODE_VERSION='1.1.0';
TOUT.EMBED_CODE_VERSION='1.1.1';

// Setup embed code constants which can be overriden for testing purposes
var sdkHost = TOUT.SDK_HOST || "platform.tout.com",
analyticsHost = TOUT.SDK_ANALYTICS_HOST || "analytics.tout.com";
var sdkHost = TOUT.SDK_HOST || 'platform.tout.com',
analyticsHost = TOUT.SDK_ANALYTICS_HOST || 'analytics.tout.com';

// Setup an onReady handler which can save off any function calls until the sdk script tag has been loaded
TOUT.onReady = function (func) {
Expand All @@ -29,7 +29,7 @@
TOUT.init = function (brandUid, options) {
options = options || {};

var sdkScriptId = "tout-js-sdk";
var sdkScriptId = 'tout-js-sdk';

// Don't load the sdk script tag if it's already been loaded (and they aren't forcing us to init twice)
if (document.getElementById(sdkScriptId) && !options.forceInit) {
Expand All @@ -41,9 +41,13 @@
brandUid = TOUT.SDK_BRAND_UID || brandUid;

// If brand uid isn't configured correctly, ping our analytics servers so Account Services can help that customer.
if (typeof brandUid === "undefined" || typeof brandUid !== 'string' || brandUid.length === 0 || brandUid === "PUT_YOUR_BRAND_UID_HERE") {
if (typeof brandUid === 'undefined' || typeof brandUid !== 'string' || brandUid.length === 0 || brandUid.length > 7) {
var image = new Image();
image.src = "http://" + analyticsHost + "/events?trigger=sdk_log&log_level=error&log_message=BRAND_UID_NOT_DEFINED&content_page_url=" + encodeURIComponent(window.location.href);
image.src = 'http://' + analyticsHost + '/events?trigger=sdk_log&log_level=error&log_message=BRAND_UID_NOT_DEFINED&content_page_url=' + encodeURIComponent(window.location.href);

if(console && console.error) {
console.error('TOUT - Invalid Brand UID: ' + brandUid);
}

// return the instance for chainability
return TOUT;
Expand All @@ -57,7 +61,7 @@
script.type = 'text/javascript';
script.src = '//' + sdkHost + '/sdk/v1/' + brandUid + '.js';
script.id = sdkScriptId;
script.className = "tout-sdk";
script.className = 'tout-sdk';
var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(script, firstScript);

Expand Down

0 comments on commit 8fa2372

Please sign in to comment.