egn-methods
Version:
Endless Gain custom methods
1 lines • 16.6 kB
JavaScript
module.exports={debugger:function(e){var i={cookie:function(e,i,t){if(void 0!==i){if((t="object"!=typeof t?{path:"/"}:t).path||(t.path="/"),null===i?t.expires=-1:i="object"==typeof i?JSON.stringify(i):String(i),"number"==typeof t.expires){var o=t.expires,n=t.expires=new Date,s=864e5*o;n.setTime(n.getTime()+s)}return document.cookie=[encodeURIComponent(e),"=",i,t.expires?"; expires="+t.expires.toUTCString():"",t.path?"; path="+t.path:"",t.domain?"; domain="+t.domain:"",t.secure?"; secure":""].join("")}for(var r=document.cookie.split("; "),a=0,l=r.length;a<l;a++){var d=r[a].split("=");if(d.shift()===e)return d.join("=")}return null},removeCookie:function(e,t){return null!==i.cookie(e)&&(i.cookie(e,null,t),!0)}};this.active=i.cookie("EGn_debugger")||/EGn_debugger|EGn_Zoltar/.test(location.search),this.jQueryFound=!1,this.audience=!1,this.args="arguments",this.options=e&&e.options,this.set=function(e){if(/EGn_debugger=off|EGn_Zoltar=off/.test(location.search))return i.removeCookie("EGn_debugger",{domain:location.host}),void(this.active=!1);if(void 0!==e){this.args=e;for(var t in e)this[t]=e[t]}if(this.meta=this.options&&this.options.meta,this.experienceID=this.meta&&this.meta.experienceId,this.variationID=this.meta&&this.meta.variationMasterId,this.isControl=this.meta&&this.meta.variationIsControl,!window.jQuery)return setTimeout(this.set.bind(this),100);if(/EGn_debugger|EGn_Zoltar/.test(location.search)&&i.cookie("EGn_debugger","true",{expires:365,domain:location.host}),i.cookie("EGn_debugger")){(i.cookie("EGn_"+this.experienceID)||window.sessionStorage["EGn_"+this.experienceID])&&(i.removeCookie("EGn_"+this.experienceID),window.sessionStorage["EGn_"+this.experienceID]=!0);for(var o in this.args)this.log("EGn | "+o+" : ",this.args[o]);this.IP||(this.IP="not found",jQuery.ajax({url:"https://api.endlessgain.com/getIP"}).then(function(e){this.IP=e.replace(/"/g,""),jQuery(".EGn_debugger .IP .value").text(this.IP)}.bind(this)));var n='<div class="info">';this.name?(n+="<label>"+this.name+"</label>",n+='<div class="experience_info collapsed">',n+='<div class="experience_inner_info">',n+='<div class="line">Experience ID: <span class="value">'+this.experienceID+"</span></div>"):(n+="<label>Experience ID: "+this.experienceID+"</label>",n+='<div class="experience_info collapsed">',n+='<div class="experience_inner_info">'),n+='<div class="line">Variation ID: <span class="value">'+this.variationID+"</span></div>",this.version&&(n+='<div class="line">Version: <span class="value">'+this.version+"</span></div>"),n+='<div class="line">isControl: <span class="value">'+this.isControl+"</span></div>",n+='<div class="line IP">IP: <span class="value">'+this.IP+"</span></div>",n+='<div class="line"><div class="audience">Audience: <span class="value">'+this.audience+"</span></div></div>",n+="</div>";var s,r,a="";if(window.sessionStorage&&window.sessionStorage.EGn_debugger){var l=JSON.parse(window.sessionStorage.EGn_debugger);if(l.goals&&l.goals[this.experienceID]){a+='<div class="goals-heading">Goals</div><table class="goals">';for(o in l.goals[this.experienceID]){a+='<tr class="'+o.replace(/\:/g,"-")+'"><td>'+o+'</td><td class="count">'+l.goals[this.experienceID][o]+"</td></div>"}a+="</table>"}if(l.pos){s=r=' style="';for(var d in l.pos.main)s+=d+":"+l.pos.main[d]+";";for(d in l.pos.toggle)r+=d+":"+l.pos.toggle[d]+";";s+='"',r+='"'}}var g=window.sessionStorage["EGn_"+this.experienceID]?"Variation":"Control";n+=a,n+='<button class="control-toggle '+this.experienceID+'">See '+g+"</div>",n+="</div>",n+="</div>",html='<div class="EGn_debugger collapsed"'+s+">",html+='<div class="toggle"'+r+'><img class="debugger-open" src="https://dd6zx4ibq538k.cloudfront.net/static/images/4613/bc1f4eb2a825ac6660a84d6a4098a041_46_48.png">',html+='<img class="debugger-close" src="https://dd6zx4ibq538k.cloudfront.net/static/images/4613/a3379ed70b6afcb100d173b5b4c36283_34_34.png"></div>',html+='<div class="move-overlay"><img src="https://dd6zx4ibq538k.cloudfront.net/static/images/4613/832d542c485e1e84543a4536077b84f9_200_200.png"></div><div class="outer"><span class="helper"><p class="help-toggle"></p><div>To disable the moduletype in<br /><b><i>?EGn_Zoltar=off</i></b> in the URL field<br><label>logger: <input type="checkbox"></label></div></span></div></div>';var c=jQuery(n),p=!1;jQuery(".EGn_debugger").length||(p=!0,jQuery("html").append(html),c.find("label").addClass("move")),this.$outerContainer=jQuery(".EGn_debugger"),this.$outerContainer.find(" > .outer").append(c),this.$container=c.find(".experience_inner_info"),this.setHeight(),this.isSet=!0,p&&function(){function e(e){o.removeAttr("style");var i=/touch/.test(e.type)?e.originalEvent.touches[0].clientX:e.clientX,t=/touch/.test(e.type)?e.originalEvent.touches[0].clientY:e.clientY;n={},s={},i>.9*window.innerWidth?(s={left:"auto",right:"5px"},o.find(".toggle").css(s),hori="right",i=window.innerWidth-(i+20),n.left="auto"):(s={right:"auto",left:"5px"},o.find(".toggle").css(s),hori="left"),t>.85*window.innerHeight?(verti="bottom",t=window.innerHeight-t,n.top="auto"):verti="top",n[hori]=i+"px",n[verti]=t+"px",o.css(n)}var t=jQuery(document);jQuery(window).on("load",this.setHeight.bind(this)),t.ready(this.setHeight.bind(this)),t.on("click",".EGn_debugger > .toggle",function(){jQuery(this).parent().toggleClass("collapsed")}),t.on("click",".EGn_debugger > .outer > .info > label",function(){jQuery(this).toggleClass("active"),jQuery(this).siblings(".experience_info").toggleClass("collapsed")}),t.on("click",".EGn_debugger .control-toggle",function(){var e=jQuery(this),t=e.attr("class").replace(/control-toggle\s/g,"");/control/i.test(e.text())?(i.cookie("EGn_"+t,!0),window.open(document.URL,"_blank")):(i.removeCookie("EGn_"+t),window.open(document.URL,"_blank"))});var o=jQuery(".EGn_debugger"),n={},s={},r=!1,a=!1;o.find(".move").on("mousedown touchstart",function(i){a=!1,setTimeout(function(){a||(r=!0,o.find(".move-overlay").show(),jQuery(window).on("mousemove touchmove",e))},250)}),jQuery(window).on("mouseup touchend",function(i){var t;a=!0,r&&(r=!1,o.find(".move-overlay").hide(),jQuery(window).unbind("mousemove touchmove",e),window.sessionStorage&&window.sessionStorage.EGn_debugger?((t=JSON.parse(window.sessionStorage.EGn_debugger)).pos={main:n,toggle:s},window.sessionStorage.EGn_debugger=JSON.stringify(t)):(t={pos:{main:n,toggle:s}},window.sessionStorage.EGn_debugger=JSON.stringify(t)))}),window.sessionStorage&&window.sessionStorage.EGn_log&&jQuery(".EGn_debugger .helper label input").prop("checked",!0),jQuery(document).on("click",".EGn_debugger .helper label",function(){jQuery(this).find("input").is(":checked")?sessionStorage.EGn_log=!0:delete sessionStorage.EGn_log});var l=document.createElement("style");l.type="text/css",l.id="EGn_styles",l.innerHTML=".EGn_debugger {min-width: 220px;font-family: Gibson;position: fixed;z-index: 999999999;top: 45px;left: 5px;background: #fff;color: #000;font-size: 13px;border: 1px solid #E0E8EC;border-top: none;}.EGn_debugger .helper {cursor: pointer;position: absolute;right: 5px;top: 5px;font-size: 12px;width: 12px;height: 17px;transition: all 0.5s;}.EGn_debugger .helper > .help-toggle {width: 12px;cursor: pointer;position: absolute;right: 0;top: 0;font-size: 12px;height: 16px;background: url(https://d1yffp2utogicl.cloudfront.net/QuestM.png) center no-repeat;background-size: contain;}.EGn_debugger .helper > div {transition: all 0.5s;opacity: 0;visibility: hidden;position: relative;width: 210px;background: #f1f9ee;padding: 10px;border-radius: 5px;top: 18px;right: 0px;border: 1px solid #cccccc;}.EGn_debugger .helper > div > label {position: relative;}.EGn_debugger .helper > div > label > input {position: relative;top: 3px;}.EGn_debugger .helper:hover {width: 210px;height: 58px;}.EGn_debugger .helper:hover > div {visibility: visible;opacity: 1;}.EGn_debugger .outer {max-height: calc(100vh - 50px);overflow-y: auto;}.EGn_debugger .outer::-webkit-scrollbar {width: 0px;}.EGn_debugger .move {user-select: none;cursor: move;}.EGn_debugger .move-overlay {display: none;position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: #fff;opacity: 0.4;}.EGn_debugger .move-overlay img {width: 50px;position: absolute;top: calc(50% - 25px);left: calc(50% - 25px);}.EGn_debugger .outer .info:first-of-type label {margin-top: 0;}.EGn_debugger .info {overflow: hidden;}.EGn_debugger .info label {margin-top: 5px;cursor: pointer;font-size: 15px;font-weight: bold;display: block;border-left: none;border-right: none;background-color: #F9F9F9;border: 1px solid #E0E8EC;padding: 10px;}.EGn_debugger .info label.active {border-top: 2px solid #00FF00;}.EGn_debugger .info .experience_info {transition: height 0.5s;overflow: hidden;}.EGn_debugger .info .experience_info .line {font-weight: 400;padding: 12px 0 5px;width: 90%;margin: 0 auto;border-bottom: 1px solid #E8EDF0;}.EGn_debugger .info .experience_info .line .value {font-weight: 300;}.EGn_debugger .info .experience_info.collapsed {height: 0 !important;}.EGn_debugger .toggle {cursor: pointer;position: absolute;left: 5px;top: -35px;font-size: 25px;width: 34px;height: 34px;background: #333333;border-radius: 100%;overflow: hidden;}.EGn_debugger .toggle .debugger-open {visibility: hidden;opacity: 0;width: 24px;position: absolute;left: 5px;top: 5px;}.EGn_debugger .toggle .debugger-close {visibility: visible;opacity: 1;width: 22px;position: absolute;left: 6px;top: 6px;}.EGn_debugger .goals {border-spacing: 2px;border-collapse: separate;width: auto;min-width: 90%;margin: 0 auto;}.EGn_debugger .goals td {border: 1px solid #878f93;padding: 3px 5px;min-width: 15px;text-align: center;}.EGn_debugger .goals-heading {text-align: center;font-size: 15px;}.EGn_debugger .control-toggle {color: #000;background: #fff;border: 2px solid #00FF00;padding: 5px;min-width: 100px;margin: 5px auto;display: block;cursor: pointer;width: calc(90% - 4px);height: 40px;font-size: 15px;font-weight: 400;font-family: Gibson;}.EGn_debugger .control-toggle:hover {background: #00FF00;color: #fff;}.EGn_debugger.collapsed {height: 0px;border-bottom: none;}.EGn_debugger.collapsed .helper {display: none;}.EGn_debugger.collapsed .outer {visibility: hidden;}.EGn_debugger.collapsed .experience_info {visibility: hidden;}.EGn_debugger.collapsed .toggle img {transition: all 0.3s;}.EGn_debugger.collapsed .toggle .debugger-open {visibility: visible;opacity: 1;}.EGn_debugger.collapsed .toggle .debugger-close {visibility: hidden;opacity: 0;}",document.head.appendChild(l)}.bind(this)()}},this.push=function(e,i){if(this.active){if(!this.isSet)return setTimeout(function(){this.push(e)}.bind(this),330);var t="";for(var o in e)t+='<div class="line'+(i=" "+i||"")+'">'+o+': <span class="value">'+e[o]+"</span></div>",this.log("EGn | "+o+" : "+e[o]);this.$container.append(t),this.setHeight()}},this.show=function(e){if(this.active){if(!this.isSet)return setTimeout(function(){this.show(e)}.bind(this),330);for(var i in e){var t=this.$container.find("."+i);if(t.length)t.text(i+": "+e[i]);else{var o={};o[i]=e[i],this.push(o,i)}this.log("EGn | "+i+" : "+e[i])}}},this.emitCustomGoal=function(e){if(this.active){if(!this.isSet)return setTimeout(function(){this.emitCustomGoal(e)}.bind(this),330);this.log("emitCustomGoal()");var i,t=e.replace(/\:/g,"-"),o=this.$outerContainer.find("table.goals"),n=o.find("."+t);if(window.sessionStorage&&window.sessionStorage.EGn_debugger?((i=JSON.parse(window.sessionStorage.EGn_debugger)).goals?i.goals[this.experienceID]?i.goals[this.experienceID][e]?i.goals[this.experienceID][e]=Number(i.goals[this.experienceID][e])+1:i.goals[this.experienceID][e]=1:(i.goals[this.experienceID]={},i.goals[this.experienceID][e]=1):(i.goals={},i.goals[this.experienceID]={},i.goals[this.experienceID][e]=1),window.sessionStorage.EGn_debugger=JSON.stringify(i)):((i={goals:{}}).goals[this.experienceID]={},i.goals[this.experienceID][e]=1,window.sessionStorage.EGn_debugger=JSON.stringify(i)),o.length)if(n.length){var s=Number(n.find("td.count").text())+1;n.find("td.count").text(s)}else o.append('<tr class="'+t+'"><td>'+e+'</td><td class="count">1</td></div>');else{var r='<div class="goals-heading">Goals</div><table class="goals">';r+='<tr class="'+t+'"><td>'+e+'</td><td class="count">1</td></div>',r+="</table>",jQuery(r).insertAfter(this.$container)}this.setHeight()}},this.setHeight=function(){var e=this.$container.parent(),i=this.$container,t=e.find(".goals"),o=i.height()+50+(t.length?t.height()+15:0);e.css("height",o),setTimeout(function(){var o=i.height()+50+(t.length?t.height()+15:0);e.css("height",o)}.bind(this),1e3)},this.cb=function(){if(this.audience=!0,this.active){if(!this.isSet)return setTimeout(function(){this.cb()}.bind(this),330);console.log("EGn | Activating Experience: "+(this.name||this.experienceID)+". Variation ID: "+this.variationID),this.$container.find(".audience > span").text("true")}},this.log=function(){if(sessionStorage.EGn_log&&this.active){var e=["EGn | "];for(var i in arguments)e.push(arguments[i]);return console.log.apply(null,e)}},this.active&&this.set(e)},cookie:function(e,t,i){if(void 0!==t){if((i="object"!=typeof i?{path:"/"}:i).path||(i.path="/"),null===t?i.expires=-1:t="object"==typeof t?JSON.stringify(t):String(t),"number"==typeof i.expires){var n=i.expires,o=i.expires=new Date,r=864e5*n;o.setTime(o.getTime()+r)}return document.cookie=[encodeURIComponent(e),"=",t,i.expires?"; expires="+i.expires.toUTCString():"",i.path?"; path="+i.path:"",i.domain?"; domain="+i.domain:"",i.secure?"; secure":""].join("")}for(var p=document.cookie.split("; "),s=0,a=p.length;s<a;s++){var u=p[s].split("=");if(u.shift()===e){return u.join("=")}}return null},removeCookie:function(n,o){return null!==EGn.cookie(n)&&(EGn.cookie(n,null,o),!0)},URLparams:function(i,n){for(var o=[],t=void 0,e=window.location.href.slice(window.location.href.indexOf("?")+1).split(/&|#/),l=0;l<e.length;l++)t=e[l].split("="),o.push(t[0]),o[t[0]]=t[1];return o},remoteDev:function (options){function run(data){var qubit_options=options&&options.options;if(!qubit_options)return console.error("Can not run remoteDev. Qubit options undefined");window.options=qubit_options,eval(data),EGn_changeListener(options)}localStorage.EGn_DevBus?run(localStorage.EGn_DevBus):jQuery.post("//api.endlessgain.com/getJSON",{client:"scripts",fileName:"EGn_Dev_BUS.min",type:"js"}).then(function(n){run(n),localStorage.EGn_DevBus=n})},modal:function(e){var n=e.jQuery||window.jQuery||window.$;if(!window.jQuery.fn.jquery)return console.error("EGn modal method requires jQuery");var o=n("head");o.find(".egn-modalCSS").length||o.append('<style type="text/css" class="egn-modalCSS">body .egn-modal {position: fixed;top: 0;left: 0;width: 100%;height: 100%;z-index: 999999999;background: rgba(0,0,0,0.7);overflow-y: auto;margin-right: 15px;visibility: hidden;opacity: 0;transition: opacity .6s,visibility .6s;text-align: center;}body .egn-modal.egn-modal-active {visibility: visible;opacity: 1;}body .egn-modal:before {content: "";display: inline-block;height: 100%;vertical-align: middle;}body .egn-modal .egn-modalInner {position: relative;display: inline-block;vertical-align: middle;text-align: left;width: 485px;max-width: calc(100% - 50px);background: #fff;margin: 20px 0;}body .egn-modal .egn-modalInner * {box-sizing: border-box;}body .egn-modal .egn-modalClose {position: absolute;height: 45px;width: 45px;top: 0;right: 0;-webkit-transform: translate(50%,-50%);-ms-transform: translate(50%,-50%);transform: translate(50%,-50%);border: 1px solid #fff;cursor: pointer;z-index: 55;}body .egn-modal .egn-modalClose > img {height: 55%;width: 55%;position: absolute;top: 50%;left: 50%;-webkit-transform: translate(-50%,-50%);-ms-transform: translate(-50%,-50%);transform: translate(-50%,-50%);}@media screen and (max-width: 738px) {body .egn-modal .egn-modalInner {max-width: calc(100% - 40px);}body .egn-modal .egn-modalClose {height: 30px;width: 30px;}}</style>');var i=e.className||"",t=e.content||"",a=n(('\n<div class="'+(i?i+" ":"")+'egn-modal">\n<div class="egn-modalInner">\n<div class="egn-modalClose"><img src="//dd6zx4ibq538k.cloudfront.net/static/images/4613/88999712ce579e241307ddd91e455425_114_109.png" /></div>\n<div class="egn-modalContent">'+t+"</div>\n</div>\n</div>").replace(/\s\s+/g," ").trim());n("body").append(a);var d=function(){a.removeClass("egn-modal-active"),"function"==typeof e.onClose&&e.onClose.bind(a)()};return a.find(".egn-modalClose").click(d),{$modal:a,$content:a.find(".egn-modalContent"),open:function(){a.addClass("egn-modal-active"),"function"==typeof e.onOpen&&e.onOpen.bind(a)()},close:d}}};