From 99ac8d4c5267e465d31b3045315a6865740e9c16 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Wed, 13 Jun 2018 22:07:32 +0200 Subject: [PATCH 1/2] Remove array-newline rule --- .eslintrc.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c8dc1b74..1fc24ce3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -32,9 +32,7 @@ "message": "Use local parameter instead." } ], - "no-param-reassign": [2, { "props": false }], - "array-bracket-newline": [2, { "minItems": 2 }], - "array-element-newline": [2, { "minItems": 2 }] + "no-param-reassign": [2, { "props": false }] }, "parserOptions": { "sourceType": "module" From 6bff6b317d6adcd9f94c8d4d8ee225d39f784e0f Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Wed, 13 Jun 2018 22:18:57 +0200 Subject: [PATCH 2/2] Remove line breaks in arrays --- src/js/captions.js | 12 ++++------ src/js/config/defaults.js | 16 ++----------- src/js/controls.js | 38 ++++++------------------------- src/js/fullscreen.js | 6 +---- src/js/i18n.js | 5 +---- src/js/listeners.js | 47 +++++---------------------------------- src/js/plugins/vimeo.js | 9 +++----- src/js/plugins/youtube.js | 5 +---- src/js/plyr.js | 12 ++-------- src/js/ui.js | 5 +---- src/js/utils/elements.js | 5 +---- src/js/utils/urls.js | 5 +---- 12 files changed, 30 insertions(+), 135 deletions(-) diff --git a/src/js/captions.js b/src/js/captions.js index 6682d6f0..5f78e636 100644 --- a/src/js/captions.js +++ b/src/js/captions.js @@ -48,10 +48,7 @@ const captions = { const src = track.getAttribute('src'); const url = parseUrl(src); - if (url !== null && url.hostname !== window.location.href.hostname && [ - 'http:', - 'https:', - ].includes(url.protocol)) { + if (url !== null && url.hostname !== window.location.href.hostname && ['http:', 'https:'].includes(url.protocol)) { fetch(src, 'blob') .then(blob => { track.setAttribute('src', window.URL.createObjectURL(blob)); @@ -202,10 +199,9 @@ const captions = { const tracks = Array.from((this.media || {}).textTracks || []); // For HTML5, use cache instead of current tracks when it exists (if captions.update is false) // Filter out removed tracks and tracks that aren't captions/subtitles (for example metadata) - return tracks.filter(track => !this.isHTML5 || update || this.captions.meta.has(track)).filter(track => [ - 'captions', - 'subtitles', - ].includes(track.kind)); + return tracks + .filter(track => !this.isHTML5 || update || this.captions.meta.has(track)) + .filter(track => ['captions', 'subtitles'].includes(track.kind)); }, // Get the current track for the current language diff --git a/src/js/config/defaults.js b/src/js/config/defaults.js index 1789b026..34fb5519 100644 --- a/src/js/config/defaults.js +++ b/src/js/config/defaults.js @@ -89,15 +89,7 @@ const defaults = { // Speed default and options to display speed: { selected: 1, - options: [ - 0.5, - 0.75, - 1, - 1.25, - 1.5, - 1.75, - 2, - ], + options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2], }, // Keyboard shortcut settings @@ -151,11 +143,7 @@ const defaults = { 'airplay', 'fullscreen', ], - settings: [ - 'captions', - 'quality', - 'speed', - ], + settings: ['captions', 'quality', 'speed'], // Localisation i18n: { diff --git a/src/js/controls.js b/src/js/controls.js index 0e28c222..39ddb79c 100644 --- a/src/js/controls.js +++ b/src/js/controls.js @@ -580,10 +580,7 @@ const controls = { // Show/hide the tooltip // If the event is a moues in/out and percentage is inside bounds - if (is.event(event) && [ - 'mouseenter', - 'mouseleave', - ].includes(event.type)) { + if (is.event(event) && ['mouseenter', 'mouseleave'].includes(event.type)) { toggle(event.type === 'mouseenter'); } }, @@ -888,15 +885,7 @@ const controls = { if (is.array(options)) { this.options.speed = options; } else if (this.isHTML5 || this.isVimeo) { - this.options.speed = [ - 0.5, - 0.75, - 1, - 1.25, - 1.5, - 1.75, - 2, - ]; + this.options.speed = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2]; } // Set options if passed and filter based on config @@ -1054,10 +1043,7 @@ const controls = { // Restore auto height/width const restore = e => { // We're only bothered about height and width on the container - if (e.target !== container || ![ - 'width', - 'height', - ].includes(e.propertyName)) { + if (e.target !== container || !['width', 'height'].includes(e.propertyName)) { return; } @@ -1404,10 +1390,7 @@ const controls = { const replace = input => { let result = input; - Object.entries(props).forEach(([ - key, - value, - ]) => { + Object.entries(props).forEach(([key, value]) => { result = replaceAll(result, `{${key}}`, value); }); @@ -1455,16 +1438,9 @@ const controls = { // Setup tooltips if (this.config.tooltips.controls) { - const labels = getElements.call( - this, - [ - this.config.selectors.controls.wrapper, - ' ', - this.config.selectors.labels, - ' .', - this.config.classNames.hidden, - ].join(''), - ); + const { classNames, selectors } = this.config; + const selector = `${selectors.controls.wrapper} ${selectors.labels} .${classNames.hidden}`; + const labels = getElements.call(this, selector); Array.from(labels).forEach(label => { toggleClass(label, this.config.classNames.hidden, false); diff --git a/src/js/fullscreen.js b/src/js/fullscreen.js index 998dc613..a8d8b7e5 100644 --- a/src/js/fullscreen.js +++ b/src/js/fullscreen.js @@ -96,11 +96,7 @@ class Fullscreen { // Check for fullscreen support by vendor prefix let value = ''; - const prefixes = [ - 'webkit', - 'moz', - 'ms', - ]; + const prefixes = ['webkit', 'moz', 'ms']; prefixes.some(pre => { if (is.function(document[`${pre}ExitFullscreen`]) || is.function(document[`${pre}CancelFullScreen`])) { diff --git a/src/js/i18n.js b/src/js/i18n.js index f1108dae..5b0ebbab 100644 --- a/src/js/i18n.js +++ b/src/js/i18n.js @@ -23,10 +23,7 @@ const i18n = { '{title}': config.title, }; - Object.entries(replace).forEach(([ - key, - value, - ]) => { + Object.entries(replace).forEach(([key, value]) => { string = replaceAll(string, key, value); }); diff --git a/src/js/listeners.js b/src/js/listeners.js index 283bd4a2..3e691fe7 100644 --- a/src/js/listeners.js +++ b/src/js/listeners.js @@ -46,29 +46,7 @@ class Listeners { // Reset on keyup if (pressed) { // Which keycodes should we prevent default - const preventDefault = [ - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 56, - 57, - 32, - 75, - 38, - 40, - 77, - 39, - 37, - 70, - 67, - 73, - 76, - 79, - ]; + const preventDefault = [32, 37, 38, 39, 40, 48, 49, 50, 51, 52, 53, 54, 56, 57, 67, 70, 73, 75, 76, 77, 79]; // Check focused element // and if the focused element is not editable (e.g. text input) @@ -249,11 +227,7 @@ class Listeners { } // Show, then hide after a timeout unless another control event occurs - const show = [ - 'touchstart', - 'touchmove', - 'mousemove', - ].includes(event.type); + const show = ['touchstart', 'touchmove', 'mousemove'].includes(event.type); let delay = 0; @@ -407,10 +381,8 @@ class Listeners { // Proxy events to container // Bubble up key events for Edge - on.call(this.player, this.player.media, this.player.config.events.concat([ - 'keyup', - 'keydown', - ]).join(' '), event => { + const proxyEvents = this.player.config.events.concat(['keyup', 'keydown']).join(' '); + on.call(this.player, this.player.media, proxyEvents, event => { let {detail = {}} = event; // Get error details from media @@ -572,11 +544,7 @@ class Listeners { const play = seek.hasAttribute('play-on-seeked'); // Done seeking - const done = [ - 'mouseup', - 'touchend', - 'keyup', - ].includes(event.type); + const done = ['mouseup', 'touchend', 'keyup'].includes(event.type); // If we're done seeking and it was playing, resume playback if (play && done) { @@ -651,10 +619,7 @@ class Listeners { // Update controls.pressed state (used for ui.toggleControls to avoid hiding when interacting) bind(this.player.elements.controls, 'mousedown mouseup touchstart touchend touchcancel', event => { - this.player.elements.controls.pressed = [ - 'mousedown', - 'touchstart', - ].includes(event.type); + this.player.elements.controls.pressed = ['mousedown', 'touchstart'].includes(event.type); }); // Focus in/out on controls diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js index c8c09b05..312d53cf 100644 --- a/src/js/plugins/vimeo.js +++ b/src/js/plugins/vimeo.js @@ -70,8 +70,8 @@ const vimeo = { // Set aspect ratio // For Vimeo we have an extra 300% height
to hide the standard controls and UI setAspectRatio(input) { - const ratio = is.string(input) ? input.split(':') : this.config.ratio.split(':'); - const padding = 100 / ratio[0] * ratio[1]; + const [x, y] = (is.string(input) ? input : this.config.ratio).split(':'); + const padding = 100 / x * y; this.elements.wrapper.style.paddingBottom = `${padding}%`; if (this.supported.ui) { @@ -294,10 +294,7 @@ const vimeo = { }); // Set aspect ratio based on video size - Promise.all([ - player.embed.getVideoWidth(), - player.embed.getVideoHeight(), - ]).then(dimensions => { + Promise.all([player.embed.getVideoWidth(), player.embed.getVideoHeight()]).then(dimensions => { const ratio = getAspectRatio(dimensions[0], dimensions[1]); vimeo.setAspectRatio.call(this, ratio); }); diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js index 8a16726e..a1e52b48 100644 --- a/src/js/plugins/youtube.js +++ b/src/js/plugins/youtube.js @@ -408,10 +408,7 @@ const youtube = { // Reset timer clearInterval(player.timers.playing); - const seeked = player.media.seeking && [ - 1, - 2, - ].includes(event.data); + const seeked = player.media.seeking && [1, 2].includes(event.data); if (seeked) { // Unset seeking and fire seeked event diff --git a/src/js/plyr.js b/src/js/plyr.js index 543291e7..20f97974 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -172,10 +172,7 @@ class Plyr { // Get attributes from URL and set config if (url.searchParams.length) { - const truthy = [ - '1', - 'true', - ]; + const truthy = ['1', 'true']; if (truthy.includes(url.searchParams.get('autoplay'))) { this.config.autoplay = true; @@ -682,12 +679,7 @@ class Plyr { return; } - let quality = ([ - !is.empty(input) && Number(input), - this.storage.get('quality'), - config.selected, - config.default, - ]).find(is.number); + let quality = [!is.empty(input) && Number(input), this.storage.get('quality'), config.selected, config.default].find(is.number); if (!options.includes(quality)) { const value = closest(options, quality); diff --git a/src/js/ui.js b/src/js/ui.js index d3d86124..285739a7 100644 --- a/src/js/ui.js +++ b/src/js/ui.js @@ -212,10 +212,7 @@ const ui = { // Check if media is loading checkLoading(event) { - this.loading = [ - 'stalled', - 'waiting', - ].includes(event.type); + this.loading = ['stalled', 'waiting'].includes(event.type); // Clear timer clearTimeout(this.timers.loading); diff --git a/src/js/utils/elements.js b/src/js/utils/elements.js index 55866367..39b944d2 100644 --- a/src/js/utils/elements.js +++ b/src/js/utils/elements.js @@ -42,10 +42,7 @@ export function setAttributes(element, attributes) { return; } - Object.entries(attributes).forEach(([ - key, - value, - ]) => { + Object.entries(attributes).forEach(([key, value]) => { element.setAttribute(key, value); }); } diff --git a/src/js/utils/urls.js b/src/js/utils/urls.js index 89bd77ff..3ebe622e 100644 --- a/src/js/utils/urls.js +++ b/src/js/utils/urls.js @@ -30,10 +30,7 @@ export function buildUrlParams(input) { const params = new URLSearchParams(); if (is.object(input)) { - Object.entries(input).forEach(([ - key, - value, - ]) => { + Object.entries(input).forEach(([key, value]) => { params.set(key, value); }); }