angular-dfp
Version:
Semantic DoubleClick integration with AngularJS
39 lines (35 loc) • 15.1 kB
JavaScript
/*
Apache
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var n="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global?global:this;function v(d){var b=Error;function c(){}c.prototype=b.prototype;d.prototype=new c;d.prototype.constructor=d;for(var a in b)if(n.Object.defineProperties){var p=n.Object.getOwnPropertyDescriptor(b,a);void 0!==p&&n.Object.defineProperty(d,a,p)}else d[a]=b[a]}var googletag=googletag||{};googletag.cmd=googletag.cmd||[];var A=angular.module("angularDfp",[]);(function(d){d.factory("httpError",["$log",function(b){function c(a){b.error("Error ("+a.status+")")}c.X=function(a){if("number"===typeof a)return!(200<=a&&300>a);console.assert("string"===typeof a);return"2"!==a[0]};return c}])})(A);(function(d){function b(){}v(b);b.a=Error.captureStackTrace;d.factory("parseDuration",function(){return function(c){if(void 0===c||null===c)throw new b;if("number"===typeof c)return c;if("string"!==typeof c)throw new TypeError("'"+c+"' must be of number or string type");var a=c.match(/((?:\d+)?.?\d+)(m?s|min|h)?/);if(!a)throw new b;c=parseFloat(a[1]);2!==a.length&&(a=a[2],console.assert(/^(m?s|min|h)$/g.test(a)),c="ms"===a?c:"s"===a?1E3*c:"min"===a?6E4*c:36E5*c);return c}})})(A);(function(d){d.factory("scriptInjector",["$q","httpError",function(b,c){function a(a,g){function f(){e.resolve()}function d(a){a=a||{status:400};c(a,'loading script "{0}".',g);e.reject(a)}var e=b.defer();a.onreadystatechange=function(){4===this.readyState&&(c.X(this.status)?d(this):f())};a.onload=f;a.onerror=d;return e.promise}return function(c){var b=document.createElement("script"),f="https:"===document.location.protocol;b.async="async";b.type="text/javascript";b.src=(f?"https:":"http:")+c;(document.head||
document.querySelector("head")).appendChild(b);return a(b,c)}}])})(A);googletag=googletag||{};googletag.cmd=googletag.cmd||[];
(function(d){function b(a){var c=[],b=[],f=[],d=[],e=[];this.J=function(a){return void 0!==this[a]};this.j=function(){if(0===c.length)throw new a("dfp-ad","dfp-size");if(!this.adUnit)throw new a("dfp-ad","ad-unit",!0);};this.l=function(){this.j();return Object.freeze({sizes:c,w:b,aa:f,V:d,I:this.adUnit,D:this.J("forceSafeFrame"),m:this.safeFrameConfig,K:this.clickUrl,refresh:this.refresh,scripts:e,B:this.J("collapseIfEmpty")})};this.addSize=function(a){c.push(a)};this.O=function(a){b.push(a)};this.R=
function(a){f.push(a)};this.N=function(a){d.push(a)};this.P=function(a){e.push(a)}}function c(a,c,b,f,d){function e(a){if(0!==k.w.length){var c=googletag.sizeMapping();k.w.forEach(function(a){c.addSize(a.viewportSize,a.adSizes)});a.defineSizeMapping(c.build())}}function l(a){return a.map(function(a){return{width:a.viewportSize[0],height:a.viewportSize[1]}})}b=d.get("dfp");var r=d.get("dfpIDGenerator"),u=d.get("dfpRefresh"),x=d.get("dfpResponsiveResize"),k=f.l(),z=c;c=c[0];r(c);b.then(function(){var b=
googletag.defineSlot(k.I,k.sizes,c.id);void 0!==k.D&&b.setForceSafeFrame(!0);k.K&&b.setClickUrl(k.K);k.B&&b.setCollapseEmptyDiv(!0,!0);k.m&&b.setSafeFrameConfig(JSON.parse(k.m));e(b);k.aa.forEach(function(a){b.setTargeting(a.key,a.values)});k.V.forEach(function(a){b.setCategoryExclusion(a)});k.scripts.forEach(function(a){a(b)});b.addService(googletag.pubads());googletag.display(c.id);u(b,k.refresh).then(function(){if(0<k.w.length){var a=l(k.w);x(z,b,a)}});a.$on("$destroy",function(){console.assert(googletag.destroySlots([b]))})})}
d.directive("dfpAd",["$injector",function(a){return{restrict:"AE",controller:["DFPIncompleteError",b],controllerAs:"controller",bindToController:!0,link:function(b){for(var g=[],d=0;d<arguments.length;++d)g[d-0]=arguments[d];c.apply(null,g.slice(0,4).concat(a))},scope:{adUnit:"@",clickUrl:"@",forceSafeFrame:"@",safeFrameConfig:"@",refresh:"@",collapseIfEmpty:"@"}}}])})(A);(function(d){function b(c,a){var b=1E13*String(Math.random()),d="";c.I&&(d="dc_iu="+c.adUnit);var f="";c.v&&(f="ppid="+c.ppid);var h=document.createElement("img");h.src="https://pubads.g.doubleclick.net/activity;ord=";h.src+=b+";dc_seg="+c.segmentId+";"+d+f;h.width=1;h.height=1;h.border=0;h.style.visibility="hidden";a.append(h)}d.directive("dfpAudiencePixel",[function(){return{restrict:"E",link:b,scope:{adUnit:"@",segmentId:"@",ppid:"@"}}}])})(A);(function(d){d.factory("DFPIncompleteError",function(){function b(){}v(b);b.a=Error.captureStackTrace;return b});d.factory("DFPTypeError",function(){function b(){}v(b);b.a=Error.captureStackTrace;return b});d.factory("DFPMissingParentError",function(){function b(c,a){for(var b=[],d=1;d<arguments.length;++d)b[d-1]=arguments[d];console.assert(b&&0<b.length);Array.isArray(b[0])&&(b=b[0]);1<b.length&&(b=b.map(function(a){return"'"+a+"'"}))}v(b);b.a=Error.captureStackTrace;return b})})(A);(function(d){function b(c,a,b,d){d.N(a.html())}d.directive("dfpExclusion",[function(){return{restrict:"E",require:"^^dfpAd",link:b}}])})(A);(function(d){d.factory("dfpIDGenerator",[function(){function b(a){if(a&&a.id&&!(a.id in c))return a.id;var b=null;do b="gpt-ad-"+Math.random().toString().slice(2);while(b in c);c[b]=!0;a&&(a.id=b);return b}var c={};b.a=function(a){return a in c};b.u=function(a){return!b.a(a)};return b}])})(A);googletag=googletag||{};googletag.cmd=googletag.cmd||[];
(function(d){function b(){}v(b);b.a=Error.captureStackTrace;d.provider("dfpRefresh",[function(){var c=this;c.b=null;c.f=null;c.G=!0;c.c=null;c.priority={refresh:1,interval:1,barrier:1};c.$get=["$rootScope","$interval","$q","$log","parseDuration",function(a,d,g,f,h){function e(a,b,c){var d=g.defer();a={M:a,U:d};b&&E(a,b);b&&c||(e.L()?C(a):u([a]));return d.promise}function l(a){if("number"!==typeof a)throw new b;}function r(){var a=Object.keys(m).map(function(a){return m[a]}).filter(e.Y),b=a.map(function(a){return c.priority[a]}),
d=null;0<b.length&&(d=b.reduce(function(a,b){return Math.max(a,b)}));for(var g=0;g<a.length;++g)if(b[g]===d)switch(a[g]){case m.s:x();break;case m.o:z();break;case m.h:console.assert(e.u());q.i=!0;break;default:console.assert(!1)}else switch(a[g]){case m.s:k();break;case m.o:y();break;case m.h:q.i=!1;break;default:console.assert(!1)}}function u(a){console.assert(void 0===a||null!==a);void 0===a?googletag.cmd.push(function(){googletag.pubads().refresh()}):0!==a.length&&(a=a.filter(function(a){return null!==
a}),googletag.cmd.push(function(){googletag.pubads().refresh(a.map(function(a){return a.M}));a.forEach(function(a){return a.U.resolve()})}))}function x(){console.assert(e.C());var a=d(function(){B();u()},c.c);t.refresh=a;q.refresh=!0}function k(){q.refresh&&(d.cancel(t.refresh),t.refresh=null,q.refresh=!1)}function z(){console.assert(e.A());var a=d(function(){u(w);B()},c.b);t.buffer=a;q.interval=!0}function y(){q.interval&&(d.cancel(t.buffer),t.buffer=null,q.interval=!1)}function B(){if(q.i)for(var a=
0;a<w.length;++a)w[a]=null;else w=[]}function E(a,b){var c=h(b);D(c);c=d(function(){e.L()?C(a):u([a])},c);t[a.M]=c}function C(a){w.push(a);q[m.h]&&w.length===c.f&&(u(w),w=[],c.G&&e.W())}function D(a){console.assert(a);500>a&&f.warn("Careful: ${beforeParsing} is quite a low interval!")}var m=Object.freeze({s:"refresh",o:"interval",h:"barrier"});e.Options=Object.freeze({REFRESH:m.s,INTERVAL:m.o,BARRIER:m.h});var w=[],t={refresh:null,buffer:null},q=Object.seal({refresh:null!==c.c,interval:null!==c.b,
i:null!==c.f});e.sa=function(a){if(!e.Z(a))throw new b;d.cancel(t[a]);delete t[a];return e};e.Z=function(a){return a in t};e.ka=function(a){c.b=h(a);r();return e};e.ta=function(){if(!e.A())return console.warn("clearBufferInterval had no effect because no interval was set."),e;y();c.b=null;r();return e};e.A=function(){return null!==c.b};e.ra=function(){return q.interval};e.da=function(){return c.b};e.ja=function(a,b){c.f=a;c.G=void 0===b?!0:b;r();return e};e.W=function(){e.u()?(c.f=null,r()):console.warn("clearBufferBarrier had not effect because no barrier was set.")};
e.ca=function(){return c.f};e.u=function(){return null!==c.f};e.pa=function(){return q.i};e.qa=function(){return c.G};e.ma=function(a){c.c=h(a);D(c.c);x();r();return e};e.C=function(){return null!==c.c};e.ha=function(){return q.refresh};e.ua=function(){e.C()||console.warn("clearRefreshInterval had no effect because no refresh interval was set.");k();r();return e};e.fa=function(){return c.c};e.L=function(){return q.i||q.interval};e.Y=function(a){switch(a){case m.s:return e.C();case m.o:return e.A();
case m.h:return e.u();default:throw new b;}};e.F=function(a,e){if(!(a in m))throw new b;l(e);c.priority[a]=e};e.a=function(a){if(!(a in m))throw new b;return c.priority[a]};e.na=function(a){l(a);e.F("refresh",a)};e.ga=function(){return e.a("refresh")};e.ia=function(a){l(a);e.F("barrier",a)};e.ba=function(){return e.a("barrier")};e.la=function(a){l(a);e.F("interval",a)};e.ea=function(){return e.a("interval")};a.$on("$destroy",function(){t.forEach(function(a){d.cancel(a)})});c.c&&(c.c=h(c.c));c.b&&
(c.b=h(c.b));r();return e}]}])})(A);(function(d){d.provider("dfpResponsiveResize",function(){var b=this;b.H=200;this.$get=["$interval","$timeout","$window","dfpRefresh","parseDuration",function(c,a,d,g,f){d=angular.element(d);b.H=f(b.H);return function(f,e,l){function r(){return f.find("div iframe")}function u(a){a=a||r();a.css("width",a.attr("width")+"px");a.css("height",a.attr("height")+"px")}function x(a){var b=r();["width","height"].some(function(c){return b.attr(c)!==a[c]})&&(u(b),f.parent().removeClass("refreshing"))}function k(b){var e=
c(function(){return x(b)},100);a(function(){return c.cancel(e)},2500)}function z(){var a=r(),a=[a.css("width"),a.css("height")].map(function(a){return a?a.slice(0,-2):null});return{width:a[0],height:a[1]}}function y(){k(z());d.on("resize",function(){u()})}l.sort(function(a,b){return a.width<b.width?-1:a.width>b.width?1:a.height<b.height?-1:a.height>b.height?1:0});d.on("resize",function(){function c(){g(e).then(function(){y()})}function d(e){console.assert(0<=p&&p<l.length);console.assert(-1===e||
1===e);p+=e;f.parent().addClass("refreshing");a(c,b.H);console.assert(0<=p&&p<l.length)}var p=function(){for(var a=window.innerWidth,b=window.innerHeight,c=l.length,e=1;e<c&&!(a<l[e].width)&&!(b<l[e].height);++e);return e-1}();y();return function(){p+1>=l.length||window.innerWidth<l[p+1].width||window.innerHeight<l[p+1].height?(0===p?0:window.innerWidth<l[p].width||window.innerHeight<l[p].height)&&d(-1):d(1)}}())}}]})})(A);(function(d){function b(a,b){var c=Object.seal([this.viewportWidth,this.viewportHeight||0]),d=[];this.j=function(){var c=this;["viewportWidth","viewportHeight"].forEach(function(a){var d=c[a];if("number"!==typeof d)throw a=a.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()}),new b("dfp-responsive",a,d,"number");});if(0===d.length)throw new a("dfp-responsive","dfp-size",!1);};this.addSize=function(a){d.push(a)};this.l=function(){this.j();return Object.freeze({viewportSize:c,adSizes:d})}}function c(a,
b,c,d){a=a.controller.l();d.O(a)}b.a=["$scope"];d.directive("dfpResponsive",[function(){return{restrict:"E",require:"^^dfpAd",controller:["DFPIncompleteError","DFPTypeError",b],controllerAs:"controller",bindToController:!0,link:c,scope:{viewportWidth:"=",viewportHeight:"="}}}])})(A);(function(d){function b(){}function c(a,c,d,f,h){function e(b){f.P(eval("(function(scope, "+a.slotAs+"){"+b+"})").bind(null,a.scope))}d=h.get("$http");h=h.get("$log");a.src?(c.html()&&h.warn("Ignoring inner HTML of dfp-script in favor of src contents."),d.get(a.src).then(function(a){e(a.data)},function(){throw new b;})):e(c.html().trim())}v(b);b.a=Error.captureStackTrace;d.directive("dfpScript",["$injector",function(a){return{restrict:"E",require:"^^dfpAd",scope:{slotAs:"@",scope:"=",src:"@"},link:function(b){for(var d=
[],f=0;f<arguments.length;++f)d[f-0]=arguments[f];c.apply(null,d.slice(0,4).concat(a))}}}])})(A);(function(d){function b(b,a,d,g,f){g=g[1]||g[0];if(!g)throw new f("dfp-size","dfp-ad","dfp-responsive");b.width&&b.height?g.addSize([b.width,b.height]):g.addSize(a[0].innerHTML)}d.directive("dfpSize",["DFPMissingParentError",function(c){return{restrict:"E",require:["?^^dfpAd","?^^dfpResponsive"],scope:{width:"=",height:"="},link:function(a){for(var d=[],g=0;g<arguments.length;++g)d[g-0]=arguments[g];d=d.slice(0,4).concat(c);b.apply(null,d)}}}])})(A);(function(d){function b(a){var b=this.value?[this.value]:[];this.j=function(){if(void 0===this.key)throw new a("dfp-targeting","key",!0);if(0===b.length)throw new a("dfp-targeting","value",!0);};this.l=function(){this.j();return Object.freeze({key:this.key,values:b})};this.S=function(a){b.push(a)}}function c(a,b,c,d){console.assert(void 0!==d);a=a.controller.l();d.R(a)}d.directive("dfpTargeting",[function(){return{restrict:"E",require:"^^dfpAd",controller:["DFPIncompleteError",b],controllerAs:"controller",
bindToController:!0,scope:{key:"@",value:"@"},link:c}}])})(A);(function(d){function b(b,a,d,g){g.S(a.html())}d.directive("dfpValue",[function(){return{restrict:"E",require:"^^dfpTargeting",link:b}}])})(A);(function(d){function b(){}function c(a,c,d,f){d=f.get("dfpIDGenerator");c=c[0];if("VIDEO"!==c.tagName)throw new b;d(c);d=videojs(c.id);d.ima({id:c.id,oa:a.adTag});d.ima.requestAds();d.ima.initializeAdDisplayContainer()}v(b);b.a=Error.captureStackTrace;d.directive("dfpVideo",["$injector",function(a){return{restrict:"A",scope:{adTag:"@"},link:function(b){for(var d=[],f=0;f<arguments.length;++f)d[f-0]=arguments[f];c.apply(null,d.slice(0,3).concat(a))}}}]);return d})(angular.module("angularDfp"));googletag=googletag||{};googletag.cmd=googletag.cmd||[];
(function(d){function b(){}v(b);b.a=Error.captureStackTrace;d.constant("GPT_LIBRARY_URL","//www.googletagservices.com/tag/js/gpt.js");window.googletag=googletag;d.provider("dfp",["GPT_LIBRARY_URL",function(c){var a=this;a.enableVideoAds=!0;a.B=!0;a.T=!1;a.location=null;a.v=null;a.g=null;a.D=!1;a.m=null;a.$=!0;var d=!1;this.$get=["scriptInjector",function(g){function f(){var c=googletag.pubads();a.enableVideoAds&&c.enableVideoAds();a.B&&c.collapseEmptyDivs();c.disableInitialLoad();c.setForceSafeFrame(a.D);
c.setCentering(a.T);if(a.location)if("string"===typeof a.location)c.setLocation(a.location);else{if(!Array.isArray(a.location))throw new b;c.setLocation.apply(c,a.location)}if(a.v){if("string"!==typeof a.v)throw new b;c.setPublisherProvidedId(a.v)}if(a.g){if("object"!==typeof a.g)throw new b;for(var d in a.g)a.g.hasOwnProperty(d)&&c.setTargeting(d,a.g[d])}if(a.m){if("object"!==typeof a.g)throw new b;c.setSafeFrameConfig(a.m)}googletag.enableServices()}function h(){googletag.cmd.push(f);a.$&&g(c).then(function(){d=
!0})}h.a=function(){return d};h.then=function(a){googletag.cmd.push(a)};return h}]}])})(A);