Skip to content
This repository has been archived by the owner on Nov 20, 2021. It is now read-only.

Commit

Permalink
Restore missing native events in fullscreen
Browse files Browse the repository at this point in the history
ended, timeupdate, seeking, seeked

Partially fixes #33
  • Loading branch information
fregante committed Jun 8, 2017
1 parent 27a2f96 commit 0444341
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
25 changes: 20 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ function pause(forceEvents) {
if (!player.hasAudio) {
dispatchEventAsync(video, 'pause');
}
if (video.ended) {

// Handle the 'ended' event only if it's not fullscreen
if (video.ended && !video.webkitDisplayingFullscreen) {
video[ಠevent] = true;
dispatchEventAsync(video, 'ended');
}
Expand Down Expand Up @@ -245,6 +247,12 @@ function addPlayer(video, hasAudio) {
}
}

function preventWithPropOrFullscreen(el) {
const isAllowed = el[ಠevent];
delete el[ಠevent];
return !el.webkitDisplayingFullscreen && !isAllowed;
}

function overloadAPI(video) {
const player = video[];
video[ಠplay] = video.play;
Expand All @@ -256,10 +264,17 @@ function overloadAPI(video) {
proxyProperty(video, 'playbackRate', player.driver, true);
proxyProperty(video, 'ended', player.driver);
proxyProperty(video, 'loop', player.driver, true);
preventEvent(video, 'seeking');
preventEvent(video, 'seeked');
preventEvent(video, 'timeupdate', ಠevent, false);
preventEvent(video, 'ended', ಠevent, false); // Prevent occasional native ended events

// IIV works by seeking 60 times per second.
// These events are now useless.
preventEvent(video, 'seeking', el => !el.webkitDisplayingFullscreen);
preventEvent(video, 'seeked', el => !el.webkitDisplayingFullscreen);

// Limit timeupdate events
preventEvent(video, 'timeupdate', preventWithPropOrFullscreen);

// Prevent occasional native ended events
preventEvent(video, 'ended', preventWithPropOrFullscreen);
}

export default function enableInlineVideo(video, opts = {}) {
Expand Down
7 changes: 3 additions & 4 deletions lib/prevent-event.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export default function preventEvent(element, eventName, toggleProperty, preventWithProperty) {
export default function preventEvent(element, eventName, test) {
function handler(e) {
if (Boolean(element[toggleProperty]) === Boolean(preventWithProperty)) {
if (!test || test(element, eventName)) {
e.stopImmediatePropagation();
// // console.log(eventName, 'prevented on', element);
}
delete element[toggleProperty];
}
element.addEventListener(eventName, handler, false);
element.addEventListener(eventName, handler);

// Return handler to allow to disable the prevention. Usage:
// const preventionHandler = preventEvent(el, 'click');
Expand Down

0 comments on commit 0444341

Please sign in to comment.