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

Commit

Permalink
2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jun 8, 2017
1 parent 0444341 commit 63cd77c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
34 changes: 24 additions & 10 deletions dist/iphone-inline-video.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! npm.im/iphone-inline-video 2.1.0 */
/*! npm.im/iphone-inline-video 2.2.0 */
var enableInlineVideo = (function () {
'use strict';

Expand Down Expand Up @@ -33,15 +33,14 @@ function frameIntervalometer(cb) {
return intervalometer(cb, requestAnimationFrame, cancelAnimationFrame);
}

function preventEvent(element, eventName, toggleProperty, preventWithProperty) {
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 Expand Up @@ -219,7 +218,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 @@ -315,6 +316,12 @@ function addPlayer(video, hasAudio) {
}
}

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

function overloadAPI(video) {
var player = video[];
video[ಠplay] = video.play;
Expand All @@ -326,10 +333,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', function (el) { return !el.webkitDisplayingFullscreen; });
preventEvent(video, 'seeked', function (el) { return !el.webkitDisplayingFullscreen; });

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

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

function enableInlineVideo(video, opts) {
Expand Down
4 changes: 2 additions & 2 deletions dist/iphone-inline-video.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iphone-inline-video",
"version": "2.1.0",
"version": "2.2.0",
"description": "Make videos playable inline on the iPhone (prevents automatic fullscreen)",
"license": "MIT",
"repository": "bfred-it/iphone-inline-video",
Expand Down

0 comments on commit 63cd77c

Please sign in to comment.