forked from coop182/jquery.dfp.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.dfp.min.js
8 lines (8 loc) · 5.26 KB
/
jquery.dfp.min.js
1
2
3
4
5
6
7
8
/**
* jQuery DFP v1.0.18
* http://github.com/coop182/jquery.dfp.js
*
* Copyright 2013 Matt Cooper
* Released under the MIT license
*/
!function(a,b,c){"use strict";var d,e=this,f="",g=0,h=0,i=".adunit",j={},k=!1,l="googleAdUnit",m=function(b,c,e){f=b,d=a(c),u(),n(e),a(function(){o(),p()})},n=function(c){if(j={setTargeting:{},setCategoryExclusion:"",setLocation:"",enableSingleRequest:!0,collapseEmptyDivs:"original",refreshExisting:!0,disablePublisherConsole:!1,disableInitialLoad:!1,noFetch:!1},"undefined"==typeof c.setUrlTargeting||c.setUrlTargeting){var d=q();a.extend(!0,j.setTargeting,{inURL:d.inURL,URLIs:d.URLIs,Query:d.Query,Domain:b.location.host})}a.extend(!0,j,c),j.googletag&&b.googletag.cmd.push(function(){a.extend(!0,b.googletag,j.googletag)})},o=function(){d.each(function(){var c=a(this);g++;var e=s(c),i=r(c,e,g),k=t(c),m=c.html();c.html("").addClass("display-none"),b.googletag.cmd.push(function(){var n,o=c.data(l);n=o?o:c.data("outofpage")?b.googletag.defineOutOfPageSlot("/"+f+"/"+e,i).addService(b.googletag.pubads()):b.googletag.defineSlot("/"+f+"/"+e,k,i).addService(b.googletag.pubads());var p=c.data("targeting");p&&a.each(p,function(a,b){n.setTargeting(a,b)});var q=c.data("exclusions");if(q){var r,s=q.split(",");a.each(s,function(b,c){r=a.trim(c),r.length>0&&n.setCategoryExclusion(r)})}n.oldRenderEnded=n.oldRenderEnded||n.renderEnded,n.renderEnded=function(){h++;var b=c.css("display");"none"===b&&a.trim(m).length>0&&"original"===j.collapseEmptyDivs&&(c.show().html(m),b="block display-original"),c.removeClass("display-none").addClass("display-"+b),n.oldRenderEnded(),"function"==typeof j.afterEachAdLoaded&&j.afterEachAdLoaded.call(this,c),"function"==typeof j.afterAllAdsLoaded&&h===g&&j.afterAllAdsLoaded.call(this,d)},c.data(l,n)})}),b.googletag.cmd.push(function(){if(j.enableSingleRequest===!0&&b.googletag.pubads().enableSingleRequest(),a.each(j.setTargeting,function(a,c){b.googletag.pubads().setTargeting(a,c)}),"object"==typeof j.setLocation&&("number"==typeof j.setLocation.latitude&&"number"==typeof j.setLocation.longitude&&"number"==typeof j.setLocation.precision?b.googletag.pubads().setLocation(j.setLocation.latitude,j.setLocation.longitude,j.setLocation.precision):"number"==typeof j.setLocation.latitude&&"number"==typeof j.setLocation.longitude&&b.googletag.pubads().setLocation(j.setLocation.latitude,j.setLocation.longitude)),j.setCategoryExclusion.length>0){var c,d=j.setCategoryExclusion.split(",");a.each(d,function(d,e){c=a.trim(e),c.length>0&&b.googletag.pubads().setCategoryExclusion(c)})}(j.collapseEmptyDivs===!0||"original"===j.collapseEmptyDivs)&&b.googletag.pubads().collapseEmptyDivs(),j.disablePublisherConsole===!0&&b.googletag.pubads().disablePublisherConsole(),j.disableInitialLoad===!0&&b.googletag.pubads().disableInitialLoad(),j.noFetch===!0&&b.googletag.pubads().noFetch(),b.googletag.enableServices()})},p=function(){d.each(function(){var c=a(this),d=c.data(l);j.refreshExisting&&d&&c.hasClass("display-block")?b.googletag.cmd.push(function(){b.googletag.pubads().refresh([d])}):b.googletag.cmd.push(function(){b.googletag.display(c.attr("id"))})})},q=function(){var a=b.location.pathname.replace(/\/$/,""),c=new RegExp("/([^/]*)","ig"),d=a.match(c),e=["/"],f="";if(d&&"/"!==a){var g="",h=d.length;if(h>0)for(var i=0;h>i;i++){g=d[i],e.push(g);for(var j=i+1;h>j;j++)g+=d[j],e.push(g);0===i&&(e.splice(-1,1),f=g)}e.push(f)}e=e.reverse();var k=(b.location.toString().replace(/\=/gi,":").match(/\?(.+)$/),RegExp.$1.split("&"));return{inURL:e,URLIs:e[0],Query:k}},r=function(a,b,c){return a.attr("id")||a.attr("id",b+"-auto-gen-id-"+c).attr("id")},s=function(a){return a.data("adunit")||a.attr("id")},t=function(b){var c=[],d=b.data("dimensions");if(d){var e=d.split(",");a.each(e,function(a,b){var d=b.split("x");c.push([parseInt(d[0],10),parseInt(d[1],10)])})}else c.push([b.width(),b.height()]);return c},u=function(){if(k=k||a('script[src*="googletagservices.com/tag/js/gpt.js"]').length,!k){b.googletag=b.googletag||{},b.googletag.cmd=b.googletag.cmd||[];var c=document.createElement("script");c.async=!0,c.type="text/javascript",c.onerror=function(){v()};var d="https:"===document.location.protocol;c.src=(d?"https:":"http:")+"//www.googletagservices.com/tag/js/gpt.js";var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(c,e),"none"===c.style.display&&v()}},v=function(){var c=b.googletag.cmd;setTimeout(function(){var d=function(a,c,d){return b.googletag.ads.push(d),b.googletag.ads[d]={renderEnded:function(){},addService:function(){return this}},b.googletag.ads[d]};b.googletag={cmd:{push:function(a){a.call(e)}},ads:[],pubads:function(){return this},noFetch:function(){return this},disableInitialLoad:function(){return this},disablePublisherConsole:function(){return this},enableSingleRequest:function(){return this},setTargeting:function(){return this},collapseEmptyDivs:function(){return this},enableServices:function(){return this},defineSlot:function(a,b,c){return d(a,b,c,!1)},defineOutOfPageSlot:function(a,b){return d(a,[],b,!0)},display:function(a){return b.googletag.ads[a].renderEnded.call(e),this}},a.each(c,function(a,c){b.googletag.cmd.push(c)})},50)};a.dfp=a.fn.dfp=function(a,b){b=b||{},a===c&&(a=f),"object"==typeof a&&(b=a,a=b.dfpID||f);var d=this;return"function"==typeof this&&(d=i),m(a,d,b),this}}(window.jQuery||window.Zepto||window.tire,window);