forked from fightforthefuture/battleforthenet-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.min.js
1 lines (1 loc) · 4.75 KB
/
widget.min.js
1
!function(){var a="https://boldprogressives.github.io/battleforthenet-widget/iframe";"undefined"==typeof _bftn_options&&(_bftn_options={}),"undefined"==typeof _bftn_options.iframe_base_path&&(_bftn_options.iframe_base_path=a),"undefined"==typeof _bftn_options.animation&&(_bftn_options.animation="modal"),"undefined"==typeof _bftn_options.delay&&(_bftn_options.delay=0),"undefined"==typeof _bftn_options.debug&&(_bftn_options.debug=!1),"undefined"==typeof _bftn_options.always_show_widget&&(_bftn_options.always_show_widget=!1);var b={modal:{options:{modalAnimation:"modal"},preload:["envelope.png","envelope-hover.png","field-gradient.png","check-on.png","check-off.png","check-on-big.png","check-off-big.png","close.png"],init:function(a){for(var b in a)this.options[b]=a[b];return this},start:function(){var a="#_bftn_iframe { position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 20000; }";c.injectCSS("_bftn_iframe_css",a);var b=c.createIframe(this.options.modalAnimation);c.bindIframeCommunicator(b,this)},stop:function(){c.destroyIframe()}},banner:{options:{modalAnimation:"banner",position:"topright",width:500,height:100,offsetX:10,offsetY:20,url:"http://noslowlane.com",theme:"light"},preload:[],init:function(a){for(var b in a)this.options[b]=a[b];return this},start:function(){switch(console.log("width: ",this.options.width),this.options.position){case"topright":var a="top: "+this.options.offsetY+"px; right: "+this.options.offsetX+"px; ",b="top";break;case"topleft":var a="top: "+this.options.offsetY+"px; left: "+this.options.offsetX+"px; ",b="top";break;case"bottomright":var a="bottom: "+this.options.offsetY+"px; right: "+this.options.offsetX+"px; ",b="bottom";break;case"bottomleft":var a="bottom: "+this.options.offsetY+"px; left: "+this.options.offsetX+"px; ",b="bottom"}var d=this.options.width+this.options.offsetX,e="\n #_bftn_iframe { position: fixed; "+a+" width: "+this.options.width+"px; height: "+this.options.height+"px; z-index: 20000; } @media (max-width:"+d+"px) { #_bftn_iframe { position: absolute; width: 100%; left: 0px; "+b+": 0px; } }";c.injectCSS("_bftn_iframe_css",e);var f=c.createIframe(this.options.modalAnimation);c.bindIframeCommunicator(f,this)},stop:function(){c.destroyIframe()}}},c={injectCSS:function(a,b){var c=document.createElement("style");c.type="text/css",c.id=a,c.styleSheet?c.styleSheet.cssText=b:c.appendChild(document.createTextNode(b)),document.head.appendChild(c)},createIframe:function(a){var b=document.createElement("iframe");return b.id="_bftn_iframe",b.src=_bftn_options.iframe_base_path+"/"+a+".html",b.frameBorder=0,b.allowTransparency=!0,b.style.display="none",document.body.appendChild(b),b},destroyIframe:function(){var a=document.getElementById("_bftn_iframe");a.parentNode.removeChild(a)},bindIframeCommunicator:function(a,b){var c=function(b,c){c||(c={}),c.requestType=b,c.BFTN_WIDGET_MSG=!0,c.HOST_NAME=g,a.contentWindow.postMessage(c,"*")},d=window.addEventListener?"addEventListener":"attachEvent",e=window[d],f="attachEvent"==d?"onmessage":"message",g=this.getHostname();e(f,function(d){if(d.data&&d.data.BFTN_IFRAME_MSG)switch(delete d.data.BFTN_IFRAME_MSG,d.data.requestType){case"getAnimation":a.style.display="block",c("putAnimation",b.options);break;case"stop":b.stop()}},!1)},setCookie:function(a,b,c){var d=new Date;d.setTime(d.getTime()+24*c*60*60*1e3);var e="expires="+d.toGMTString();document.cookie=a+"="+b+"; "+e},getCookie:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d<c.length;d++){var e=c[d].trim();if(0==e.indexOf(b))return e.substring(b.length,e.length)}return""},getHostname:function(){var a=window.location.host.replace("www.","");return a},log:function(){_bftn_options.debug&&console.log.apply(console,arguments)}},d=function(){var a=window.location.href.indexOf("SHOW_BFTN_WIDGET")>-1;if(!_bftn_options.always_show_widget&&0==a){if(c.getCookie("_BFTN_WIDGET_SHOWN"))return;var d=new Date,e=d.getFullYear()+"/"+(d.getMonth()+1)+"/"+d.getDate();if("2014/9/10"!==e)return}if(c.setCookie("_BFTN_WIDGET_SHOWN","true",365),"undefined"==typeof b[_bftn_options.animation])return c.log("Animation undefined: "+_bftn_options.animation);var f=b[_bftn_options.animation],g=new Array,h=0,j=function(){setTimeout(function(){f.init(_bftn_options).start()},_bftn_options.delay)};if("undefined"!=typeof f.preload&&f.preload.length)for(i=0;i<f.preload.length;i++){var k=f.preload[i];g[i]=new Image,g[i].src=_bftn_options.iframe_base_path+"/images/"+k,g[i].onload=function(){h++,c.log("Preloaded "+h+" images."),h==g.length&&(c.log("DONE PRELOADING IMAGES."),c.log("Animate in "+_bftn_options.delay+" ms"),j())}}else j()},e=document.readyState;"complete"==e||"loaded"==e||"interactive"==e?d():document.addEventListener&&document.addEventListener("DOMContentLoaded",d,!1)}();