-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore errors when manipulating classes (#75)
- Loading branch information
Showing
6 changed files
with
127 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
@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() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
@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() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
@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() { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "studyjs", | ||
"version": "5.0.2", | ||
"version": "5.0.3", | ||
"author": "Jacob Kelley <[email protected]>", | ||
"homepage": "https://github.com/dollarshaveclub/study", | ||
"description": "A client side A/B tester", | ||
|
Oops, something went wrong.