mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Migrate some easy components to ES6
This commit is contained in:
parent
37ebb772e8
commit
f3b5c804a3
5 changed files with 256 additions and 267 deletions
22
package.json
22
package.json
|
@ -70,11 +70,23 @@
|
||||||
"whatwg-fetch": "^3.0.0"
|
"whatwg-fetch": "^3.0.0"
|
||||||
},
|
},
|
||||||
"babel": {
|
"babel": {
|
||||||
"presets": ["@babel/preset-env"],
|
"presets": [
|
||||||
"overrides": [{
|
"@babel/preset-env"
|
||||||
"test": ["src/components/cardbuilder/cardBuilder.js"],
|
],
|
||||||
"plugins": ["@babel/plugin-transform-modules-amd"]
|
"overrides": [
|
||||||
}]
|
{
|
||||||
|
"test": [
|
||||||
|
"src/components/cardbuilder/cardBuilder.js",
|
||||||
|
"src/components/filedownloader.js",
|
||||||
|
"src/components/filesystem.js",
|
||||||
|
"src/components/input/keyboardnavigation.js",
|
||||||
|
"src/components/sanatizefilename.js"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"@babel/plugin-transform-modules-amd"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 2 Firefox versions",
|
"last 2 Firefox versions",
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
define(['multi-download'], function (multiDownload) {
|
import multiDownload from "multi-download"
|
||||||
'use strict';
|
|
||||||
|
|
||||||
return {
|
export function download(items) {
|
||||||
download: function (items) {
|
|
||||||
|
|
||||||
if (window.NativeShell) {
|
if (window.NativeShell) {
|
||||||
items.map(function (item) {
|
items.map(function (item) {
|
||||||
|
@ -14,5 +12,3 @@ define(['multi-download'], function (multiDownload) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
define([], function () {
|
export function fileExists(path) {
|
||||||
'use strict';
|
|
||||||
|
|
||||||
return {
|
|
||||||
fileExists: function (path) {
|
|
||||||
if (window.NativeShell && window.NativeShell.FileSystem) {
|
if (window.NativeShell && window.NativeShell.FileSystem) {
|
||||||
return window.NativeShell.FileSystem.fileExists(path);
|
return window.NativeShell.FileSystem.fileExists(path);
|
||||||
}
|
}
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
},
|
}
|
||||||
directoryExists: function (path) {
|
|
||||||
|
export function directoryExists(path) {
|
||||||
if (window.NativeShell && window.NativeShell.FileSystem) {
|
if (window.NativeShell && window.NativeShell.FileSystem) {
|
||||||
return window.NativeShell.FileSystem.directoryExists(path);
|
return window.NativeShell.FileSystem.directoryExists(path);
|
||||||
}
|
}
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
define(["inputManager", "layoutManager"], function (inputManager, layoutManager) {
|
import inputManager from "inputManager";
|
||||||
"use strict";
|
import layoutManager from "layoutManager";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key name mapping.
|
* Key name mapping.
|
||||||
*/
|
*/
|
||||||
// Add more to support old browsers
|
const KeyNames = {
|
||||||
var KeyNames = {
|
|
||||||
13: "Enter",
|
13: "Enter",
|
||||||
19: "Pause",
|
19: "Pause",
|
||||||
27: "Escape",
|
27: "Escape",
|
||||||
|
@ -37,9 +36,9 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager)
|
||||||
/**
|
/**
|
||||||
* Keys used for keyboard navigation.
|
* Keys used for keyboard navigation.
|
||||||
*/
|
*/
|
||||||
var NavigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"];
|
const NavigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"];
|
||||||
|
|
||||||
var hasFieldKey = false;
|
let hasFieldKey = false;
|
||||||
try {
|
try {
|
||||||
hasFieldKey = "key" in new KeyboardEvent("keydown");
|
hasFieldKey = "key" in new KeyboardEvent("keydown");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -48,7 +47,7 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager)
|
||||||
|
|
||||||
if (!hasFieldKey) {
|
if (!hasFieldKey) {
|
||||||
// Add [a..z]
|
// Add [a..z]
|
||||||
for (var i = 65; i <= 90; i++) {
|
for (let i = 65; i <= 90; i++) {
|
||||||
KeyNames[i] = String.fromCharCode(i).toLowerCase();
|
KeyNames[i] = String.fromCharCode(i).toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,10 +55,10 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager)
|
||||||
/**
|
/**
|
||||||
* Returns key name from event.
|
* Returns key name from event.
|
||||||
*
|
*
|
||||||
* @param {KeyboardEvent} keyboard event
|
* @param {KeyboardEvent} event keyboard event
|
||||||
* @return {string} key name
|
* @return {string} key name
|
||||||
*/
|
*/
|
||||||
function getKeyName(event) {
|
export function getKeyName(event) {
|
||||||
return KeyNames[event.keyCode] || event.key;
|
return KeyNames[event.keyCode] || event.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,20 +68,20 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager)
|
||||||
* @param {string} key name
|
* @param {string} key name
|
||||||
* @return {boolean} _true_ if key is used for navigation
|
* @return {boolean} _true_ if key is used for navigation
|
||||||
*/
|
*/
|
||||||
function isNavigationKey(key) {
|
export function isNavigationKey(key) {
|
||||||
return NavigationKeys.indexOf(key) != -1;
|
return NavigationKeys.indexOf(key) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function enable() {
|
export function enable() {
|
||||||
document.addEventListener("keydown", function (e) {
|
document.addEventListener("keydown", function (e) {
|
||||||
var key = getKeyName(e);
|
const key = getKeyName(e);
|
||||||
|
|
||||||
// Ignore navigation keys for non-TV
|
// Ignore navigation keys for non-TV
|
||||||
if (!layoutManager.tv && isNavigationKey(key)) {
|
if (!layoutManager.tv && isNavigationKey(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var capture = true;
|
let capture = true;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "ArrowLeft":
|
case "ArrowLeft":
|
||||||
|
@ -156,10 +155,3 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager)
|
||||||
|
|
||||||
// No need to check for gamepads manually at load time, the eventhandler will be fired for that
|
// No need to check for gamepads manually at load time, the eventhandler will be fired for that
|
||||||
window.addEventListener("gamepadconnected", attachGamepadScript);
|
window.addEventListener("gamepadconnected", attachGamepadScript);
|
||||||
|
|
||||||
return {
|
|
||||||
enable: enable,
|
|
||||||
getKeyName: getKeyName,
|
|
||||||
isNavigationKey: isNavigationKey
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
// From https://github.com/parshap/node-sanitize-filename
|
// From https://github.com/parshap/node-sanitize-filename
|
||||||
|
|
||||||
define([], function () {
|
const illegalRe = /[\/\?<>\\:\*\|":]/g;
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var illegalRe = /[\/\?<>\\:\*\|":]/g;
|
|
||||||
// eslint-disable-next-line no-control-regex
|
// eslint-disable-next-line no-control-regex
|
||||||
var controlRe = /[\x00-\x1f\x80-\x9f]/g;
|
const controlRe = /[\x00-\x1f\x80-\x9f]/g;
|
||||||
var reservedRe = /^\.+$/;
|
const reservedRe = /^\.+$/;
|
||||||
var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
|
const windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
|
||||||
var windowsTrailingRe = /[\. ]+$/;
|
const windowsTrailingRe = /[\. ]+$/;
|
||||||
|
|
||||||
function isHighSurrogate(codePoint) {
|
function isHighSurrogate(codePoint) {
|
||||||
return codePoint >= 0xd800 && codePoint <= 0xdbff;
|
return codePoint >= 0xd800 && codePoint <= 0xdbff;
|
||||||
|
@ -23,11 +20,11 @@ define([], function () {
|
||||||
throw new Error("Input must be string");
|
throw new Error("Input must be string");
|
||||||
}
|
}
|
||||||
|
|
||||||
var charLength = string.length;
|
const charLength = string.length;
|
||||||
var byteLength = 0;
|
let byteLength = 0;
|
||||||
var codePoint = null;
|
let codePoint = null;
|
||||||
var prevCodePoint = null;
|
let prevCodePoint = null;
|
||||||
for (var i = 0; i < charLength; i++) {
|
for (let i = 0; i < charLength; i++) {
|
||||||
codePoint = string.charCodeAt(i);
|
codePoint = string.charCodeAt(i);
|
||||||
// handle 4-byte non-BMP chars
|
// handle 4-byte non-BMP chars
|
||||||
// low surrogate
|
// low surrogate
|
||||||
|
@ -56,12 +53,12 @@ define([], function () {
|
||||||
throw new Error("Input must be string");
|
throw new Error("Input must be string");
|
||||||
}
|
}
|
||||||
|
|
||||||
var charLength = string.length;
|
const charLength = string.length;
|
||||||
var curByteLength = 0;
|
let curByteLength = 0;
|
||||||
var codePoint;
|
let codePoint;
|
||||||
var segment;
|
let segment;
|
||||||
|
|
||||||
for (var i = 0; i < charLength; i += 1) {
|
for (let i = 0; i < charLength; i += 1) {
|
||||||
codePoint = string.charCodeAt(i);
|
codePoint = string.charCodeAt(i);
|
||||||
segment = string[i];
|
segment = string[i];
|
||||||
|
|
||||||
|
@ -82,9 +79,8 @@ define([], function () {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
export function sanitize(input, replacement) {
|
||||||
sanitize: function (input, replacement) {
|
const sanitized = input
|
||||||
var sanitized = input
|
|
||||||
.replace(illegalRe, replacement)
|
.replace(illegalRe, replacement)
|
||||||
.replace(controlRe, replacement)
|
.replace(controlRe, replacement)
|
||||||
.replace(reservedRe, replacement)
|
.replace(reservedRe, replacement)
|
||||||
|
@ -92,5 +88,3 @@ define([], function () {
|
||||||
.replace(windowsTrailingRe, replacement);
|
.replace(windowsTrailingRe, replacement);
|
||||||
return truncate(sanitized, 255);
|
return truncate(sanitized, 255);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue