Skip to content

Commit

Permalink
fix(ads): Cleaned up styles for Ads, simplified method to resize Ads …
Browse files Browse the repository at this point in the history
…and added missing conditional to indicate their view mode
  • Loading branch information
rafa8626 committed Sep 8, 2018
1 parent a0b9bcb commit 618dfd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
3 changes: 0 additions & 3 deletions src/css/player.css
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,6 @@ video:-webkit-media-text-track-display {
.om-ads--active #om-ads {
z-index: 1;
}
.om-player[data-fullscreen='true'] #om-ads {
z-index: -1;
}
.om-player[data-fullscreen='true'].om-ads--active #om-ads {
z-index: 2147483645;
}
Expand Down
47 changes: 19 additions & 28 deletions src/js/media/ads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,31 +364,24 @@ class Ads {
* @memberof Ads
*/
public resizeAds(width?: number, height?: number): void {
let timeout;
if (timeout) {
window.cancelAnimationFrame(timeout);
}
if (this.adsManager) {
const target = this.element;
const mode = target.getAttribute('data-fullscreen') === 'true' ?
google.ima.ViewMode.FULLSCREEN : google.ima.ViewMode.NORMAL;

timeout = window.requestAnimationFrame(() => {
if (this.adsManager) {
const target = this.element;
if (width && height) {
const mode = target.getAttribute('data-fullscreen') === 'true' ?
google.ima.ViewMode.FULLSCREEN : google.ima.ViewMode.NORMAL;
this.adsManager.resize(
width,
height,
mode,
);
} else {
this.adsManager.resize(
target.offsetWidth,
target.offsetHeight,
google.ima.ViewMode.NORMAL,
);
}
let timeout;

if (timeout) {
window.cancelAnimationFrame(timeout);
}
});
timeout = window.requestAnimationFrame(() => {
this.adsManager.resize(
width && height ? width : target.offsetWidth,
width && height ? height : target.offsetHeight,
mode,
);
});
}
}

/**
Expand Down Expand Up @@ -514,9 +507,6 @@ class Ads {

const loadedEvent = addEvent('loadedmetadata');
this.element.dispatchEvent(loadedEvent);

const resizeEvent = addEvent('resize');
window.dispatchEvent(resizeEvent);
}
break;
case google.ima.AdEvent.Type.STARTED:
Expand All @@ -537,7 +527,7 @@ class Ads {
const timeEvent = addEvent('timeupdate');
this.element.dispatchEvent(timeEvent);
}
}, 250);
}, 300);
}
break;
case google.ima.AdEvent.Type.COMPLETE:
Expand Down Expand Up @@ -772,7 +762,8 @@ class Ads {
this.adsManager.init(
this.element.offsetWidth,
this.element.offsetHeight,
google.ima.ViewMode.NORMAL,
this.element.parentElement.getAttribute('data-fullscreen') === 'true' ?
google.ima.ViewMode.FULLSCREEN : google.ima.ViewMode.NORMAL,
);
this.adsManager.start();
const e = addEvent('play');
Expand Down

0 comments on commit 618dfd2

Please sign in to comment.