(function(funcName, baseObj) { "use strict"; funcName = funcName || "dom_ready"; baseObj = baseObj || window; var readyList = []; var readyFired = false; var readyEventHandlersInstalled = false; function ready() { if (!readyFired) { readyFired = true; for (var i = 0; i < readyList.length; i++) { readyList[i].fn.call(window, readyList[i].ctx); } readyList = []; } } function readyStateChange() { if ( document.readyState === "complete" ) { ready(); } } baseObj[funcName] = function(callback, context) { if (readyFired) { setTimeout(function() {callback(context);}, 1); return; } else { readyList.push({fn: callback, ctx: context}); } if (document.readyState === "complete" || (!document.attachEvent && document.readyState === "interactive")) { setTimeout(ready, 1); } else if (!readyEventHandlersInstalled) { if (document.addEventListener) { document.addEventListener("DOMContentLoaded", ready, false); window.addEventListener("load", ready, false); } else { // must be IE document.attachEvent("onreadystatechange", readyStateChange); window.attachEvent("onload", ready); } readyEventHandlersInstalled = true; } } })("dom_ready", window); function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } function checkAdHeights(){ var ads = document.getElementsByClassName('adbit-display-ad'); if(ads){ for(var i = ads.length - 1; i >= 0; i--){ var ad = ads[i]; var ad_id = ad.getAttribute('data-adspace-id'); if(ad_id != null){ var ad_iframe = document.getElementById('adbit-displayed-ad-' + ad_id); if(ad_iframe != null){ var ad_width = ad_iframe.getAttribute('width'); var ad_height = ad_iframe.getAttribute('orig-height'); if(ad_height == null){ ad_height = ad_iframe.getAttribute('height'); ad_iframe.setAttribute('orig-height', ad_height); } var ad_r = ad_width / ad_height; var ad_position = ad_iframe.getBoundingClientRect(); var new_height = ad_height; if(ad_position != null){ if(ad_position.width < ad_width){ new_height = ad_position.width / ad_r; } } ad_iframe.setAttribute('height', new_height); } } } } } window.dom_ready(function(){ window.setTimeout(function(){ if(typeof window.adbit_ads_loading != 'undefined'){ return false; } window.adbit_ads_loading = true; var ads = document.getElementsByClassName('adbit-display-ad'); var ad_list = new Array(); for(var i = ads.length - 1; i >= 0; i--){ var ad = ads[i]; var ad_id = ad.getAttribute('data-adspace-id'); if(ad_id != null){ ad_list.push(ad_id); } } window.ad_list = ad_list; var viewed_ads = readCookie('adbit-viewed-ads'); if(!viewed_ads || viewed_ads == null){ var viewed_ads = []; } else{ viewed_ads = viewed_ads.split(','); } if(window.ad_list.length > 0){ var postData = {"ad_list": window.ad_list, "ref_host": window.location.origin, "ref_path": window.location.pathname, "viewed_ads": viewed_ads.join(',')}; var url = 'https://adbit.biz/display'; xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == XMLHttpRequest.DONE ) { if(xmlhttp.status == 200){ //success var result = JSON.parse(xmlhttp.response); if(result){ for(var key in result.ads){ var thisAd = result.ads[key]; if(typeof thisAd){ var getElem = document.querySelector('[data-adspace-id="' + key + '"]'); var ifr = document.createElement('iframe'); ifr.width = parseInt(thisAd.width); ifr.height = parseInt(thisAd.height); ifr.setAttribute('frameborder', 0); ifr.setAttribute('allowtransparency', "true"); ifr.scrolling = "no"; ifr.setAttribute('allowfullscreen',"true"); ifr.setAttribute('style', 'position: relative; max-width: 100%;'); ifr.setAttribute('id', 'adbit-displayed-ad-' + key); getElem.appendChild(ifr); var ref_code = ''; if(typeof thisAd.ref_code != 'undefined'){ ref_code = '?r=' + thisAd.ref_code; } var styles, new_html = ''; if(typeof thisAd.image != 'undefined' && thisAd.ad_is_text == 0){ styles = ''; new_html = styles + '
! Advertise Here
'; } if(thisAd.ad_is_text == 1){ styles = ''; new_html = styles + '
!

'+thisAd.ad_title+'

'+thisAd.real_url+'

'+thisAd.ad_text+'

Advertise Here
'; } ifr.contentWindow.document.open(); ifr.contentWindow.document.write(new_html); ifr.contentWindow.document.close(); var ad_viewed = false; for(var vk in viewed_ads){ if(viewed_ads[vk] == thisAd.ad_id){ ad_viewed = true; } } if(!ad_viewed){ //mark ad as viewed in cookie viewed_ads.push(thisAd.ad_id); } } } checkAdHeights(); createCookie('adbit-viewed-ads',viewed_ads.join(','),1); } } else{ //error console.log('Error loading advertisements'); } } } xmlhttp.open("POST", url, true); xmlhttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); xmlhttp.send(JSON.stringify(postData)); } }, 50); }); window.onresize = function(){ checkAdHeights(); };