From ab65c2e6edea3a2018bbf3a27b887cfb9e26cfbf Mon Sep 17 00:00:00 2001 From: Chuck Carpenter Date: Mon, 6 Oct 2014 13:29:27 -0400 Subject: [PATCH] add settings to allow for companion ads and autoplay companion ads --- .gitignore | 1 + bower.json | 2 +- jquery.dfp.js | 14 +++++++++++++- jquery.dfp.min.js | 4 ++-- package.json | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 34e85ec..44667b9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ tmp/ *.bak *.swp *~.nib +*.log local.properties .classpath .settings/ diff --git a/bower.json b/bower.json index 58db308..0db9c29 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.dfp", - "version": "1.1.4", + "version": "1.1.5", "main": "jquery.dfp.js", "ignore": [ "img/", diff --git a/jquery.dfp.js b/jquery.dfp.js index 48a8330..7e97200 100644 --- a/jquery.dfp.js +++ b/jquery.dfp.js @@ -146,7 +146,13 @@ if ($adUnit.data('outofpage')) { googleAdUnit = window.googletag.defineOutOfPageSlot('/' + dfpID + '/' + adUnitName, adUnitID).addService(window.googletag.pubads()); } else { - googleAdUnit = window.googletag.defineSlot('/' + dfpID + '/' + adUnitName, dimensions, adUnitID).addService(window.googletag.pubads()); + if ($adUnit.data('companion')) { + googleAdUnit = window.googletag.defineSlot('/' + dfpID + '/' + adUnitName, dimensions, adUnitID) + .addService(window.googletag.companionAds()).addService(window.googletag.pubads()); + } else { + googleAdUnit = window.googletag.defineSlot('/' + dfpID + '/' + adUnitName, dimensions, adUnitID) + .addService(window.googletag.pubads()); + } } } @@ -229,7 +235,13 @@ if (dfpOptions.disablePublisherConsole) { window.googletag.pubads().disablePublisherConsole(); } + if (dfpOptions.companionAds) { + window.googletag.companionAds().setRefreshUnfilledSlots(true); + if (!dfpOptions.disableInitialLoad) { + window.googletag.pubads().enableVideoAds(); + } + } if (dfpOptions.disableInitialLoad) { window.googletag.pubads().disableInitialLoad(); } diff --git a/jquery.dfp.min.js b/jquery.dfp.min.js index a80ddc0..9d6b7f9 100644 --- a/jquery.dfp.min.js +++ b/jquery.dfp.min.js @@ -1,8 +1,8 @@ /** - * jQuery DFP v1.1.4 + * jQuery DFP v1.1.5 * http://github.com/coop182/jquery.dfp.js * * Copyright 2014 Matt Cooper * Released under the MIT license */ -!function(a,b,c){"use strict";var d,e=this,f="",g=0,h=0,i=0,j=".adunit",k={},l=!1,m="googleAdUnit",n=function(b,c,e){g=0,i=0,f=b,d=a(c),v(),o(e),a(function(){p(),q()})},o=function(d){if(k={setTargeting:{},setCategoryExclusion:"",setLocation:"",enableSingleRequest:!0,collapseEmptyDivs:"original",refreshExisting:!0,disablePublisherConsole:!1,disableInitialLoad:!1,noFetch:!1,namespace:c,sizeMapping:{}},"undefined"==typeof d.setUrlTargeting||d.setUrlTargeting){var e=r();a.extend(!0,k.setTargeting,{inURL:e.inURL,URLIs:e.URLIs,Query:e.Query,Domain:b.location.host})}a.extend(!0,k,d),k.googletag&&b.googletag.cmd.push(function(){a.extend(!0,b.googletag,k.googletag)})},p=function(){d.each(function(){var c=a(this);g++;var d=t(c),e=s(c,d),h=u(c);c.data("existingContent",c.html()),c.html("").addClass("display-none"),b.googletag.cmd.push(function(){var g,i=c.data(m);g=i?i:c.data("outofpage")?b.googletag.defineOutOfPageSlot("/"+f+"/"+d,e).addService(b.googletag.pubads()):b.googletag.defineSlot("/"+f+"/"+d,h,e).addService(b.googletag.pubads());var j=c.data("targeting");j&&a.each(j,function(a,b){g.setTargeting(a,b)});var l=c.data("exclusions");if(l){var n,o=l.split(",");a.each(o,function(b,c){n=a.trim(c),n.length>0&&g.setCategoryExclusion(n)})}var p=c.data("size-mapping");if(p&&k.sizeMapping[p]){var q=b.googletag.sizeMapping();a.each(k.sizeMapping[p],function(a,b){q.addSize(b.browser,b.ad_sizes)}),g.defineSizeMapping(q.build())}c.data(m,g),"function"==typeof k.beforeEachAdLoaded&&k.beforeEachAdLoaded.call(this,c)})}),b.googletag.cmd.push(function(){if(k.enableSingleRequest&&b.googletag.pubads().enableSingleRequest(),a.each(k.setTargeting,function(a,c){b.googletag.pubads().setTargeting(a,c)}),"object"==typeof k.setLocation&&("number"==typeof k.setLocation.latitude&&"number"==typeof k.setLocation.longitude&&"number"==typeof k.setLocation.precision?b.googletag.pubads().setLocation(k.setLocation.latitude,k.setLocation.longitude,k.setLocation.precision):"number"==typeof k.setLocation.latitude&&"number"==typeof k.setLocation.longitude&&b.googletag.pubads().setLocation(k.setLocation.latitude,k.setLocation.longitude)),k.setCategoryExclusion.length>0){var c,e=k.setCategoryExclusion.split(",");a.each(e,function(d,e){c=a.trim(e),c.length>0&&b.googletag.pubads().setCategoryExclusion(c)})}k.collapseEmptyDivs&&b.googletag.pubads().collapseEmptyDivs(),k.disablePublisherConsole&&b.googletag.pubads().disablePublisherConsole(),k.disableInitialLoad&&b.googletag.pubads().disableInitialLoad(),k.noFetch&&b.googletag.pubads().noFetch(),b.googletag.pubads().addEventListener("slotRenderEnded",function(b){i++;var c=a("#"+b.slot.getSlotId().getDomId()),e=b.isEmpty?"none":"block",f=c.data("existingContent");"none"===e&&a.trim(f).length>0&&"original"===k.collapseEmptyDivs&&(c.show().html(f),e="block display-original"),c.removeClass("display-none").addClass("display-"+e),"function"==typeof k.afterEachAdLoaded&&k.afterEachAdLoaded.call(this,c,b),"function"==typeof k.afterAllAdsLoaded&&i===g&&k.afterAllAdsLoaded.call(this,d)}),b.googletag.enableServices()})},q=function(){d.each(function(){var c=a(this),d=c.data(m);b.googletag.cmd.push(k.refreshExisting&&d&&c.hasClass("display-block")?function(){b.googletag.pubads().refresh([d])}:function(){b.googletag.display(c.attr("id"))})})},r=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}},s=function(a,b){return h++,a.attr("id")||a.attr("id",b.replace(/[^A-z0-9]/g,"_")+"-auto-gen-id-"+h).attr("id")},t=function(a){var b=a.data("adunit")||k.namespace||a.attr("id")||"";return"function"==typeof k.alterAdUnitName&&(b=k.alterAdUnitName.call(this,b,a)),b},u=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},v=function(){if(l=l||a('script[src*="googletagservices.com/tag/js/gpt.js"]').length,!l){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(){w()};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&&w()}},w=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=j),n(a,d,b),this}}(window.jQuery||window.Zepto||window.tire,window); \ No newline at end of file +!function(a,b,c){"use strict";var d,e=this,f="",g=0,h=0,i=0,j=".adunit",k={},l=!1,m="googleAdUnit",n=function(b,c,e){g=0,i=0,f=b,d=a(c),v(),o(e),a(function(){p(),q()})},o=function(d){if(k={setTargeting:{},setCategoryExclusion:"",setLocation:"",enableSingleRequest:!0,collapseEmptyDivs:"original",refreshExisting:!0,disablePublisherConsole:!1,disableInitialLoad:!1,noFetch:!1,namespace:c,sizeMapping:{}},"undefined"==typeof d.setUrlTargeting||d.setUrlTargeting){var e=r();a.extend(!0,k.setTargeting,{inURL:e.inURL,URLIs:e.URLIs,Query:e.Query,Domain:b.location.host})}a.extend(!0,k,d),k.googletag&&b.googletag.cmd.push(function(){a.extend(!0,b.googletag,k.googletag)})},p=function(){d.each(function(){var c=a(this);g++;var d=t(c),e=s(c,d),h=u(c);c.data("existingContent",c.html()),c.html("").addClass("display-none"),b.googletag.cmd.push(function(){var g,i=c.data(m);g=i?i:c.data("outofpage")?b.googletag.defineOutOfPageSlot("/"+f+"/"+d,e).addService(b.googletag.pubads()):c.data("companion")?b.googletag.defineSlot("/"+f+"/"+d,h,e).addService(b.googletag.companionAds()).addService(b.googletag.pubads()):b.googletag.defineSlot("/"+f+"/"+d,h,e).addService(b.googletag.pubads());var j=c.data("targeting");j&&a.each(j,function(a,b){g.setTargeting(a,b)});var l=c.data("exclusions");if(l){var n,o=l.split(",");a.each(o,function(b,c){n=a.trim(c),n.length>0&&g.setCategoryExclusion(n)})}var p=c.data("size-mapping");if(p&&k.sizeMapping[p]){var q=b.googletag.sizeMapping();a.each(k.sizeMapping[p],function(a,b){q.addSize(b.browser,b.ad_sizes)}),g.defineSizeMapping(q.build())}c.data(m,g),"function"==typeof k.beforeEachAdLoaded&&k.beforeEachAdLoaded.call(this,c)})}),b.googletag.cmd.push(function(){if(k.enableSingleRequest&&b.googletag.pubads().enableSingleRequest(),a.each(k.setTargeting,function(a,c){b.googletag.pubads().setTargeting(a,c)}),"object"==typeof k.setLocation&&("number"==typeof k.setLocation.latitude&&"number"==typeof k.setLocation.longitude&&"number"==typeof k.setLocation.precision?b.googletag.pubads().setLocation(k.setLocation.latitude,k.setLocation.longitude,k.setLocation.precision):"number"==typeof k.setLocation.latitude&&"number"==typeof k.setLocation.longitude&&b.googletag.pubads().setLocation(k.setLocation.latitude,k.setLocation.longitude)),k.setCategoryExclusion.length>0){var c,e=k.setCategoryExclusion.split(",");a.each(e,function(d,e){c=a.trim(e),c.length>0&&b.googletag.pubads().setCategoryExclusion(c)})}k.collapseEmptyDivs&&b.googletag.pubads().collapseEmptyDivs(),k.disablePublisherConsole&&b.googletag.pubads().disablePublisherConsole(),k.companionAds&&(b.googletag.companionAds().setRefreshUnfilledSlots(!0),k.disableInitialLoad||b.googletag.pubads().enableVideoAds()),k.disableInitialLoad&&b.googletag.pubads().disableInitialLoad(),k.noFetch&&b.googletag.pubads().noFetch(),b.googletag.pubads().addEventListener("slotRenderEnded",function(b){i++;var c=a("#"+b.slot.getSlotId().getDomId()),e=b.isEmpty?"none":"block",f=c.data("existingContent");"none"===e&&a.trim(f).length>0&&"original"===k.collapseEmptyDivs&&(c.show().html(f),e="block display-original"),c.removeClass("display-none").addClass("display-"+e),"function"==typeof k.afterEachAdLoaded&&k.afterEachAdLoaded.call(this,c,b),"function"==typeof k.afterAllAdsLoaded&&i===g&&k.afterAllAdsLoaded.call(this,d)}),b.googletag.enableServices()})},q=function(){d.each(function(){var c=a(this),d=c.data(m);b.googletag.cmd.push(k.refreshExisting&&d&&c.hasClass("display-block")?function(){b.googletag.pubads().refresh([d])}:function(){b.googletag.display(c.attr("id"))})})},r=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}},s=function(a,b){return h++,a.attr("id")||a.attr("id",b.replace(/[^A-z0-9]/g,"_")+"-auto-gen-id-"+h).attr("id")},t=function(a){var b=a.data("adunit")||k.namespace||a.attr("id")||"";return"function"==typeof k.alterAdUnitName&&(b=k.alterAdUnitName.call(this,b,a)),b},u=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},v=function(){if(l=l||a('script[src*="googletagservices.com/tag/js/gpt.js"]').length,!l){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(){w()};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&&w()}},w=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=j),n(a,d,b),this}}(window.jQuery||window.Zepto||window.tire,window); \ No newline at end of file diff --git a/package.json b/package.json index 6bf9089..8fbbb25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery.dfp", - "version": "1.1.4", + "version": "1.1.5", "devDependencies": { "grunt": "~0.4", "grunt-contrib-jshint": "~0.9",