/** * @license ev-em.js v3.2.11 * (c) 2015-2017 Evolok, Inc. http://www.evolok.com/ * * License: MIT */ window.EV=window.EV||{},function(t){"use strict";function o(){g&&n("ev_sid")!=g&&(s("ev_sid",g,10),c("ev_sid",g,0,"localStorage"),m=m+"&ev_sid="+g),f&&n("ev_did")!=f&&(s("ev_did",f,10),c("ev_did",f,0,"localStorage"),m=m+"&ev_did="+f)}function n(e){var t,o="; "+document.cookie,n=o.split("; "+e+"=");return 2==n.length?(t=n.pop().split(";").shift(),t=t.replace(/["'()]/g,"")):""}function s(e,t,o){if(!v.sidCookieDomain)throw new Error("Please specify sidCookieDomain in the config!",!0);var n=new Date;o=1460,n.setDate(n.getDate()+o),document.cookie=e+"="+escape(t)+(null===o?"":";expires="+n.toUTCString())+";path=/; domain="+v.sidCookieDomain,console.log(e+"="+escape(t)+(null===o?"":";expires="+n.toUTCString())+";path=/; domain="+v.sidCookieDomain)}function i(e){if(""!==n(e)&&"undefined"!==n(e))return n(e)}function r(e){if(""!==d(e,"localStorage")&&"undefined"!==d(e,"localStorage"))return d(e,"localStorage")}function a(){if(!v)throw"Evolok Metering library is not initialised!"}function d(e,t){var o=document.cookie.indexOf(e+"=");if("localStorage"==t){if("undefined"==typeof localStorage)return document.cookie.length>0&&-1!==o?getCookieSubstring(o,e):"";try{return localStorage.getItem(e)}catch(e){return console.warn("Could not retrieve the cookie in local storage - maybe the browser's running on an environment with restricted access to localStorage?"),"undefined"}}if("sessionStorage"==t){if("undefined"==typeof sessionStorage)return o=document.cookie.indexOf(e+"="),document.cookie.length>0&&-1!==o?getCookieSubstring(o,e):"";console.log(sessionStorage.getItem(e));try{return sessionStorage.getItem(e)}catch(e){return console.warn("Could not retrieve the cookie in session storage - maybe the browser's running on an environment with restricted access to sessionStorage?"),"undefined"}}}function c(e,t,o,n){var s=new Date;if("localStorage"==n)if(s.setDate(s.getDate()+o),"undefined"!=typeof localStorage)try{localStorage.setItem(e,t)}catch(e){console.warn("Could not store the cookie in local storage - maybe the browser's running on an environment with restricted access to localStorage?")}else document.cookie=e+"="+escape(t)+(null===o?"":";expires="+s.toUTCString());if("sessionStorage"==n)if(s.setDate(s.getDate()+o),"undefined"!=typeof sessionStorage)try{sessionStorage.setItem(e,t)}catch(e){console.warn("Could not store the cookie in session storage - maybe the browser's running on an environment with restricted access to sessionStorage?")}else document.cookie=e+"="+escape(t)+(null===o?"":";expires="+s.toUTCString())}function l(e){var t="";e=JSON.parse(e);for(var o in e)""!==t&&(t+="&"),t+=o+"="+encodeURIComponent(e[o]);return t}function u(e,t){a();var o=v.url;if(!o)throw new Error("Evolok Metering host url is not configured!");return"/"===o.charAt(o.length-1)&&"/"===e.charAt(0)?o+=e.substring(1,e.length):o+=e,o=t?o+"?"+t:o}var v,g,f,m,p;t.Em={init:function(e){if(!e.url)throw"Configuration must specify the url property!";v=e},authorize:function(e,o,a){t.Em.assert(e,"Parameters should not be empty!"),t.Em.assert(o,"Success callback should not be empty!"),t.Em.assert(a,"Error callback should not be empty!");var _=l(e),h="",w="",S="";m=_,i("ev_sid")?(w="&ev_sid="+n("ev_sid"),c("ev_sid",n("ev_sid"),0,"localStorage")):r("ev_sid")&&(v.meterHD?!0===v.meterHD&&(s("ev_sid",d("ev_sid","localStorage"),10),w="&ev_sid="+d("ev_sid","localStorage"),p=v.meterHD):s("ev_sid",d("ev_sid","localStorage"),10)),i("ev_did")?(S="&ev_did="+n("ev_did"),c("ev_did",n("ev_did"),0,"localStorage")):r("ev_did")&&(v.meterHD?!0===v.meterHD&&(s("ev_did",d("ev_did","localStorage"),10),S="&ev_did="+d("ev_did","localStorage")):s("ev_did",d("ev_did","localStorage"),10)),""!==n("ev_ss")&&(h+="&ev_ss="+n("ev_ss")),h=h==="&ev_ss="+n("ev_ss")?"&ev_ss="+n("ev_ss"):"&ev_ss=",w=w==="&ev_sid="+n("ev_sid")?"&ev_sid="+n("ev_sid"):"&ev_sid=",S=S==="&ev_did="+n("ev_did")?"&ev_did="+n("ev_did"):"&ev_did=",_=_+h+w+S;var y=u("/authorize/json",_),E=new XMLHttpRequest;E.open("GET",y,!0),E.withCredentials=!0,E.onload=function(){if(E.status>=200&&E.status<400){var e=JSON.parse(E.responseText);!function(e){function t(e){var t;"function"==typeof CustomEvent?t=new CustomEvent("ev.ad.authorize",{detail:e}):(t=document.createEvent("CustomEvent"),t.initCustomEvent("ev.ad.authorize",!1,!1,e)),window.dispatchEvent(t)}t(e),window.addEventListener("ev.widgets.paywall.load",function(){t(e)}),window.addEventListener("ev.widgets.notifier.load",function(){t(e)})}(e),e.sessionKeys&&(e.sessionKeys.ev_sid&&(g=e.sessionKeys.ev_sid),e.sessionKeys.ev_did&&(f=e.sessionKeys.ev_did)),"ALLOW_ACCESS"!=e.result&&t.Em.hideMeteredContent(),o(e)}else a&&a(E.status,E.responseText)},E.onerror=function(e){e?a(e):a(0,"unknown connection error")},E.send()},pretty_print:function(e){var o=/^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/gm,n=JSON.stringify(e,null,3).replace(/&/g,"&").replace(/\\"/g,""").replace(//g,">").replace(o,t.Em.replacer);return n="
"+n+""},replacer:function(e,t,o,n,s){var i=t||"";return o&&(i=i+""+o.replace(/[": ]/g,"")+": "),n&&(i=i+('"'==n[0]?"":"")+n+""),i+(s||"")},segment:function(o,n,s){t.Em.assert(o,"Parameters should not be empty!"),t.Em.assert(n,"Success callback should not be empty!"),t.Em.assert(s,"Error callback should not be empty!");var i=l(o),r=u("/segment",i),a=new XMLHttpRequest;a.open("GET",r,!0),a.withCredentials=!0,a.onload=function(){if(a.status>=200&&a.status<400){var e=JSON.parse(a.responseText);n(e)}else s&&s(a.status,a.responseText)},a.onerror=function(){e?s(e):s(0,"unknown connection error")},a.send()},assert:function(e,t){if(!e){if(t=t||"Assertion failed","undefined"!=typeof Error)throw new Error(t);throw t}},getUrl:function(){return v.url},showMeteredContent:function(){var e=document.getElementsByClassName("ev-meter-content");[].forEach.call(e,function(e){e.style.display="block"})},hideMeteredContent:function(){var e=document.getElementsByClassName("ev-meter-content");[].forEach.call(e,function(e){e.style.display="none"})}},setTimeout(function(){o()},4e3)}(window.EV);