From 5411ffb6f21e72a8d3e7e2782c2716ea5d9b25db Mon Sep 17 00:00:00 2001 From: nechehin Date: Tue, 24 Oct 2017 17:01:11 +0300 Subject: [PATCH] fix - collapse ads on empty ads --- vast-contentroll.js | 3 ++- vast-contentroll.min.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/vast-contentroll.js b/vast-contentroll.js index 36b4d87..13a4516 100644 --- a/vast-contentroll.js +++ b/vast-contentroll.js @@ -35,7 +35,7 @@ this._domObserver&&(this._domObserver.disconnect(),this._domObserver=null))};d.p /*! * VAST content-roll * - * @version 0.0.8 + * @version 0.0.9 * @link https://github.com/nechehin/vast-contentroll */ (function(){ @@ -255,6 +255,7 @@ this._domObserver&&(this._domObserver.disconnect(),this._domObserver=null))};d.p */ function onAdsEmpty(roll) { intersectionObserver.unobserve(roll); + roll.style.height = '0'; var onEmptyCallback = data(roll, 'on-empty'); if (typeof window[onEmptyCallback] === 'function') { diff --git a/vast-contentroll.min.js b/vast-contentroll.min.js index 6ab3a4d..a1421c4 100644 --- a/vast-contentroll.min.js +++ b/vast-contentroll.min.js @@ -35,15 +35,15 @@ this._domObserver&&(this._domObserver.disconnect(),this._domObserver=null))};d.p /*! * VAST content-roll * - * @version 0.0.8 + * @version 0.0.9 * @link https://github.com/nechehin/vast-contentroll */ (function(){var g=document.createElement("script");g.async=!0;g.src="https://imasdk.googleapis.com/js/sdkloader/ima3.js";g.onload=function(){function f(a,c,b){c="data-"+c;return"undefined"!==typeof b?a.setAttribute(c,b):a.getAttribute(c)}function b(a,c,b){return"undefined"!==typeof b?f(a,c,b?"1":"0"):~["1","true"].indexOf(f(a,c))?!0:!1}function d(a,c,d){b(a,e.DEBUG)&&console.log("vast-contentroll:",c,d||"")}function g(a){b(a,e.CONTROLLS)||(b(a,e.CONTROLLS,1),a.muteButton=document.createElement("a"), a.muteButton.className="vast-contentroll--btn-mute",a.muteButton.textContent=f(a,"mute-text")||"Mute",a.muteButton.style.position="relative",a.muteButton.style.padding="8px 16px",a.muteButton.style.backgroundColor="rgba(0,0,0,0.8)",a.muteButton.style.color="#e6e6e6",a.muteButton.style.fontFamily="arial",a.muteButton.style.fontSize="12px",a.muteButton.style.cursor="pointer",a.muteButton.onclick=function(){0===a.adsManager.getVolume()?(d(a,"unmute clicked"),a.adsManager.setVolume(1),this.textContent= - f(a,"mute-text")||"Mute"):(a.adsManager.setVolume(0),d(a,"mute clicked"),this.textContent=f(a,"unmute-text")||"Unmute")},a.appendChild(a.muteButton))}function l(a){k.unobserve(a);a=f(a,"on-empty");if("function"===typeof window[a])window[a]()}function m(a){var c=a.clientWidth,b=a.parentNode.clientWidth,e=b/c*a.clientHeight;b>c?d(a,"adapt size skiped"):(a.style.width=b+"px",a.style.height=e+"px",a.style.maxWidth="100%",d(a,"size adapted"))}var e={INIT:"init",LOADING:"loading",LOADED:"loaded",STARTED:"started", - CONTROLLS:"controlls",DEBUG:"debug",COLLAPSE:"collapse",COMPANION:"companion",RESPONSIVE:"responsive"},p=document.getElementsByClassName("vast-contentroll"),k=new IntersectionObserver(function(a){[].forEach.call(a,function(a){"undefined"!==typeof a.isIntersecting&&!1===a.isIntersecting?(a=a.target,b(a,e.STARTED)&&(a.adsManager.pause(),d(a,"pauseAd"))):(a=a.target,b(a,e.STARTED)?(a.adsManager.resume(),d(a,"resumeAd")):b(a,e.LOADING)?d(a,"yet loading"):(d(a,"load"),a.adsRequest.adTagUrl=f(a,"vast"), - a.adsLoader.requestAds(a.adsRequest),b(a,e.LOADING,1)))})},{threshold:0});[].forEach.call(p,function(a){b(a,e.INIT)||(b(a,e.RESPONSIVE)&&m(a),k.observe(a),a.adDisplayContainer=new google.ima.AdDisplayContainer(a),a.adDisplayContainer.initialize(),a.adsLoader=new google.ima.AdsLoader(a.adDisplayContainer),a.adsRequest=new google.ima.AdsRequest,a.adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,function(c){var h=document.createElement("video");h.muted=!0;h.autoplay= - !0;a.adsManager=c.getAdsManager(h);a.adsManager.addEventListener(google.ima.AdEvent.Type.LOADED,function(d){b(a,e.LOADED,1)});a.adsManager.addEventListener(google.ima.AdEvent.Type.STARTED,function(c){b(a,e.STARTED,1);g(a);if(b(a,e.COMPANION)){d(a,"get a list of companion ads");c=c.getAd();var f=new google.ima.CompanionAdSelectionSettings;f.resourceType=google.ima.CompanionAdSelectionSettings.ResourceType.STATIC;f.creativeType=google.ima.CompanionAdSelectionSettings.CreativeType.IMAGE;f.sizeCriteria= - google.ima.CompanionAdSelectionSettings.SizeCriteria.IGNORE;a.companionAds=c.getCompanionAds(a.clientWidth,a.clientHeight,f);d(a,"getted companion ads count: "+a.companionAds.length)}});a.adsManager.addEventListener(google.ima.AdEvent.Type.ALL_ADS_COMPLETED,function(c){d(a,"ALL_ADS_COMPLETED");a.muteButton&&a.removeChild(a.muteButton);k.unobserve(a);b(a,e.COMPANION)&&a.companionAds&&a.companionAds.length?(a.innerHTML=a.companionAds[0].getContent(),a.style.height="auto",d(a,"display companion")):b(a, - e.COLLAPSE)&&(a.style.height="0",d(a,"ads collapsed"));c=f(a,"on-complete");if("function"===typeof window[c])window[c]()});try{a.adsManager.init(a.clientWidth,a.clientHeight,google.ima.ViewMode.NORMAL),a.adsManager.start()}catch(n){d(a,"error or empty ad",n),l(a)}},!1),a.adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,function(b){d(a,"error or empty ad",b.getError());"undefined"!==typeof a.adsManager&&a.adsManager.destroy();l(a)},!1),b(a,e.INIT,1),b(a,e.LOADED,0),b(a,e.STARTED,0), - d(a,"init"))})};document.head.appendChild(g)})(); + f(a,"mute-text")||"Mute"):(a.adsManager.setVolume(0),d(a,"mute clicked"),this.textContent=f(a,"unmute-text")||"Unmute")},a.appendChild(a.muteButton))}function l(a){k.unobserve(a);a.style.height="0";a=f(a,"on-empty");if("function"===typeof window[a])window[a]()}function m(a){var c=a.clientWidth,b=a.parentNode.clientWidth,e=b/c*a.clientHeight;b>c?d(a,"adapt size skiped"):(a.style.width=b+"px",a.style.height=e+"px",a.style.maxWidth="100%",d(a,"size adapted"))}var e={INIT:"init",LOADING:"loading",LOADED:"loaded", + STARTED:"started",CONTROLLS:"controlls",DEBUG:"debug",COLLAPSE:"collapse",COMPANION:"companion",RESPONSIVE:"responsive"},p=document.getElementsByClassName("vast-contentroll"),k=new IntersectionObserver(function(a){[].forEach.call(a,function(a){"undefined"!==typeof a.isIntersecting&&!1===a.isIntersecting?(a=a.target,b(a,e.STARTED)&&(a.adsManager.pause(),d(a,"pauseAd"))):(a=a.target,b(a,e.STARTED)?(a.adsManager.resume(),d(a,"resumeAd")):b(a,e.LOADING)?d(a,"yet loading"):(d(a,"load"),a.adsRequest.adTagUrl= + f(a,"vast"),a.adsLoader.requestAds(a.adsRequest),b(a,e.LOADING,1)))})},{threshold:0});[].forEach.call(p,function(a){b(a,e.INIT)||(b(a,e.RESPONSIVE)&&m(a),k.observe(a),a.adDisplayContainer=new google.ima.AdDisplayContainer(a),a.adDisplayContainer.initialize(),a.adsLoader=new google.ima.AdsLoader(a.adDisplayContainer),a.adsRequest=new google.ima.AdsRequest,a.adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,function(c){var h=document.createElement("video");h.muted= + !0;h.autoplay=!0;a.adsManager=c.getAdsManager(h);a.adsManager.addEventListener(google.ima.AdEvent.Type.LOADED,function(d){b(a,e.LOADED,1)});a.adsManager.addEventListener(google.ima.AdEvent.Type.STARTED,function(c){b(a,e.STARTED,1);g(a);if(b(a,e.COMPANION)){d(a,"get a list of companion ads");c=c.getAd();var f=new google.ima.CompanionAdSelectionSettings;f.resourceType=google.ima.CompanionAdSelectionSettings.ResourceType.STATIC;f.creativeType=google.ima.CompanionAdSelectionSettings.CreativeType.IMAGE; + f.sizeCriteria=google.ima.CompanionAdSelectionSettings.SizeCriteria.IGNORE;a.companionAds=c.getCompanionAds(a.clientWidth,a.clientHeight,f);d(a,"getted companion ads count: "+a.companionAds.length)}});a.adsManager.addEventListener(google.ima.AdEvent.Type.ALL_ADS_COMPLETED,function(c){d(a,"ALL_ADS_COMPLETED");a.muteButton&&a.removeChild(a.muteButton);k.unobserve(a);b(a,e.COMPANION)&&a.companionAds&&a.companionAds.length?(a.innerHTML=a.companionAds[0].getContent(),a.style.height="auto",d(a,"display companion")): + b(a,e.COLLAPSE)&&(a.style.height="0",d(a,"ads collapsed"));c=f(a,"on-complete");if("function"===typeof window[c])window[c]()});try{a.adsManager.init(a.clientWidth,a.clientHeight,google.ima.ViewMode.NORMAL),a.adsManager.start()}catch(n){d(a,"error or empty ad",n),l(a)}},!1),a.adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,function(b){d(a,"error or empty ad",b.getError());"undefined"!==typeof a.adsManager&&a.adsManager.destroy();l(a)},!1),b(a,e.INIT,1),b(a,e.LOADED,0),b(a,e.STARTED, + 0),d(a,"init"))})};document.head.appendChild(g)})();