(function() {
var appScriptEl, assets, betaBranch, betaBranches, betaIsActive, betaName, branch, branches, defaultBetaBranch, defaultBranch, forceBranchParam, headEl, key, protocol, reason, requestedBranch, requestedBy, styleEl, suteamBranch, value, variant;
betaIsActive = false;
betaName = typeof cookie !== "undefined" && cookie !== null ? cookie.get('beta') : void 0;
defaultBranch = 'master';
suteamBranch = 'suteam2';
betaBranch = "beta/" + betaName;
headEl = document.head || document.querySelector('head');
appScriptEl = document.createElement('script');
styleEl = document.createElement('link');
protocol = window.location.protocol;
if ((typeof optimizely !== "undefined" && optimizely !== null ? optimizely.activeExperiments.length : void 0) > 0) {
variant = optimizely.variationNamesMap[optimizely.activeExperiments].toLowerCase();
}
branches = [];
for (key in SUassets) {
value = SUassets[key];
branches.push(key);
}
betaBranches = branches.filter(function(name) {
return name.match('beta');
});
defaultBetaBranch = betaBranches != null ? betaBranches[0] : void 0;
forceBranchParam = 'SUbranch=';
if (window.top.location.search.match(forceBranchParam)) {
requestedBranch = window.top.location.search.split(forceBranchParam).pop();
if (typeof cookie !== "undefined" && cookie !== null) {
cookie.set('b', requestedBranch, {
expires: 7,
path: '/'
});
}
requestedBy = 'get param';
} else if (typeof cookie !== "undefined" && cookie !== null ? cookie.get('b') : void 0) {
requestedBranch = typeof cookie !== "undefined" && cookie !== null ? cookie.get('b') : void 0;
requestedBy = 'cookie';
} else if ((typeof cookie !== "undefined" && cookie !== null ? cookie.get('suteam') : void 0) === 'true') {
requestedBranch = suteamBranch;
requestedBy = 'suteam';
} else if (betaIsActive && (typeof cookie !== "undefined" && cookie !== null ? cookie.get('beta') : void 0)) {
requestedBranch = betaBranch;
requestedBy = 'beta opt-in';
} else if (variant) {
requestedBranch = variant;
requestedBy = 'test';
}
if (requestedBranch) {
console.debug("requesting branch " + requestedBranch + " because " + requestedBy);
}
if (branches.length === 1) {
branch = branches.shift();
reason = 'only one';
} else if (branches.indexOf(requestedBranch) !== -1) {
branch = requestedBranch;
reason = 'requested';
} else if (betaIsActive && branches.indexOf(defaultBetaBranch) !== -1 && requestedBranch === suteamBranch) {
branch = defaultBetaBranch;
reason = 'beta auto opt-in for suteam';
} else {
cookie.remove('b');
cookie.remove('beta');
branch = defaultBranch;
reason = 'default';
}
console.debug("using branch " + branch + " because " + reason);
assets = SUassets[branch][protocol];
styleEl.setAttribute('rel', 'stylesheet');
styleEl.setAttribute('href', assets.css);
if (!(assets.app.match('origin.stumble.net|static'))) {
appScriptEl.setAttribute('crossorigin', 'anonymous');
}
appScriptEl.setAttribute('src', assets.app);
headEl.appendChild(styleEl);
headEl.appendChild(appScriptEl);
appScriptEl.addEventListener('error', function() {
throw new Error("Unable to load " + assets.app + " from " + branch);
}, false);
}).call(this);