forked from kohatang/ngDfp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-dfp.min.js
More file actions
9 lines (9 loc) · 3.98 KB
/
angular-dfp.min.js
File metadata and controls
9 lines (9 loc) · 3.98 KB
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(g){var b={},f={},c={},p=null,l=!0,m={},n=!1,h=!0;this._createTag=function(a){if(l){var d=document.createElement("script"),e="https:"===document.location.protocol,c=document.getElementsByTagName("script")[0];d.async=!0;d.type="text/javascript";d.src=(e?"https:":"http:")+g;c.parentNode.insertBefore(d,c);d.onreadystatechange=function(){"complete"==this.readyState&&a()};
d.onload=a}};this._initialize=function(){var a=this;googletag.cmd.push(function(){angular.forEach(b,function(a,e){f[e]=googletag.defineSlot.apply(null,a).addService(googletag.pubads());c[e]&&f[e].defineSizeMapping(c[e]);var b=a.getSlotTargeting();b&&angular.forEach(b,function(a,d){f[e].setTargeting(a.id,a.value)})});angular.forEach(m,function(a,e){googletag.pubads().setTargeting(e,a)});n&&googletag.pubads().collapseEmptyDivs();h&&googletag.pubads().enableSingleRequest();googletag.enableServices();
googletag.pubads().addEventListener("slotRenderEnded",a._slotRenderEnded)})};this._slotRenderEnded=function(a){a=b[a.slot.getSlotId().getDomId()].renderCallback;"function"===typeof a&&a()};this._refreshInterval=function(){return p};this.setRefreshInterval=function(a){p=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};b[arguments[2]]=a;return this};
this.defineSizeMapping=function(a){c[a]||(c[a]=[]);this.addSize=function(d,e){c[a].push([d,e]);return this};return this};this.setEnabled=function(a){l=a};this.setPageTargeting=function(a,d){m[a]=d};this.collapseEmptyDivs=function(){n=!0};this.setSingleRequest=function(a){h=a};var k=this;this.$get=["$q","$window","$interval",function(a,d,e){var c=a.defer();k._createTag(function(){k._initialize();null!==k._refreshInterval()&&e(function(){googletag.cmd.push(function(){d.googletag.pubads().refresh()})},
k._refreshInterval());c.resolve()});return{getAdSize:function(a){return c.promise.then(function(){if(angular.isUndefined(b[a]))throw"Slot "+a+" has not been defined. Define it using DoubleClickProvider.defineSlot().";return b[a][1]})},getSlot:function(a){return c.promise.then(function(){if(angular.isUndefined(b[a]))throw"Slot "+a+" has not been defined. Define it using DoubleClickProvider.defineSlot().";return b[a]})},runAd:function(a){googletag.cmd.push(function(){d.googletag.display(a)})},refreshAds:function(){var a=
[];angular.forEach(arguments,function(e){a.push(f[e])});googletag.cmd.push(function(){d.googletag.pubads().refresh(a)})}}}]}]).directive("ngDfpAdContainer",function(){return{restrict:"A",controller:["$element",function(g){this.$$setVisible=function(b,f){b?"visibility"===f?g.css("visibility","visible"):g.show():"visibility"===f?g.css("visibility","hidden"):g.hide()}}]}}).directive("ngDfpAd",["$timeout","$parse","$interval","DoubleClick",function(g,b,f,c){return{restrict:"A",template:'<div id="{{adId}}"></div>',
require:"?^ngDfpAdContainer",scope:{adId:"@ngDfpAd",refresh:"@ngDfpAdRefresh",interval:"@ngDfpAdRefreshInterval",timeout:"@ngDfpAdRefreshTimeout"},replace:!0,link:function(b,l,m,n){b.$watch("adId",function(h){l.html("");var k=null;c.getSlot(h).then(function(a){var d=a.getSize();l.css("width",d[0]).css("height",d[1]);g(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))});b.$watch("refresh",function(a){angular.isUndefined(a)||c.refreshAds(h)});b.$watch("interval",function(a){angular.isUndefined(a)||(f.cancel(k),k=f(function(){c.refreshAds(h)},b.interval))});b.$watch("timeout",function(a){angular.isUndefined(a)||g(function(){c.refreshAds(h)},b.timeout)})})})}}}]);module.exports="ngDfp";