mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Remove focus-prevent-scroll, migrate gamepadtokey and chromecastHelper to ES6
This commit is contained in:
parent
e2aff66203
commit
58361ce70c
8 changed files with 540 additions and 569 deletions
|
@ -62,6 +62,7 @@
|
||||||
"epubjs": "^0.3.85",
|
"epubjs": "^0.3.85",
|
||||||
"fast-text-encoding": "^1.0.3",
|
"fast-text-encoding": "^1.0.3",
|
||||||
"flv.js": "^1.5.0",
|
"flv.js": "^1.5.0",
|
||||||
|
"focus-options-polyfill": "^1.5.0",
|
||||||
"headroom.js": "^0.11.0",
|
"headroom.js": "^0.11.0",
|
||||||
"hls.js": "^0.14.7",
|
"hls.js": "^0.14.7",
|
||||||
"howler": "^2.2.0",
|
"howler": "^2.2.0",
|
||||||
|
@ -278,6 +279,7 @@
|
||||||
"src/plugins/backdropScreensaver/plugin.js",
|
"src/plugins/backdropScreensaver/plugin.js",
|
||||||
"src/plugins/bookPlayer/plugin.js",
|
"src/plugins/bookPlayer/plugin.js",
|
||||||
"src/plugins/bookPlayer/tableOfContents.js",
|
"src/plugins/bookPlayer/tableOfContents.js",
|
||||||
|
"src/plugins/chromecastPlayer/chromecastHelper.js",
|
||||||
"src/plugins/photoPlayer/plugin.js",
|
"src/plugins/photoPlayer/plugin.js",
|
||||||
"src/plugins/youtubePlayer/plugin.js",
|
"src/plugins/youtubePlayer/plugin.js",
|
||||||
"src/scripts/alphanumericshortcuts.js",
|
"src/scripts/alphanumericshortcuts.js",
|
||||||
|
|
|
@ -10,6 +10,11 @@ _define('fetch', function() {
|
||||||
return fetch;
|
return fetch;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var focusPreventScroll = require('focus-options-polyfill');
|
||||||
|
_define('focus-options-polyfill', function() {
|
||||||
|
return focusPreventScroll;
|
||||||
|
});
|
||||||
|
|
||||||
// Blurhash
|
// Blurhash
|
||||||
var blurhash = require('blurhash');
|
var blurhash = require('blurhash');
|
||||||
_define('blurhash', function() {
|
_define('blurhash', function() {
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
// TODO: Move to external library (https://github.com/calvellido/focus-options-polyfill)
|
|
||||||
// Polyfill to add support for preventScroll by focus function
|
|
||||||
|
|
||||||
if (HTMLElement.prototype.nativeFocus === undefined) {
|
|
||||||
(function () {
|
|
||||||
var supportsPreventScrollOption = false;
|
|
||||||
try {
|
|
||||||
var focusElem = document.createElement('div');
|
|
||||||
|
|
||||||
focusElem.addEventListener('focus', function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
var opts = Object.defineProperty({}, 'preventScroll', {
|
|
||||||
// eslint-disable-next-line getter-return
|
|
||||||
get: function () {
|
|
||||||
supportsPreventScrollOption = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
focusElem.focus(opts);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('error checking preventScroll support');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!supportsPreventScrollOption) {
|
|
||||||
HTMLElement.prototype.nativeFocus = HTMLElement.prototype.focus;
|
|
||||||
|
|
||||||
HTMLElement.prototype.focus = function(options) {
|
|
||||||
var scrollX = window.scrollX;
|
|
||||||
var scrollY = window.scrollY;
|
|
||||||
|
|
||||||
this.nativeFocus();
|
|
||||||
|
|
||||||
// Restore window scroll if preventScroll
|
|
||||||
if (options && options.preventScroll) {
|
|
||||||
window.scroll(scrollX, scrollY);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
define(['events'], function (events) {
|
import events from 'events';
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// LinkParser
|
// LinkParser
|
||||||
//
|
//
|
||||||
|
@ -36,15 +35,15 @@ define(['events'], function (events) {
|
||||||
// 5) It wasn't as smart as it could have been about what should be part of a
|
// 5) It wasn't as smart as it could have been about what should be part of a
|
||||||
// URL and what should be part of human language.
|
// URL and what should be part of human language.
|
||||||
|
|
||||||
var protocols = '(?:(?:http|https|rtsp|ftp):\\/\\/)';
|
const protocols = '(?:(?:http|https|rtsp|ftp):\\/\\/)';
|
||||||
var credentials = "(?:(?:[a-z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-f0-9]{2})){1,64}" // username (1-64 normal or url escaped characters)
|
const credentials = "(?:(?:[a-z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-f0-9]{2})){1,64}" // username (1-64 normal or url escaped characters)
|
||||||
+ "(?:\\:(?:[a-z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-f0-9]{2})){1,25})?" // followed by optional password (: + 1-25 normal or url escaped characters)
|
+ "(?:\\:(?:[a-z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-f0-9]{2})){1,25})?" // followed by optional password (: + 1-25 normal or url escaped characters)
|
||||||
+ '\\@)';
|
+ '\\@)';
|
||||||
|
|
||||||
// IPv6 Regex http://forums.intermapper.com/viewtopic.php?t=452
|
// IPv6 Regex http://forums.intermapper.com/viewtopic.php?t=452
|
||||||
// by Dartware, LLC is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
|
// by Dartware, LLC is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
|
||||||
// http://intermapper.com/
|
// http://intermapper.com/
|
||||||
var ipv6 = '('
|
const ipv6 = '('
|
||||||
+ '(([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))'
|
+ '(([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))'
|
||||||
+ '|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))'
|
+ '|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))'
|
||||||
+ '|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))'
|
+ '|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))'
|
||||||
|
@ -55,13 +54,13 @@ define(['events'], function (events) {
|
||||||
+ '|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))'
|
+ '|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))'
|
||||||
+ ')(%.+)?';
|
+ ')(%.+)?';
|
||||||
|
|
||||||
var ipv4 = '(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.'
|
const ipv4 = '(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.'
|
||||||
+ '(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.'
|
+ '(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.'
|
||||||
+ '(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.'
|
+ '(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.'
|
||||||
+ '(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])';
|
+ '(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])';
|
||||||
|
|
||||||
// This would have been a lot cleaner if JS RegExp supported conditionals...
|
// This would have been a lot cleaner if JS RegExp supported conditionals...
|
||||||
var linkRegExpString =
|
const linkRegExpString =
|
||||||
|
|
||||||
// begin match for protocol / username / password / host
|
// begin match for protocol / username / password / host
|
||||||
'(?:'
|
'(?:'
|
||||||
|
@ -112,9 +111,9 @@ define(['events'], function (events) {
|
||||||
+ ')';
|
+ ')';
|
||||||
|
|
||||||
// regex = XRegExp(regex,'gi');
|
// regex = XRegExp(regex,'gi');
|
||||||
var linkRegExp = RegExp(linkRegExpString, 'gi');
|
const linkRegExp = RegExp(linkRegExpString, 'gi');
|
||||||
|
|
||||||
var protocolRegExp = RegExp('^' + protocols, 'i');
|
const protocolRegExp = RegExp('^' + protocols, 'i');
|
||||||
|
|
||||||
// if url doesn't begin with a known protocol, add http by default
|
// if url doesn't begin with a known protocol, add http by default
|
||||||
function ensureProtocol(url) {
|
function ensureProtocol(url) {
|
||||||
|
@ -125,18 +124,18 @@ define(['events'], function (events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for links in the text
|
// look for links in the text
|
||||||
var LinkParser = {
|
const LinkParser = {
|
||||||
parse: function (text) {
|
parse: function (text) {
|
||||||
var links = [];
|
const links = [];
|
||||||
var match;
|
let match;
|
||||||
|
|
||||||
// eslint-disable-next-line no-cond-assign
|
// eslint-disable-next-line no-cond-assign
|
||||||
while (match = linkRegExp.exec(text)) {
|
while (match = linkRegExp.exec(text)) {
|
||||||
console.debug(match);
|
console.debug(match);
|
||||||
var txt = match[0];
|
const txt = match[0];
|
||||||
var pos = match.index;
|
const pos = match.index;
|
||||||
var len = txt.length;
|
const len = txt.length;
|
||||||
var url = ensureProtocol(text);
|
const url = ensureProtocol(text);
|
||||||
links.push({ 'pos': pos, 'text': txt, 'len': len, 'url': url });
|
links.push({ 'pos': pos, 'text': txt, 'len': len, 'url': url });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,21 +147,23 @@ define(['events'], function (events) {
|
||||||
window.LinkParser = LinkParser;
|
window.LinkParser = LinkParser;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var cache = {};
|
let cache = {};
|
||||||
|
|
||||||
|
// TODO: Replace with isIP (https://www.npmjs.com/package/is-ip)
|
||||||
function isValidIpAddress(address) {
|
function isValidIpAddress(address) {
|
||||||
var links = LinkParser.parse(address);
|
const links = LinkParser.parse(address);
|
||||||
|
|
||||||
return links.length == 1;
|
return links.length == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add IPv6 support. Potentially replace with isLocalhost (https://www.npmjs.com/package/is-localhost-ip)
|
||||||
function isLocalIpAddress(address) {
|
function isLocalIpAddress(address) {
|
||||||
address = address.toLowerCase();
|
address = address.toLowerCase();
|
||||||
|
|
||||||
if (address.indexOf('127.0.0.1') !== -1) {
|
if (address.includes('127.0.0.1')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (address.indexOf('localhost') !== -1) {
|
if (address.includes('localhost')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,13 +171,13 @@ define(['events'], function (events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getServerAddress(apiClient) {
|
function getServerAddress(apiClient) {
|
||||||
var serverAddress = apiClient.serverAddress();
|
const serverAddress = apiClient.serverAddress();
|
||||||
|
|
||||||
if (isValidIpAddress(serverAddress) && !isLocalIpAddress(serverAddress)) {
|
if (isValidIpAddress(serverAddress) && !isLocalIpAddress(serverAddress)) {
|
||||||
return Promise.resolve(serverAddress);
|
return Promise.resolve(serverAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
var cachedValue = getCachedValue(serverAddress);
|
const cachedValue = getCachedValue(serverAddress);
|
||||||
if (cachedValue) {
|
if (cachedValue) {
|
||||||
return Promise.resolve(cachedValue);
|
return Promise.resolve(cachedValue);
|
||||||
}
|
}
|
||||||
|
@ -184,7 +185,7 @@ define(['events'], function (events) {
|
||||||
return apiClient.getEndpointInfo().then(function (endpoint) {
|
return apiClient.getEndpointInfo().then(function (endpoint) {
|
||||||
if (endpoint.IsInNetwork) {
|
if (endpoint.IsInNetwork) {
|
||||||
return apiClient.getPublicSystemInfo().then(function (info) {
|
return apiClient.getPublicSystemInfo().then(function (info) {
|
||||||
var localAddress = info.LocalAddress;
|
let localAddress = info.LocalAddress;
|
||||||
if (!localAddress) {
|
if (!localAddress) {
|
||||||
console.debug('No valid local address returned, defaulting to external one');
|
console.debug('No valid local address returned, defaulting to external one');
|
||||||
localAddress = serverAddress;
|
localAddress = serverAddress;
|
||||||
|
@ -211,7 +212,7 @@ define(['events'], function (events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCachedValue(key) {
|
function getCachedValue(key) {
|
||||||
var obj = cache[key];
|
const obj = cache[key];
|
||||||
|
|
||||||
if (obj && (new Date().getTime() - obj.time) < 180000) {
|
if (obj && (new Date().getTime() - obj.time) < 180000) {
|
||||||
return obj.value;
|
return obj.value;
|
||||||
|
@ -223,7 +224,6 @@ define(['events'], function (events) {
|
||||||
events.on(ConnectionManager, 'localusersignedin', clearCache);
|
events.on(ConnectionManager, 'localusersignedin', clearCache);
|
||||||
events.on(ConnectionManager, 'localusersignedout', clearCache);
|
events.on(ConnectionManager, 'localusersignedout', clearCache);
|
||||||
|
|
||||||
return {
|
export default {
|
||||||
getServerAddress: getServerAddress
|
getServerAddress: getServerAddress
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|
|
@ -366,6 +366,8 @@ define(['appSettings', 'userSettings', 'playbackManager', 'connectionManager', '
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
require(['./chromecastHelper'], function (chromecastHelper) {
|
require(['./chromecastHelper'], function (chromecastHelper) {
|
||||||
|
chromecastHelper = chromecastHelper.default || chromecastHelper;
|
||||||
|
|
||||||
chromecastHelper.getServerAddress(apiClient).then(function (serverAddress) {
|
chromecastHelper.getServerAddress(apiClient).then(function (serverAddress) {
|
||||||
message.serverAddress = serverAddress;
|
message.serverAddress = serverAddress;
|
||||||
player.sendMessageInternal(message).then(resolve, reject);
|
player.sendMessageInternal(message).then(resolve, reject);
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
// # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
// # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// # THE SOFTWARE.
|
// # THE SOFTWARE.
|
||||||
require(['apphost'], function (appHost) {
|
|
||||||
'use strict';
|
import appHost from 'apphost';
|
||||||
|
|
||||||
var _GAMEPAD_A_BUTTON_INDEX = 0;
|
var _GAMEPAD_A_BUTTON_INDEX = 0;
|
||||||
var _GAMEPAD_B_BUTTON_INDEX = 1;
|
var _GAMEPAD_B_BUTTON_INDEX = 1;
|
||||||
|
@ -399,4 +399,3 @@ require(['apphost'], function (appHost) {
|
||||||
// and provide input to the DOM navigator.getGamepads API.
|
// and provide input to the DOM navigator.getGamepads API.
|
||||||
window.navigator.gamepadInputEmulation = 'gamepad';
|
window.navigator.gamepadInputEmulation = 'gamepad';
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
|
@ -689,7 +689,8 @@ function initClient() {
|
||||||
'events',
|
'events',
|
||||||
'credentialprovider',
|
'credentialprovider',
|
||||||
'connectionManagerFactory',
|
'connectionManagerFactory',
|
||||||
'appStorage'
|
'appStorage',
|
||||||
|
'focus-options-polyfill'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
urlArgs: urlArgs,
|
urlArgs: urlArgs,
|
||||||
|
@ -698,7 +699,7 @@ function initClient() {
|
||||||
});
|
});
|
||||||
|
|
||||||
promise = require(['fetch'])
|
promise = require(['fetch'])
|
||||||
.then(() => require(['jQuery', 'polyfill', 'fast-text-encoding', 'intersection-observer', 'classlist-polyfill', 'css!assets/css/site', 'jellyfin-noto'], (jQuery) => {
|
.then(() => require(['jQuery', 'polyfill', 'fast-text-encoding', 'intersection-observer', 'classlist-polyfill', 'focus-options-polyfill', 'css!assets/css/site', 'jellyfin-noto'], (jQuery) => {
|
||||||
// Expose jQuery globally
|
// Expose jQuery globally
|
||||||
window.$ = jQuery;
|
window.$ = jQuery;
|
||||||
window.jQuery = jQuery;
|
window.jQuery = jQuery;
|
||||||
|
|
|
@ -4608,6 +4608,11 @@ flv.js@^1.5.0:
|
||||||
es6-promise "^4.2.5"
|
es6-promise "^4.2.5"
|
||||||
webworkify "^1.5.0"
|
webworkify "^1.5.0"
|
||||||
|
|
||||||
|
focus-options-polyfill@^1.5.0:
|
||||||
|
version "1.5.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/focus-options-polyfill/-/focus-options-polyfill-1.5.0.tgz#fd2e6a0d6d8f828346726a5adf02f3d2bdfece5f"
|
||||||
|
integrity sha512-HiMSaXGUz2OFjOuoGTWXlp+YjZCGnVXPu6vPeccgaSOzGmqLVz8tJRcKXWfMJnj16LXf/IM1rJI0zrZMVc9q7g==
|
||||||
|
|
||||||
follow-redirects@1.5.10:
|
follow-redirects@1.5.10:
|
||||||
version "1.5.10"
|
version "1.5.10"
|
||||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
|
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue