function VMCookies() { this.get = function (key) { if (!key) { return null; } return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null; }; this.set = function (sKey, sValue, vEnd, sPath, sDomain, bSecure) { if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; } var sExpires = ""; if (vEnd) { switch (vEnd.constructor) { case Number: sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd; break; case String: sExpires = "; expires=" + vEnd; break; case Date: sExpires = "; expires=" + vEnd.toUTCString(); break; } } document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : ""); return true; }; } var __vm_cookies = new VMCookies(); function __vm_gi(el) { return document.getElementById(el); } function __vm_cap(hash) { return __vm_gi("vm-capture-" + hash); } function __vm_cset(key, value, time) { if (typeof time === "undefined") time = 60 * 60 * 24; __vm_cookies.set(key, value, time); } function __vm_cget(key) { return __vm_cookies.get(key); } function __vm_adde2b(template) { var el = document.createElement("div"); el.innerHTML += template; document.body.appendChild(el); } function __vm_debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; clearTimeout(timeout); timeout = setTimeout(function() { timeout = null; if (!immediate) func.apply(context, args); }, wait); if (immediate && !timeout) func.apply(context, args); }; } function HQ() { this.captures = { active: [], visible: [] }; this.takeovers = function() { var result = []; for (var i = 0; i < this.captures.active.length; i++) { if (this.captures.active[i] instanceof Takeover) { result.push(this.captures.active[i]); } } return result; }; this.addCapture = function(capture) { this.captures.active.push(capture); capture.hq = this; }; this.showCapture = function(hash) { this.captures.visible.push(hash); }; this.hideCapture = function(hash) { var index = this.captures.visible.indexOf(hash); this.captures.visible.splice(index, 1); }; this.getCapture = function(hash) { var result = null; for (var i = 0; i < this.captures.active.length; i++) { var capture = this.captures.active[i]; if (capture.hash == hash) { result = capture; break; } } return result; }; this.install = function() { for (var i = 0; i < this.captures.active.length; i++) { var capture = this.captures.active[i]; capture.install(); } }; this.start = function() { for (var i = 0; i < this.captures.active.length; i++) { var capture = this.captures.active[i]; capture.start(); } var that = this; document.onkeydown = function(evt) { evt = evt || window.event; var isEscape = false; if ("key" in evt) { isEscape = evt.key === "Escape" || evt.key === "Esc"; } else { isEscape = evt.keyCode === 27; } if (isEscape) { for (var i = 0; i < that.captures.active.length; i++) { var capture = that.captures.active[i]; capture.hide(); } } }; }; } function Impression(hash) { this.el = document.createElement("img"); this.el.style = "position: absolute; top: -1000px; width: 1px; height: 1px;"; this.record = function() { console.log("Impression (" + hash + ")", "Recording..."); this.el.src = window.__vm_HQ_URL + "seen?c=" + hash + "&o=" + window.location.href; document.body.appendChild(this.el); }; } function Conversion(hash) { this.record = function(value) { console.log("Conversion (" + hash + ")", "Recording..."); var head = document.getElementsByTagName("head")[0]; var el = document.createElement("script"); el.id = "vm-conversion-" + hash; el.async = "async"; el.src = window.__vm_HQ_URL + hash + "/lc-add.js" + "?e=" + value + "&o=" + window.location.href + "&t=" + Math.floor(Date.now() / 1000); head.appendChild(el); }; } function Takeover(hash, data) { this.hash = hash; this.hq = null; this.triggerHeight = 50; this.delay = 20; this.release = null; this.template = '
'; this.install = function() { console.log("Takeover (" + hash + ")", "Installing..."); this.impression = new Impression(hash); this.conversion = new Conversion(hash); var template = this.template.replace(/\[HASH\]/g, hash); __vm_adde2b(template); return this; }; this.start = function() { var release = new Date(); release.setSeconds(release.getSeconds() + this.delay); this.release = release; console.log("Takeover (" + hash + ")", "Starting..."); var that = this; __vm_gi("vm-close-button-" + hash).addEventListener( "click", function() { that.onClose(); }, false ); __vm_gi("vm-submit-button-" + hash).addEventListener( "click", function() { that.onSubmit(); }, false ); document.addEventListener( "mousemove", function(e) { that.onMouseMove(e); }, false ); var suggest = __vm_debounce(function() { var elem = __vm_gi("vm-suggest-script-" + hash); if (elem) elem.parentNode.removeChild(elem); var head = document.getElementsByTagName("head")[0]; var el = document.createElement("script"); el.id = "vm-suggest-script-" + hash; head.appendChild(el); el.src = window.__vm_HQ_URL + "verify?c=" + hash + "&e=" + __vm_gi("vm-email-" + hash).value; }, 250); __vm_gi("vm-email-" + hash).addEventListener("input", suggest, false); __vm_gi("vm-heading-" + hash).innerHTML = data.headingText; __vm_gi("vm-main-text-" + hash).innerHTML = data.mainText; __vm_gi("vm-email-" + hash).placeholder = data.emailPlaceholder; __vm_gi("vm-submit-button-" + hash).value = data.buttonText; return this; }; this.show = function() { __vm_cap(hash).classList.remove("hidden"); this.hq.showCapture(hash); this.impression.record(); return this; }; this.hide = function() { __vm_cap(hash).className += " hidden"; this.hq.hideCapture(hash); return this; }; this.isSeen = function() { return ( __vm_cget("vm-capture-" + hash + "-seen") == "true" || __vm_cget("vm-converted") == "true" ); }; this.onTrigger = function() { if (this.release == null || this.release < new Date()) { __vm_cset("vm-capture-" + hash + "-seen", true); this.show(); } }; this.onMouseMove = function(e) { if (window.__vm_HQ.captures.visible.length > 0) return; if (!this.isSeen() && e.clientY < this.triggerHeight) { this.onTrigger(); } }; this.onClose = function() { __vm_cset("vm-capture-" + hash + "-close", true, 60 * 60 * 24); this.hide(); }; this.onSubmit = function() { var element = __vm_gi("vm-email-" + hash); var value = element.value.trim(); if (value == null || value.length == 0) { element.classList.add("vm-error"); element.focus(); return; } var form = __vm_gi("vm-form-" + hash); var valid = form.reportValidity(); if (!valid) return; this.conversion.record(value); console.log(value); }; } function Popup(hash, data) { this.hash = hash; this.template = ' '; this.install = function() { console.log("Popup (" + hash + ")", "Installing..."); this.impression = new Impression(hash); this.conversion = new Conversion(hash); var template = this.template.replace(/\[HASH\]/g, hash); __vm_adde2b(template); return this; }; this.start = function() { console.log("Popup (" + hash + ")", "Starting..."); var that = this; __vm_gi("vm-close-button-" + hash).addEventListener( "click", function() { that.onClose(); }, false ); __vm_gi("vm-submit-button-" + hash).addEventListener( "click", function() { that.onSubmit(); }, false ); __vm_gi("vm-popup-" + hash).addEventListener( "click", function() { that.onClose(); }, false ); __vm_gi("vm-form-" + hash).addEventListener( "click", function(e) { if (!e) e = window.event; e.cancelBubble = true; if (e.stopPropagation) e.stopPropagation(); }, false ); var suggest = __vm_debounce(function() { var elem = __vm_gi("vm-suggest-script-" + hash); if (elem) elem.parentNode.removeChild(elem); var head = document.getElementsByTagName("head")[0]; var el = document.createElement("script"); el.id = "vm-suggest-script-" + hash; head.appendChild(el); el.src = window.__vm_HQ_URL + "verify?c=" + hash + "&e=" + __vm_gi("vm-email-" + hash).value; }, 250); __vm_gi("vm-email-" + hash).addEventListener("input", suggest, false); __vm_gi("vm-image-" + hash).src = data.imagePath; __vm_gi("vm-image-" + hash).alt = data.imageAltText; __vm_gi("vm-heading-" + hash).innerHTML = data.headingText; if (data.mainText.length > 0) { __vm_gi("vm-main-text-" + hash).innerHTML = data.mainText; } else { var el = __vm_gi("vm-main-text-" + hash) el.parentNode.removeChild(el); } __vm_gi("vm-email-" + hash).placeholder = data.emailPlaceholder; __vm_gi("vm-submit-button-" + hash).value = data.buttonText; /// if (window.__vm_HQ.captures.visible.length == 0 && !this.isSeen()) { this.onTrigger(); } /// return this; }; this.show = function() { __vm_cap(hash).classList.remove("hidden"); this.hq.showCapture(hash); this.impression.record(); return this; }; this.hide = function() { __vm_cap(hash).className += " hidden"; this.hq.hideCapture(hash); var takeovers = this.hq.takeovers(); for (var i = 0; i < takeovers.length; i++) { var release = new Date(); release.setSeconds(release.getSeconds() + 5); if (release > takeovers[i].release) { takeovers[i].release = release; } } return this; }; this.isSeen = function() { return ( __vm_cget("vm-capture-" + hash + "-seen") == "true" || __vm_cget("vm-converted") == "true" ); }; this.onTrigger = function() { __vm_cset("vm-capture-" + hash + "-seen", true); this.show(); }; this.onClose = function() { __vm_cset("vm-capture-" + hash + "-close", true, 60 * 60 * 24); this.hide(); }; this.onSubmit = function() { var element = __vm_gi("vm-email-" + hash); var value = element.value.trim(); if (value == null || value.length == 0) { element.classList.add("vm-error"); element.focus(); return; } var form = __vm_gi("vm-form-" + hash); var valid = form.reportValidity(); if (!valid) return; this.conversion.record(value); console.log(value); }; } function r(f){ if (/in/.test(document.readyState)) { setTimeout('r('+f+')',9); } else { f(); } } r(function(){ window.__vm_HQ = new HQ(); window.__vm_HQ_URL = 'https://hq.volomedia.com/'; var ref = window.location.href; console.log('ref: ' + ref); __vm_adde2b("