"use strict";
var pipelineRequest = function () {
var nextRequestId = 1;
var pipelineHandlers = {};
window.addEventListener("message", function (event) {
if (event.source === window.top && typeof event.data === "string") {
try {
var message = JSON.parse(event.data);
} catch (e) {
return;
}
if (message.pipeline && message.id) {
if (pipelineHandlers[message.id]) {
pipelineHandlers[message.id](message.payload);
delete pipelineHandlers[message.id];
} else {
console.log("Unexpected id #" + message.id + " for " + message.eventName);
}
}
}
});
return function (eventName, payload, callback) {
var id = nextRequestId++;
if (typeof callback === "function") {
pipelineHandlers[id] = callback;
}
window.top.postMessage(JSON.stringify({
pipeline: true,
id: id,
eventName: eventName,
payload: payload
}), "*");
};
}();
function sendToGTM(_ref) {
var label = _ref.label,
trigger = _ref.trigger,
action = _ref.action,
value = _ref.value,
pipelineEvent = _ref.pipelineEvent;
pipelineEvent = pipelineEvent || "gtm_event";
pipelineRequest(pipelineEvent, {
label: label,
trigger: trigger,
action: action,
value: value
});
}
function setCookie(cookieName, cookieValue, expireDay, cookiePath) {
pipelineRequest("set_cookie", {
cookieName: cookieName,
cookieValue: cookieValue,
expireDay: expireDay,
cookiePath: cookiePath
});
}
function registerNewsletter(email) {
pipelineRequest("register_newsletter", {
email: email
});
}
function setModalDetails(modalName, modalParams) {
pipelineRequest("set_modal_details", {
modalName: modalName,
modalParams: modalParams
});
}
function addStyle(styleObj) {
var style = document.createElement('style');
style.type = 'text/css';
var text = "";
for (var key in styleObj) {
text += key + " {\n";
for (var attr in styleObj[key]) {
text += " " + attr + ": " + styleObj[key][attr] + ";\n";
}
text += "}\n\n";
}
style.innerHTML = text;
document.getElementsByTagName('head')[0].appendChild(style);
}
function addScript(src, attrs) {
var script = document.createElement("script");
document.getElementsByTagName("head")[0].appendChild(script);
for (var attr in attrs) {
script.setAttribute(attr, attrs[attr]);
}
script.setAttribute("type", "text/javascript");
script.setAttribute("src", src);
}
var getHostName = function () {
var callbacks = [];
var hostname = null;
pipelineRequest("get_suzuka", undefined, function (payload) {
hostname = payload.url;
for (var x = 0; x < callbacks.length; x++) {
callbacks[x](hostname);
}
callbacks = null;
});
return function (callback) {
if (callbacks !== null) {
callbacks.push(callback);
} else {
callback(hostname);
}
};
}();
var getHash = function () {
var callbacks = [];
var hash = null;
pipelineRequest("get_hash", undefined, function (payload) {
hash = payload.hash;
for (var x = 0; x < callbacks.length; x++) {
callbacks[x](hash);
}
callbacks = null;
});
return function (callback) {
if (callbacks !== null) {
callbacks.push(callback);
} else {
callback(hostname);
}
};
}();
function getJSON(url, params, callback) {
var handled = false;
var handle = function handle(data) {
if (!handled) {
handled = true;
callback(data);
}
};
setTimeout(function () {
handle(null);
}, 10 * 1000);
if (params) {
url += "?";
for (var key in params) {
url += encodeURI(key) + "=" + encodeURI(params[key]) + "&";
}
url = url.slice(0, -1);
}
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function () {
if (this.status >= 200 && this.status < 300) {
try {
handle(JSON.parse(this.response));
} catch (e) {
console.error(e);
handle(null);
}
} else {
handle(null);
}
};
request.onerror = function () {
handle(null);
};
request.send();
}
function getClosest(element, tagName) {
while (element) {
if (element.tagName === tagName) {
return element;
}
element = element.parentElement;
}
return null;
}
/*function initSentry() {
Sentry.init({
dsn: 'https://2cc3647bcd8c4c0ca638ff1e1c2e9003@sentry.io/2253432'
});
}
addScript("https://browser.sentry-cdn.com/5.12.0/bundle.min.js", {
onload: "initSentry()",
integrity: "sha384-628yQYiY4aWhtsw5Qy17Mmuij8Qwsu5EeUbhpWDRUBkxa41oNaPoXwVJ7+dH7CJb",
crossorigin: "anonymous",
});*/
{{activeMeters[0].viewsLeft}} / {{activeMeters[0].maxViews}} free articles remaining | For Unlimited Access
SUBSCRIBE