-
Notifications
You must be signed in to change notification settings - Fork 0
/
mads.min.js
1 lines (1 loc) · 1.33 KB
/
mads.min.js
1
var TG=TG||{};TG.mads=function(a,b){"use strict";function g(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var c="mads-js-"+Date.now(),d=0,e=0,f={max_tries:10,timeout:500};return{get options(){return f},set options(a){if("object"!=typeof a)throw"params must be an object";g(f,a)},get loaded(){return a.getElementById(c)&&d?!0:!1},reset:function(){this.loaded||(d=0,e=0)},load:function(g){var h=function(){try{if(d=b.MADSAdrequest!==void 0?1:0,!d)throw"MADS not yet loaded";g()}catch(a){if(!(f.max_tries>e))throw"MADS couldn't be downloaded";setTimeout(h,f.timeout),e++}};d>0?g():0===d?(d=-1,function(b,c){var d,e=a.getElementsByTagName(b)[0];a.getElementById(c)||(d=a.createElement(b),d.id=c,d.src="http://eu2.madsone.com/js/tags.js",e.parentNode.insertBefore(d,e))}("script",c),h()):h()},showAd:function(c,d){var e=a.getElementById(c);if(!e)throw"Couldn't find element with id "+c;if(e.children.length)throw"Already loaded "+c;d="object"==typeof d?d:{};var h={pid:"6252122059",element_id:c,async:!0,ad_type:"live"};g(h,f),g(h,d),this.load(function(){b.MADSAdrequest.adrequest(h)})},showAllAds:function(b){var c=Array.prototype.slice.call(a.getElementsByClassName(b),0),d=this;c.length&&d.load(function(){c.forEach(function(a){var b=a.getAttribute("id");if(b&&!a.children.length){var c=a.dataset;d.showAd.call(d,b,c)}})})}}}(document,window);