Removed logic related to starting the ad by clicking/ tapping the advertisement container. Ad is started by plyr play method.
This commit is contained in:
parent
d822f0c6bf
commit
3583165b30
@ -1,23 +1,5 @@
|
|||||||
import utils from '../utils';
|
import utils from '../utils';
|
||||||
|
|
||||||
// Events are different on various devices. We set the correct events, based on userAgent.
|
|
||||||
const getStartEvents = () => {
|
|
||||||
let events = ['click'];
|
|
||||||
|
|
||||||
// TODO: Detecting touch is tricky, we should look at other ways?
|
|
||||||
// For mobile users the start event will be one of
|
|
||||||
// touchstart, touchend and touchmove.
|
|
||||||
if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/Android/i)) {
|
|
||||||
events = [
|
|
||||||
'touchstart',
|
|
||||||
'touchend',
|
|
||||||
'touchmove',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return events;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Ads {
|
class Ads {
|
||||||
constructor(player) {
|
constructor(player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -41,7 +23,6 @@ class Ads {
|
|||||||
|
|
||||||
ready() {
|
ready() {
|
||||||
this.time = Date.now();
|
this.time = Date.now();
|
||||||
this.startEvents = getStartEvents();
|
|
||||||
this.adsContainer = null;
|
this.adsContainer = null;
|
||||||
this.adDisplayContainer = null;
|
this.adDisplayContainer = null;
|
||||||
this.adsManager = null;
|
this.adsManager = null;
|
||||||
@ -106,24 +87,6 @@ class Ads {
|
|||||||
// that will house the ads.
|
// that will house the ads.
|
||||||
this.adDisplayContainer = new google.ima.AdDisplayContainer(this.adsContainer);
|
this.adDisplayContainer = new google.ima.AdDisplayContainer(this.adsContainer);
|
||||||
|
|
||||||
const adsDisplayElement = this.adsContainer.firstChild;
|
|
||||||
|
|
||||||
// The AdDisplayContainer call from google IMA sets the style attribute
|
|
||||||
// by default. We remove the inline style and set it through the stylesheet.
|
|
||||||
adsDisplayElement.removeAttribute('style');
|
|
||||||
|
|
||||||
// Set class name on the adDisplayContainer element.
|
|
||||||
adsDisplayElement.setAttribute('class', this.player.config.classNames.ads);
|
|
||||||
|
|
||||||
// Play ads when clicked. Wait until the adsManager and adsLoader
|
|
||||||
// are both resolved.
|
|
||||||
Promise.all([
|
|
||||||
this.adsManagerPromise,
|
|
||||||
this.adsLoaderPromise,
|
|
||||||
]).then(() => {
|
|
||||||
this.setOnClickHandler(adsDisplayElement, this.play);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Request video ads to be pre-loaded.
|
// Request video ads to be pre-loaded.
|
||||||
this.requestAds();
|
this.requestAds();
|
||||||
}
|
}
|
||||||
@ -462,7 +425,6 @@ class Ads {
|
|||||||
|
|
||||||
// Hide our ad container.
|
// Hide our ad container.
|
||||||
this.adsContainer.style.display = 'none';
|
this.adsContainer.style.display = 'none';
|
||||||
this.adsContainer.style.zIndex = '1';
|
|
||||||
|
|
||||||
// Ad is stopped.
|
// Ad is stopped.
|
||||||
this.playing = false;
|
this.playing = false;
|
||||||
@ -481,7 +443,6 @@ class Ads {
|
|||||||
|
|
||||||
// Show our ad container.
|
// Show our ad container.
|
||||||
this.adsContainer.style.display = 'block';
|
this.adsContainer.style.display = 'block';
|
||||||
this.adsContainer.style.zIndex = '3';
|
|
||||||
|
|
||||||
// Ad is playing.
|
// Ad is playing.
|
||||||
this.playing = true;
|
this.playing = true;
|
||||||
@ -546,27 +507,6 @@ class Ads {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set start event listener on a DOM element and triggers the
|
|
||||||
* callback when clicked.
|
|
||||||
* @param {element} element - The element on which to set the listener
|
|
||||||
* @param {function} callback - The callback which will be invoked once triggered.
|
|
||||||
*/
|
|
||||||
setOnClickHandler(element, callback) {
|
|
||||||
for (let i = 0; i < this.startEvents.length; i += 1) {
|
|
||||||
const startEvent = this.startEvents[i];
|
|
||||||
element.addEventListener(
|
|
||||||
startEvent,
|
|
||||||
event => {
|
|
||||||
if ((event.type === 'touchend' && startEvent === 'touchend') || event.type === 'click') {
|
|
||||||
callback.call(this);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ once: true },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add event listeners
|
* Add event listeners
|
||||||
* @param {string} event - Event type
|
* @param {string} event - Event type
|
||||||
|
@ -3,13 +3,14 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
.plyr__ads {
|
.plyr__ads {
|
||||||
|
display: none; // Hide initially.
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
left: 0;
|
left: 0;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
top: 0;
|
top: 0;
|
||||||
z-index: 1;
|
z-index: 3; // Above the controls.
|
||||||
|
|
||||||
video {
|
video {
|
||||||
left: 0;
|
left: 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user