-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathangular-dfp.min.js
9 lines (9 loc) · 4.13 KB
/
angular-dfp.min.js
1
2
3
4
5
6
7
8
9
var googletag=googletag||{};googletag.cmd=googletag.cmd||[];
angular.module("ngDfp",[]).constant("ngDfpUrl","//www.googletagservices.com/tag/js/gpt.js").provider("DoubleClick",["ngDfpUrl",function(e){var d={},g={},c={},q=null,l=!0,m={},n=!1,h=!1,p=!0;this._createTag=function(a){if(l){var b=document.createElement("script"),f="https:"===document.location.protocol,c=document.getElementsByTagName("script")[0];b.async=!0;b.type="text/javascript";b.src=(f?"https:":"http:")+e;c.parentNode.insertBefore(b,c);b.onreadystatechange=function(){"complete"==this.readyState&&
a()};b.onload=a}};this._initialize=function(){var a=this;googletag.cmd.push(function(){angular.forEach(d,function(a,f){g[f]=googletag.defineSlot.apply(null,a).addService(googletag.pubads());c[f]&&g[f].defineSizeMapping(c[f]);var e=a.getSlotTargeting();e&&angular.forEach(e,function(a,b){g[f].setTargeting(a.id,a.value)})});angular.forEach(m,function(a,f){googletag.pubads().setTargeting(f,a)});n&&googletag.pubads().collapseEmptyDivs();h&&googletag.pubads().setCentering(!0);p&&googletag.pubads().enableSingleRequest();
googletag.enableServices();googletag.pubads().addEventListener("slotRenderEnded",a._slotRenderEnded)})};this._slotRenderEnded=function(a){var b=d[a.slot.getSlotId().getDomId()].renderCallback;"function"===typeof b&&b(a)};this._refreshInterval=function(){return q};this.setRefreshInterval=function(a){q=a;return this};this.defineSlot=function(){var a=arguments;a.getSize=function(){return this[1]};a.getSlotTargeting=function(){return this[3]?this[3]:!1};a.setRenderCallback=function(a){this.renderCallback=
a};d[arguments[2]]=a;return this};this.defineSizeMapping=function(a){c[a]||(c[a]=[]);this.addSize=function(b,f){c[a].push([b,f]);return this};return this};this.setEnabled=function(a){l=a};this.setPageTargeting=function(a,b){m[a]=b};this.collapseEmptyDivs=function(){n=!0};this.setCentering=function(a){h=a};this.setSingleRequest=function(a){p=a};var k=this;this.$get=["$q","$window","$interval",function(a,b,f){var c=a.defer();k._createTag(function(){try{k._initialize(),null!==k._refreshInterval()&&f(function(){googletag.cmd.push(function(){b.googletag.pubads().refresh()})},
k._refreshInterval()),c.resolve()}catch(a){c.reject(a)}});return{getAdSize:function(a){return c.promise.then(function(){if(angular.isUndefined(d[a]))throw"Slot "+a+" has not been defined. Define it using DoubleClickProvider.defineSlot().";return d[a][1]})},getSlot:function(a){return c.promise.then(function(){if(angular.isUndefined(d[a]))throw"Slot "+a+" has not been defined. Define it using DoubleClickProvider.defineSlot().";return d[a]})},runAd:function(a){googletag.cmd.push(function(){b.googletag.display(a)})},
refreshAds:function(){var a=[];angular.forEach(arguments,function(b){a.push(g[b])});googletag.cmd.push(function(){b.googletag.pubads().refresh(a)})}}}]}]).directive("ngDfpAdContainer",function(){return{restrict:"A",controller:["$element",function(e){this.$$setVisible=function(d,g){d?"visibility"===g?e.css("visibility","visible"):e.show():"visibility"===g?e.css("visibility","hidden"):e.hide()}}]}}).directive("ngDfpAd",["$timeout","$parse","$interval","DoubleClick",function(e,d,g,c){return{restrict:"A",
template:'<div id="{{adId}}"></div>',require:"?^ngDfpAdContainer",scope:{adId:"@ngDfpAd",refresh:"@ngDfpAdRefresh",interval:"@ngDfpAdRefreshInterval",timeout:"@ngDfpAdRefreshTimeout"},replace:!0,link:function(d,l,m,n){d.$watch("adId",function(h){l.html("");var p=null,k=null;c.getSlot(h).then(function(a){var b=a.getSize();l.css("width",b[0]).css("height",b[1]);e(function(){c.runAd(h)});n&&a.setRenderCallback(function(){angular.isDefined(m.ngDfpAdHideWhenEmpty)&&(0===l.find("iframe:not([id*=hidden])").map(function(){return this.contentWindow.document}).find("body").children().length?
n.$$setVisible(!1,m.ngDfpAdHideWhenEmpty):n.$$setVisible(!0,m.ngDfpAdHideWhenEmpty))});d.$watch("refresh",function(a){angular.isUndefined(a)||c.refreshAds(h)});d.$watch("interval",function(a){angular.isUndefined(a)||(p=g(function(){c.refreshAds(h)},d.interval))});d.$watch("timeout",function(a){angular.isUndefined(a)||(k=e(function(){c.refreshAds(h)},d.timeout))});d.$on("$destroy",function(){g.cancel(p);e.cancel(k);k=p=null})})})}}}]);