Untitled
unknown
javascript
2 years ago
4.2 kB
15
Indexable
(function () {
try {
/* main variables */
var debug = 0;
var variation_name = "";
var $;
/* all Pure helper functions */
function waitForElement(selector, trigger, delayInterval, delayTimeout) {
var interval = setInterval(function () {
if (
document &&
document.querySelector(selector) &&
document.querySelectorAll(selector).length > 0
) {
clearInterval(interval);
trigger();
}
}, delayInterval);
setTimeout(function () {
clearInterval(interval);
}, delayTimeout);
}
function live(selector, event, callback, context) {
/****Helper Functions****/
// helper for enabling IE 8 event bindings
function addEvent(el, type, handler) {
if (el.attachEvent) el.attachEvent("on" + type, handler);
else el.addEventListener(type, handler);
}
// matches polyfill
this.Element &&
(function (ElementPrototype) {
ElementPrototype.matches =
ElementPrototype.matches ||
ElementPrototype.matchesSelector ||
ElementPrototype.webkitMatchesSelector ||
ElementPrototype.msMatchesSelector ||
function (selector) {
var node = this,
nodes = (node.parentNode || node.document).querySelectorAll(selector),
i = -1;
while (nodes[++i] && nodes[i] != node);
return !!nodes[i];
};
})(Element.prototype);
// live binding helper using matchesSelector
function live(selector, event, callback, context) {
addEvent(context || document, event, function (e) {
var found,
el = e.target || e.srcElement;
while (el && el.matches && el !== context && !(found = el.matches(selector))) el = el.parentElement;
if (el && found) callback.call(el, e);
});
}
live(selector, event, callback, context);
}
/* Variation Init */
function init() {
// click tracking
live('[data-why-choose-air-doctor]', 'click', function () {
console.log('Clicks on Why Choose Air Doctor CTA');
});
live('[data-replacement-filter-tab]', 'click', function () {
console.log('Clicks on Replacement Filters link');
});
live('[data-replacement-filter-cta]', 'click', function () {
console.log('Clicks on Shop Replacement Filters CTA');
});
live('[data-air-purifire-cta]', 'click', function () {
console.log('Clicks on Shop Air Purifiers Now CTA');
});
live('html body.eg-home-page .egNW_sayGdBy-grid-item:nth-child(1)', 'click', function () {
console.log('Clicks on products --5500');
});
live('html body.eg-home-page .egNW_sayGdBy-grid-item:nth-child(2)', 'click', function () {
console.log('Clicks on products --3000');
});
live('html body.eg-home-page .egNW_sayGdBy-grid-item:nth-child(3)', 'click', function () {
console.log('Clicks on products --1000');
});
live('html body.eg-home-page .egNW_sayGdBy-grid-item:nth-child(4)', 'click', function () {
console.log('Clicks on products --2000');
});
}
/* Initialize variation */
waitForElement('body', init, 50, 15000);
} catch (e) {
if (debug) console.log(e, "error in Test" + variation_name);
}
})();
Editor is loading...