diff --git a/build/study.dev.js b/build/study.dev.js index 3ed0118..4d8a758 100644 --- a/build/study.dev.js +++ b/build/study.dev.js @@ -1,6 +1,6 @@ /** studyjs - A client side A/B tester - @version v5.0.2 + @version v5.0.3 @link https://github.com/dollarshaveclub/study @author Jacob Kelley @license MIT @@ -37,7 +37,7 @@ var getDefaultBucket = function getDefaultBucket(buckets) { var defaultBuckets = Object.keys(buckets).filter(function (name) { var x = buckets[name]; - return x.default || x.winner; + return x["default"] || x.winner; }); return defaultBuckets[0] || Object.keys(buckets)[0]; }; @@ -112,37 +112,43 @@ }; _proto.removeClasses = function removeClasses(testName, exceptClassName) { - var root = this.root; - if (!root) return; // classList does not support returning all classes - - var currentClassNames = root.className.split(/\s+/g).map(function (x) { - return x.trim(); - }).filter(Boolean); - currentClassNames.filter(function (x) { - return x.indexOf(testName + "--") === 0; - }).filter(function (className) { - return className !== exceptClassName; - }).forEach(function (className) { - return root.classList.remove(className); - }); + try { + var root = this.root; + if (!root) return; // classList does not support returning all classes + + var currentClassNames = root.className.split(/\s+/g).map(function (x) { + return x.trim(); + }).filter(Boolean); + currentClassNames.filter(function (x) { + return x.indexOf(testName + "--") === 0; + }).filter(function (className) { + return className !== exceptClassName; + }).forEach(function (className) { + return root.classList.remove(className); + }); + } catch (_) {// Ignore + } }; _proto.applyClasses = function applyClasses() { var _this2 = this; - var userAssignments = this.userAssignments, - root = this.root; - if (!root) return; - Object.keys(userAssignments).forEach(function (testName) { - var bucket = userAssignments[testName]; - var className = bucket ? testName + "--" + bucket : null; // remove all classes related to this bucket + try { + var userAssignments = this.userAssignments, + root = this.root; + if (!root) return; + Object.keys(userAssignments).forEach(function (testName) { + var bucket = userAssignments[testName]; + var className = bucket ? testName + "--" + bucket : null; // remove all classes related to this bucket - _this2.removeClasses(testName, className); // only assign a class is the test is assigned to a bucket - // this removes then adds a class, which is not ideal but is clean + _this2.removeClasses(testName, className); // only assign a class is the test is assigned to a bucket + // this removes then adds a class, which is not ideal but is clean - if (className) root.classList.add(className); - }); + if (className) root.classList.add(className); + }); + } catch (_) {// Ignore + } }; _proto.assignAll = function assignAll() { diff --git a/build/study.es.js b/build/study.es.js index 3376ada..752f01d 100644 --- a/build/study.es.js +++ b/build/study.es.js @@ -1,6 +1,6 @@ /** studyjs - A client side A/B tester - @version v5.0.2 + @version v5.0.3 @link https://github.com/dollarshaveclub/study @author Jacob Kelley @license MIT @@ -31,7 +31,7 @@ var chooseWeightedItem = function chooseWeightedItem(names, weights) { var getDefaultBucket = function getDefaultBucket(buckets) { var defaultBuckets = Object.keys(buckets).filter(function (name) { var x = buckets[name]; - return x.default || x.winner; + return x["default"] || x.winner; }); return defaultBuckets[0] || Object.keys(buckets)[0]; }; @@ -106,37 +106,43 @@ function () { }; _proto.removeClasses = function removeClasses(testName, exceptClassName) { - var root = this.root; - if (!root) return; // classList does not support returning all classes - - var currentClassNames = root.className.split(/\s+/g).map(function (x) { - return x.trim(); - }).filter(Boolean); - currentClassNames.filter(function (x) { - return x.indexOf(testName + "--") === 0; - }).filter(function (className) { - return className !== exceptClassName; - }).forEach(function (className) { - return root.classList.remove(className); - }); + try { + var root = this.root; + if (!root) return; // classList does not support returning all classes + + var currentClassNames = root.className.split(/\s+/g).map(function (x) { + return x.trim(); + }).filter(Boolean); + currentClassNames.filter(function (x) { + return x.indexOf(testName + "--") === 0; + }).filter(function (className) { + return className !== exceptClassName; + }).forEach(function (className) { + return root.classList.remove(className); + }); + } catch (_) {// Ignore + } }; _proto.applyClasses = function applyClasses() { var _this2 = this; - var userAssignments = this.userAssignments, - root = this.root; - if (!root) return; - Object.keys(userAssignments).forEach(function (testName) { - var bucket = userAssignments[testName]; - var className = bucket ? testName + "--" + bucket : null; // remove all classes related to this bucket + try { + var userAssignments = this.userAssignments, + root = this.root; + if (!root) return; + Object.keys(userAssignments).forEach(function (testName) { + var bucket = userAssignments[testName]; + var className = bucket ? testName + "--" + bucket : null; // remove all classes related to this bucket - _this2.removeClasses(testName, className); // only assign a class is the test is assigned to a bucket - // this removes then adds a class, which is not ideal but is clean + _this2.removeClasses(testName, className); // only assign a class is the test is assigned to a bucket + // this removes then adds a class, which is not ideal but is clean - if (className) root.classList.add(className); - }); + if (className) root.classList.add(className); + }); + } catch (_) {// Ignore + } }; _proto.assignAll = function assignAll() { diff --git a/build/study.js b/build/study.js index 3ed0118..4d8a758 100644 --- a/build/study.js +++ b/build/study.js @@ -1,6 +1,6 @@ /** studyjs - A client side A/B tester - @version v5.0.2 + @version v5.0.3 @link https://github.com/dollarshaveclub/study @author Jacob Kelley @license MIT @@ -37,7 +37,7 @@ var getDefaultBucket = function getDefaultBucket(buckets) { var defaultBuckets = Object.keys(buckets).filter(function (name) { var x = buckets[name]; - return x.default || x.winner; + return x["default"] || x.winner; }); return defaultBuckets[0] || Object.keys(buckets)[0]; }; @@ -112,37 +112,43 @@ }; _proto.removeClasses = function removeClasses(testName, exceptClassName) { - var root = this.root; - if (!root) return; // classList does not support returning all classes - - var currentClassNames = root.className.split(/\s+/g).map(function (x) { - return x.trim(); - }).filter(Boolean); - currentClassNames.filter(function (x) { - return x.indexOf(testName + "--") === 0; - }).filter(function (className) { - return className !== exceptClassName; - }).forEach(function (className) { - return root.classList.remove(className); - }); + try { + var root = this.root; + if (!root) return; // classList does not support returning all classes + + var currentClassNames = root.className.split(/\s+/g).map(function (x) { + return x.trim(); + }).filter(Boolean); + currentClassNames.filter(function (x) { + return x.indexOf(testName + "--") === 0; + }).filter(function (className) { + return className !== exceptClassName; + }).forEach(function (className) { + return root.classList.remove(className); + }); + } catch (_) {// Ignore + } }; _proto.applyClasses = function applyClasses() { var _this2 = this; - var userAssignments = this.userAssignments, - root = this.root; - if (!root) return; - Object.keys(userAssignments).forEach(function (testName) { - var bucket = userAssignments[testName]; - var className = bucket ? testName + "--" + bucket : null; // remove all classes related to this bucket + try { + var userAssignments = this.userAssignments, + root = this.root; + if (!root) return; + Object.keys(userAssignments).forEach(function (testName) { + var bucket = userAssignments[testName]; + var className = bucket ? testName + "--" + bucket : null; // remove all classes related to this bucket - _this2.removeClasses(testName, className); // only assign a class is the test is assigned to a bucket - // this removes then adds a class, which is not ideal but is clean + _this2.removeClasses(testName, className); // only assign a class is the test is assigned to a bucket + // this removes then adds a class, which is not ideal but is clean - if (className) root.classList.add(className); - }); + if (className) root.classList.add(className); + }); + } catch (_) {// Ignore + } }; _proto.assignAll = function assignAll() { diff --git a/build/study.min.js b/build/study.min.js index 44b2113..b2029e1 100644 --- a/build/study.min.js +++ b/build/study.min.js @@ -1,8 +1,8 @@ /** studyjs - A client side A/B tester - @version v5.0.2 + @version v5.0.3 @link https://github.com/dollarshaveclub/study @author Jacob Kelley @license MIT **/ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Study=t()}(this,function(){"use strict";var s,t=function(e,t){if(e.length!==t.length)throw new Error("names and weights must have equal length!");for(var s,n,r=t.reduce(function(e,t){return e+t},0),i=0,o=(s=0,n=r,Math.random()*(n-s)+s),u=0;u", "homepage": "https://github.com/dollarshaveclub/study", "description": "A client side A/B tester", diff --git a/src/study.js b/src/study.js index e94a981..18cdbea 100644 --- a/src/study.js +++ b/src/study.js @@ -49,35 +49,43 @@ export default class Study { } removeClasses (testName, exceptClassName) { - const { root } = this - if (!root) return - - // classList does not support returning all classes - const currentClassNames = root.className.split(/\s+/g) - .map(x => x.trim()) - .filter(Boolean) - - currentClassNames - .filter(x => x.indexOf(`${testName}--`) === 0) - .filter(className => className !== exceptClassName) - .forEach(className => root.classList.remove(className)) + try { + const { root } = this + if (!root) return + + // classList does not support returning all classes + const currentClassNames = root.className.split(/\s+/g) + .map(x => x.trim()) + .filter(Boolean) + + currentClassNames + .filter(x => x.indexOf(`${testName}--`) === 0) + .filter(className => className !== exceptClassName) + .forEach(className => root.classList.remove(className)) + } catch (_) { + // Ignore + } } applyClasses () { - const { userAssignments, root } = this - if (!root) return + try { + const { userAssignments, root } = this + if (!root) return - Object.keys(userAssignments).forEach((testName) => { - const bucket = userAssignments[testName] + Object.keys(userAssignments).forEach((testName) => { + const bucket = userAssignments[testName] - const className = bucket ? `${testName}--${bucket}` : null - // remove all classes related to this bucket - this.removeClasses(testName, className) + const className = bucket ? `${testName}--${bucket}` : null + // remove all classes related to this bucket + this.removeClasses(testName, className) - // only assign a class is the test is assigned to a bucket - // this removes then adds a class, which is not ideal but is clean - if (className) root.classList.add(className) - }) + // only assign a class is the test is assigned to a bucket + // this removes then adds a class, which is not ideal but is clean + if (className) root.classList.add(className) + }) + } catch (_) { + // Ignore + } } assignAll () {