Linting, housekeeping, duration fix (fixes #1074)

This commit is contained in:
Sam Potts 2018-06-29 00:21:22 +10:00
parent 4f5152f526
commit c99607c85a
26 changed files with 105 additions and 109 deletions

View File

@ -5,7 +5,10 @@
"browser": true, "browser": true,
"es6": true "es6": true
}, },
"globals": { "Plyr": false, "jQuery": false }, "globals": {
"Plyr": false,
"jQuery": false
},
"rules": { "rules": {
"no-const-assign": 1, "no-const-assign": 1,
"no-shadow": 0, "no-shadow": 0,
@ -22,17 +25,7 @@
"one-var": [2, "never"], "one-var": [2, "never"],
"comma-dangle": [2, "always-multiline"], "comma-dangle": [2, "always-multiline"],
"spaced-comment": [2, "always"], "spaced-comment": [2, "always"],
"no-restricted-globals": [ "no-restricted-globals": 2,
"error",
{
"name": "event",
"message": "Use local parameter instead."
},
{
"name": "error",
"message": "Use local parameter instead."
}
],
"no-param-reassign": [2, { "props": false }] "no-param-reassign": [2, { "props": false }]
}, },
"parserOptions": { "parserOptions": {

3
.gitignore vendored
View File

@ -6,6 +6,5 @@ aws.json
index-*.html index-*.html
npm-debug.log npm-debug.log
*.webm *.webm
/package-lock.json package-lock.json
.idea/ .idea/

View File

@ -2,3 +2,10 @@ demo
.github .github
.vscode .vscode
*.code-workspace *.code-workspace
aws.json
bundles.json
yarn.lock
package-lock.json
*.mp4
*.webm
!dist/blank.mp4

View File

@ -1,7 +1,6 @@
{ {
"useTabs": false, "useTabs": false,
"tabWidth": 4, "tabWidth": 4,
"printWidth": 120,
"singleQuote": true, "singleQuote": true,
"trailingComma": "all" "trailingComma": "all"
} }

View File

@ -1,33 +0,0 @@
{
"name": "plyr",
"description": "A simple HTML5 media player using custom controls",
"homepage": "http://plyr.io",
"keywords": [
"Audio",
"Video",
"HTML5 Audio",
"HTML5 Video"
],
"authors": [
"Sam Potts <sam@potts.es>"
],
"dependencies": {},
"main": [
"dist/plyr.css",
"dist/plyr.js",
"dist/plyr.svg",
"src/less/plyr.less",
"src/scss/plyr.scss",
"src/js/plyr.js"
],
"ignore": [
"node_modules",
"bower_components",
".gitignore"
],
"repository": {
"type": "git",
"url": "git://github.com/sampotts/plyr.git"
},
"license": "MIT"
}

12
demo/dist/demo.js vendored
View File

@ -1874,7 +1874,7 @@ typeof navigator === "object" && (function () {
// webpack (using a build step causes webpack #1617). Grunt verifies that // webpack (using a build step causes webpack #1617). Grunt verifies that
// this value matches package.json during build. // this value matches package.json during build.
// See: https://github.com/getsentry/raven-js/issues/465 // See: https://github.com/getsentry/raven-js/issues/465
VERSION: '3.26.2', VERSION: '3.26.3',
debug: false, debug: false,
@ -2351,7 +2351,9 @@ typeof navigator === "object" && (function () {
return; return;
} }
if (this._globalOptions.stacktrace || (options && options.stacktrace)) { // Always attempt to get stacktrace if message is empty.
// It's the only way to provide any helpful information to the user.
if (this._globalOptions.stacktrace || options.stacktrace || data.message === '') {
// fingerprint on msg, not stack trace (legacy behavior, could be revisited) // fingerprint on msg, not stack trace (legacy behavior, could be revisited)
data.fingerprint = data.fingerprint == null ? msg : data.fingerprint; data.fingerprint = data.fingerprint == null ? msg : data.fingerprint;
@ -3508,6 +3510,11 @@ typeof navigator === "object" && (function () {
options options
); );
var ex = data.exception.values[0];
if (ex.type == null && ex.value === '') {
ex.value = 'Unrecoverable error caught';
}
// Move mechanism from options to exception interface // Move mechanism from options to exception interface
// We do this, as requiring user to pass `{exception:{mechanism:{ ... }}}` would be // We do this, as requiring user to pass `{exception:{mechanism:{ ... }}}` would be
// too much // too much
@ -4130,6 +4137,7 @@ typeof navigator === "object" && (function () {
tooltips: { tooltips: {
controls: true controls: true
}, },
clickToPlay: false,
/* controls: [ /* controls: [
'play-large', 'play-large',
'restart', 'restart',

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -57,6 +57,7 @@ import Raven from 'raven-js';
tooltips: { tooltips: {
controls: true, controls: true,
}, },
clickToPlay: false,
/* controls: [ /* controls: [
'play-large', 'play-large',
'restart', 'restart',

17
dist/plyr.js vendored
View File

@ -1483,7 +1483,7 @@ typeof navigator === "object" && (function (global, factory) {
} }
if ('class' in attributes) { if ('class' in attributes) {
if (attributes.class.includes(this.config.classNames.control)) { if (!attributes.class.includes(this.config.classNames.control)) {
attributes.class += ' ' + this.config.classNames.control; attributes.class += ' ' + this.config.classNames.control;
} }
} else { } else {
@ -3009,8 +3009,10 @@ typeof navigator === "object" && (function (global, factory) {
return; return;
} }
// Toggle state // Toggle button if it's enabled
if (this.elements.buttons.captions) {
this.elements.buttons.captions.pressed = active; this.elements.buttons.captions.pressed = active;
}
// Add class hook // Add class hook
toggleClass(this.elements.container, activeClass, active); toggleClass(this.elements.container, activeClass, active);
@ -4605,9 +4607,11 @@ typeof navigator === "object" && (function (global, factory) {
}; };
// Play/pause toggle // Play/pause toggle
if (this.player.elements.buttons.play) {
Array.from(this.player.elements.buttons.play).forEach(function (button) { Array.from(this.player.elements.buttons.play).forEach(function (button) {
bind(button, 'click', _this4.player.togglePlay, 'play'); bind(button, 'click', _this4.player.togglePlay, 'play');
}); });
}
// Pause // Pause
bind(this.player.elements.buttons.restart, 'click', this.player.restart, 'restart'); bind(this.player.elements.buttons.restart, 'click', this.player.restart, 'restart');
@ -6777,7 +6781,7 @@ typeof navigator === "object" && (function (global, factory) {
var params = { var params = {
AV_PUBLISHERID: '58c25bb0073ef448b1087ad6', AV_PUBLISHERID: '58c25bb0073ef448b1087ad6',
AV_CHANNELID: '5a0458dc28a06145e4519d21', AV_CHANNELID: '5a0458dc28a06145e4519d21',
AV_URL: location.hostname, AV_URL: window.location.hostname,
cb: Date.now(), cb: Date.now(),
AV_WIDTH: 640, AV_WIDTH: 640,
AV_HEIGHT: 480, AV_HEIGHT: 480,
@ -7421,6 +7425,7 @@ typeof navigator === "object" && (function (global, factory) {
value: function on$$1(event, callback) { value: function on$$1(event, callback) {
on.call(this, this.elements.container, event, callback); on.call(this, this.elements.container, event, callback);
} }
/** /**
* Add event listeners once * Add event listeners once
* @param {string} event - Event type * @param {string} event - Event type
@ -7432,6 +7437,7 @@ typeof navigator === "object" && (function (global, factory) {
value: function once$$1(event, callback) { value: function once$$1(event, callback) {
once.call(this, this.elements.container, event, callback); once.call(this, this.elements.container, event, callback);
} }
/** /**
* Remove event listeners * Remove event listeners
* @param {string} event - Event type * @param {string} event - Event type
@ -7707,8 +7713,9 @@ typeof navigator === "object" && (function (global, factory) {
// Faux duration set via config // Faux duration set via config
var fauxDuration = parseFloat(this.config.duration); var fauxDuration = parseFloat(this.config.duration);
// Media duration can be NaN before the media has loaded // Media duration can be NaN or Infinity before the media has loaded
var duration = (this.media || {}).duration || 0; var realDuration = (this.media || {}).duration;
var duration = !is.number(realDuration) || realDuration === Infinity ? 0 : realDuration;
// If config duration is funky, use regular duration // If config duration is funky, use regular duration
return fauxDuration || duration; return fauxDuration || duration;

2
dist/plyr.js.map vendored

File diff suppressed because one or more lines are too long

2
dist/plyr.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6869,7 +6869,7 @@ typeof navigator === "object" && (function (global, factory) {
} }
if ('class' in attributes) { if ('class' in attributes) {
if (attributes.class.includes(this.config.classNames.control)) { if (!attributes.class.includes(this.config.classNames.control)) {
attributes.class += ' ' + this.config.classNames.control; attributes.class += ' ' + this.config.classNames.control;
} }
} else { } else {
@ -8395,8 +8395,10 @@ typeof navigator === "object" && (function (global, factory) {
return; return;
} }
// Toggle state // Toggle button if it's enabled
if (this.elements.buttons.captions) {
this.elements.buttons.captions.pressed = active; this.elements.buttons.captions.pressed = active;
}
// Add class hook // Add class hook
toggleClass(this.elements.container, activeClass, active); toggleClass(this.elements.container, activeClass, active);
@ -9991,9 +9993,11 @@ typeof navigator === "object" && (function (global, factory) {
}; };
// Play/pause toggle // Play/pause toggle
if (this.player.elements.buttons.play) {
Array.from(this.player.elements.buttons.play).forEach(function (button) { Array.from(this.player.elements.buttons.play).forEach(function (button) {
bind(button, 'click', _this4.player.togglePlay, 'play'); bind(button, 'click', _this4.player.togglePlay, 'play');
}); });
}
// Pause // Pause
bind(this.player.elements.buttons.restart, 'click', this.player.restart, 'restart'); bind(this.player.elements.buttons.restart, 'click', this.player.restart, 'restart');
@ -12149,7 +12153,7 @@ typeof navigator === "object" && (function (global, factory) {
}, { }, {
key: 'enabled', key: 'enabled',
get: function get() { get: function get() {
return this.player.isVideo && this.player.config.ads.enabled && !is$1.empty(this.publisherId); return this.player.isHTML5 && this.player.isVideo && this.player.config.ads.enabled && !is$1.empty(this.publisherId);
} }
}, { }, {
key: 'tagUrl', key: 'tagUrl',
@ -12801,6 +12805,7 @@ typeof navigator === "object" && (function (global, factory) {
value: function on$$1(event, callback) { value: function on$$1(event, callback) {
on.call(this, this.elements.container, event, callback); on.call(this, this.elements.container, event, callback);
} }
/** /**
* Add event listeners once * Add event listeners once
* @param {string} event - Event type * @param {string} event - Event type
@ -12812,6 +12817,7 @@ typeof navigator === "object" && (function (global, factory) {
value: function once$$1(event, callback) { value: function once$$1(event, callback) {
once.call(this, this.elements.container, event, callback); once.call(this, this.elements.container, event, callback);
} }
/** /**
* Remove event listeners * Remove event listeners
* @param {string} event - Event type * @param {string} event - Event type

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -17,10 +17,12 @@ export default class Console {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
return this.enabled ? Function.prototype.bind.call(console.log, console) : noop; return this.enabled ? Function.prototype.bind.call(console.log, console) : noop;
} }
get warn() { get warn() {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
return this.enabled ? Function.prototype.bind.call(console.warn, console) : noop; return this.enabled ? Function.prototype.bind.call(console.warn, console) : noop;
} }
get error() { get error() {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
return this.enabled ? Function.prototype.bind.call(console.error, console) : noop; return this.enabled ? Function.prototype.bind.call(console.error, console) : noop;

2
src/js/controls.js vendored
View File

@ -16,11 +16,11 @@ import {
getElement, getElement,
getElements, getElements,
hasClass, hasClass,
matches,
removeElement, removeElement,
setAttributes, setAttributes,
toggleClass, toggleClass,
toggleHidden, toggleHidden,
matches,
} from './utils/elements'; } from './utils/elements';
import { off, on } from './utils/events'; import { off, on } from './utils/events';
import is from './utils/is'; import is from './utils/is';

View File

@ -669,8 +669,7 @@ class Listeners {
const inverted = event.webkitDirectionInvertedFromDevice; const inverted = event.webkitDirectionInvertedFromDevice;
// Get delta from event. Invert if `inverted` is true // Get delta from event. Invert if `inverted` is true
const [x, y] = [event.deltaX, -event.deltaY] const [x, y] = [event.deltaX, -event.deltaY].map(value => (inverted ? -value : value));
.map(value => inverted ? -value : value);
// Using the biggest delta, normalize to 1 or -1 (or 0 if no delta) // Using the biggest delta, normalize to 1 or -1 (or 0 if no delta)
const direction = Math.sign(Math.abs(x) > Math.abs(y) ? x : y); const direction = Math.sign(Math.abs(x) > Math.abs(y) ? x : y);

View File

@ -7,12 +7,12 @@
/* global google */ /* global google */
import i18n from '../i18n'; import i18n from '../i18n';
import { createElement } from './../utils/elements'; import { createElement } from '../utils/elements';
import { triggerEvent } from './../utils/events'; import { triggerEvent } from '../utils/events';
import is from './../utils/is'; import is from '../utils/is';
import loadScript from './../utils/loadScript'; import loadScript from '../utils/loadScript';
import { formatTime } from './../utils/time'; import { formatTime } from '../utils/time';
import { buildUrlParams } from './../utils/urls'; import { buildUrlParams } from '../utils/urls';
class Ads { class Ads {
/** /**
@ -100,7 +100,7 @@ class Ads {
const params = { const params = {
AV_PUBLISHERID: '58c25bb0073ef448b1087ad6', AV_PUBLISHERID: '58c25bb0073ef448b1087ad6',
AV_CHANNELID: '5a0458dc28a06145e4519d21', AV_CHANNELID: '5a0458dc28a06145e4519d21',
AV_URL: location.hostname, AV_URL: window.location.hostname,
cb: Date.now(), cb: Date.now(),
AV_WIDTH: 640, AV_WIDTH: 640,
AV_HEIGHT: 480, AV_HEIGHT: 480,

View File

@ -2,16 +2,16 @@
// Vimeo plugin // Vimeo plugin
// ========================================================================== // ==========================================================================
import captions from './../captions'; import captions from '../captions';
import controls from './../controls'; import controls from '../controls';
import ui from './../ui'; import ui from '../ui';
import { createElement, replaceElement, toggleClass } from './../utils/elements'; import { createElement, replaceElement, toggleClass } from '../utils/elements';
import { triggerEvent } from './../utils/events'; import { triggerEvent } from '../utils/events';
import fetch from './../utils/fetch'; import fetch from '../utils/fetch';
import is from './../utils/is'; import is from '../utils/is';
import loadScript from './../utils/loadScript'; import loadScript from '../utils/loadScript';
import { format, stripHTML } from './../utils/strings'; import { format, stripHTML } from '../utils/strings';
import { buildUrlParams } from './../utils/urls'; import { buildUrlParams } from '../utils/urls';
// Parse Vimeo ID from URL // Parse Vimeo ID from URL
function parseId(url) { function parseId(url) {

View File

@ -2,16 +2,16 @@
// YouTube plugin // YouTube plugin
// ========================================================================== // ==========================================================================
import controls from './../controls'; import controls from '../controls';
import ui from './../ui'; import ui from '../ui';
import { dedupe } from './../utils/arrays'; import { dedupe } from '../utils/arrays';
import { createElement, replaceElement, toggleClass } from './../utils/elements'; import { createElement, replaceElement, toggleClass } from '../utils/elements';
import { triggerEvent } from './../utils/events'; import { triggerEvent } from '../utils/events';
import fetch from './../utils/fetch'; import fetch from '../utils/fetch';
import is from './../utils/is'; import is from '../utils/is';
import loadImage from './../utils/loadImage'; import loadImage from '../utils/loadImage';
import loadScript from './../utils/loadScript'; import loadScript from '../utils/loadScript';
import { format, generateId } from './../utils/strings'; import { format, generateId } from '../utils/strings';
// Parse YouTube ID from URL // Parse YouTube ID from URL
function parseId(url) { function parseId(url) {

View File

@ -310,18 +310,23 @@ class Plyr {
get isHTML5() { get isHTML5() {
return Boolean(this.provider === providers.html5); return Boolean(this.provider === providers.html5);
} }
get isEmbed() { get isEmbed() {
return Boolean(this.isYouTube || this.isVimeo); return Boolean(this.isYouTube || this.isVimeo);
} }
get isYouTube() { get isYouTube() {
return Boolean(this.provider === providers.youtube); return Boolean(this.provider === providers.youtube);
} }
get isVimeo() { get isVimeo() {
return Boolean(this.provider === providers.vimeo); return Boolean(this.provider === providers.vimeo);
} }
get isVideo() { get isVideo() {
return Boolean(this.type === types.video); return Boolean(this.type === types.video);
} }
get isAudio() { get isAudio() {
return Boolean(this.type === types.audio); return Boolean(this.type === types.audio);
} }
@ -489,8 +494,9 @@ class Plyr {
// Faux duration set via config // Faux duration set via config
const fauxDuration = parseFloat(this.config.duration); const fauxDuration = parseFloat(this.config.duration);
// Media duration can be NaN before the media has loaded // Media duration can be NaN or Infinity before the media has loaded
const duration = (this.media || {}).duration || 0; const realDuration = (this.media || {}).duration;
const duration = !is.number(realDuration) || realDuration === Infinity ? 0 : realDuration;
// If config duration is funky, use regular duration // If config duration is funky, use regular duration
return fauxDuration || duration; return fauxDuration || duration;
@ -944,6 +950,7 @@ class Plyr {
on(event, callback) { on(event, callback) {
on.call(this, this.elements.container, event, callback); on.call(this, this.elements.container, event, callback);
} }
/** /**
* Add event listeners once * Add event listeners once
* @param {string} event - Event type * @param {string} event - Event type
@ -952,6 +959,7 @@ class Plyr {
once(event, callback) { once(event, callback) {
once.call(this, this.elements.container, event, callback); once.call(this, this.elements.container, event, callback);
} }
/** /**
* Remove event listeners * Remove event listeners
* @param {string} event - Event type * @param {string} event - Event type

View File

@ -2,7 +2,7 @@
// Sprite loader // Sprite loader
// ========================================================================== // ==========================================================================
import Storage from './../storage'; import Storage from '../storage';
import fetch from './fetch'; import fetch from './fetch';
import is from './is'; import is from './is';