1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Migration of browser to ES6 module

This commit is contained in:
Cameron 2020-07-29 10:04:55 +01:00
parent 9e9a6ecff1
commit da5eb9ccc4
2 changed files with 219 additions and 222 deletions

View file

@ -239,6 +239,7 @@
"src/plugins/youtubePlayer/plugin.js", "src/plugins/youtubePlayer/plugin.js",
"src/scripts/alphanumericshortcuts.js", "src/scripts/alphanumericshortcuts.js",
"src/scripts/autoBackdrops.js", "src/scripts/autoBackdrops.js",
"src/scripts/browser.js",
"src/scripts/datetime.js", "src/scripts/datetime.js",
"src/scripts/deleteHelper.js", "src/scripts/deleteHelper.js",
"src/scripts/dfnshelper.js", "src/scripts/dfnshelper.js",

View file

@ -1,9 +1,6 @@
define([], function () { function isTv() {
'use strict';
function isTv() {
// This is going to be really difficult to get right // This is going to be really difficult to get right
var userAgent = navigator.userAgent.toLowerCase(); const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('tv') !== -1) { if (userAgent.indexOf('tv') !== -1) {
return true; return true;
@ -22,10 +19,10 @@ define([], function () {
} }
return false; return false;
} }
function isMobile(userAgent) { function isMobile(userAgent) {
var terms = [ const terms = [
'mobi', 'mobi',
'ipad', 'ipad',
'iphone', 'iphone',
@ -37,18 +34,18 @@ define([], function () {
'opera mini' 'opera mini'
]; ];
var lower = userAgent.toLowerCase(); const lower = userAgent.toLowerCase();
for (var i = 0, length = terms.length; i < length; i++) { for (let i = 0, length = terms.length; i < length; i++) {
if (lower.indexOf(terms[i]) !== -1) { if (lower.indexOf(terms[i]) !== -1) {
return true; return true;
} }
} }
return false; return false;
} }
function hasKeyboard(browser) { function hasKeyboard(browser) {
if (browser.touch) { if (browser.touch) {
return true; return true;
} }
@ -73,20 +70,20 @@ define([], function () {
} }
return false; return false;
} }
function iOSversion() { function iOSversion() {
// MacIntel: Apple iPad Pro 11 iOS 13.1 // MacIntel: Apple iPad Pro 11 iOS 13.1
if (/iP(hone|od|ad)|MacIntel/.test(navigator.platform)) { if (/iP(hone|od|ad)|MacIntel/.test(navigator.platform)) {
// supports iOS 2.0 and later: <http://bit.ly/TJjs1V> // supports iOS 2.0 and later: <http://bit.ly/TJjs1V>
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/); const v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
} }
} }
var _supportsCssAnimation; let _supportsCssAnimation;
var _supportsCssAnimationWithPrefix; let _supportsCssAnimationWithPrefix;
function supportsCssAnimation(allowPrefix) { function supportsCssAnimation(allowPrefix) {
// TODO: Assess if this is still needed, as all of our targets should natively support CSS animations. // TODO: Assess if this is still needed, as all of our targets should natively support CSS animations.
if (allowPrefix) { if (allowPrefix) {
if (_supportsCssAnimationWithPrefix === true || _supportsCssAnimationWithPrefix === false) { if (_supportsCssAnimationWithPrefix === true || _supportsCssAnimationWithPrefix === false) {
@ -98,16 +95,16 @@ define([], function () {
} }
} }
var animation = false; let animation = false;
var domPrefixes = ['Webkit', 'O', 'Moz']; const domPrefixes = ['Webkit', 'O', 'Moz'];
var elm = document.createElement('div'); const elm = document.createElement('div');
if (elm.style.animationName !== undefined) { if (elm.style.animationName !== undefined) {
animation = true; animation = true;
} }
if (animation === false && allowPrefix) { if (animation === false && allowPrefix) {
for (var i = 0; i < domPrefixes.length; i++) { for (let i = 0; i < domPrefixes.length; i++) {
if (elm.style[domPrefixes[i] + 'AnimationName'] !== undefined) { if (elm.style[domPrefixes[i] + 'AnimationName'] !== undefined) {
animation = true; animation = true;
break; break;
@ -122,12 +119,12 @@ define([], function () {
_supportsCssAnimation = animation; _supportsCssAnimation = animation;
return _supportsCssAnimation; return _supportsCssAnimation;
} }
} }
var uaMatch = function (ua) { const uaMatch = function (ua) {
ua = ua.toLowerCase(); ua = ua.toLowerCase();
var match = /(edg)[ \/]([\w.]+)/.exec(ua) || const match = /(edg)[ \/]([\w.]+)/.exec(ua) ||
/(edga)[ \/]([\w.]+)/.exec(ua) || /(edga)[ \/]([\w.]+)/.exec(ua) ||
/(edgios)[ \/]([\w.]+)/.exec(ua) || /(edgios)[ \/]([\w.]+)/.exec(ua) ||
/(edge)[ \/]([\w.]+)/.exec(ua) || /(edge)[ \/]([\w.]+)/.exec(ua) ||
@ -139,15 +136,15 @@ define([], function () {
ua.indexOf('compatible') < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || ua.indexOf('compatible') < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
[]; [];
var versionMatch = /(version)[ \/]([\w.]+)/.exec(ua); const versionMatch = /(version)[ \/]([\w.]+)/.exec(ua);
var platform_match = /(ipad)/.exec(ua) || let platform_match = /(ipad)/.exec(ua) ||
/(iphone)/.exec(ua) || /(iphone)/.exec(ua) ||
/(windows)/.exec(ua) || /(windows)/.exec(ua) ||
/(android)/.exec(ua) || /(android)/.exec(ua) ||
[]; [];
var browser = match[1] || ''; let browser = match[1] || '';
if (browser === 'edge') { if (browser === 'edge') {
platform_match = ['']; platform_match = [''];
@ -157,14 +154,14 @@ define([], function () {
browser = 'opera'; browser = 'opera';
} }
var version; let version;
if (versionMatch && versionMatch.length > 2) { if (versionMatch && versionMatch.length > 2) {
version = versionMatch[2]; version = versionMatch[2];
} }
version = version || match[2] || '0'; version = version || match[2] || '0';
var versionMajor = parseInt(version.split('.')[0]); let versionMajor = parseInt(version.split('.')[0]);
if (isNaN(versionMajor)) { if (isNaN(versionMajor)) {
versionMajor = 0; versionMajor = 0;
@ -176,85 +173,84 @@ define([], function () {
platform: platform_match[0] || '', platform: platform_match[0] || '',
versionMajor: versionMajor versionMajor: versionMajor
}; };
}; };
var userAgent = navigator.userAgent; const userAgent = navigator.userAgent;
var matched = uaMatch(userAgent); const matched = uaMatch(userAgent);
var browser = {}; const browser = {};
if (matched.browser) { if (matched.browser) {
browser[matched.browser] = true; browser[matched.browser] = true;
browser.version = matched.version; browser.version = matched.version;
browser.versionMajor = matched.versionMajor; browser.versionMajor = matched.versionMajor;
} }
if (matched.platform) { if (matched.platform) {
browser[matched.platform] = true; browser[matched.platform] = true;
} }
browser.edgeChromium = browser.edg || browser.edga || browser.edgios; browser.edgeChromium = browser.edg || browser.edga || browser.edgios;
if (!browser.chrome && !browser.edgeChromium && !browser.edge && !browser.opera && userAgent.toLowerCase().indexOf('webkit') !== -1) { if (!browser.chrome && !browser.edgeChromium && !browser.edge && !browser.opera && userAgent.toLowerCase().indexOf('webkit') !== -1) {
browser.safari = true; browser.safari = true;
} }
if (userAgent.toLowerCase().indexOf('playstation 4') !== -1) { if (userAgent.toLowerCase().indexOf('playstation 4') !== -1) {
browser.ps4 = true; browser.ps4 = true;
browser.tv = true; browser.tv = true;
} }
if (isMobile(userAgent)) { if (isMobile(userAgent)) {
browser.mobile = true; browser.mobile = true;
} }
if (userAgent.toLowerCase().indexOf('xbox') !== -1) { if (userAgent.toLowerCase().indexOf('xbox') !== -1) {
browser.xboxOne = true; browser.xboxOne = true;
browser.tv = true; browser.tv = true;
} }
browser.animate = typeof document !== 'undefined' && document.documentElement.animate != null; browser.animate = typeof document !== 'undefined' && document.documentElement.animate != null;
browser.tizen = userAgent.toLowerCase().indexOf('tizen') !== -1 || self.tizen != null; browser.tizen = userAgent.toLowerCase().indexOf('tizen') !== -1 || self.tizen != null;
browser.web0s = userAgent.toLowerCase().indexOf('Web0S'.toLowerCase()) !== -1; browser.web0s = userAgent.toLowerCase().indexOf('Web0S'.toLowerCase()) !== -1;
browser.edgeUwp = browser.edge && (userAgent.toLowerCase().indexOf('msapphost') !== -1 || userAgent.toLowerCase().indexOf('webview') !== -1); browser.edgeUwp = browser.edge && (userAgent.toLowerCase().indexOf('msapphost') !== -1 || userAgent.toLowerCase().indexOf('webview') !== -1);
if (!browser.tizen) { if (!browser.tizen) {
browser.orsay = userAgent.toLowerCase().indexOf('smarthub') !== -1; browser.orsay = userAgent.toLowerCase().indexOf('smarthub') !== -1;
} else { } else {
var v = (navigator.appVersion).match(/Tizen (\d+).(\d+)/); const v = (navigator.appVersion).match(/Tizen (\d+).(\d+)/);
browser.tizenVersion = parseInt(v[1]); browser.tizenVersion = parseInt(v[1]);
} }
if (browser.edgeUwp) { if (browser.edgeUwp) {
browser.edge = true; browser.edge = true;
} }
browser.tv = isTv(); browser.tv = isTv();
browser.operaTv = browser.tv && userAgent.toLowerCase().indexOf('opr/') !== -1; browser.operaTv = browser.tv && userAgent.toLowerCase().indexOf('opr/') !== -1;
if (browser.mobile || browser.tv) { if (browser.mobile || browser.tv) {
browser.slow = true; browser.slow = true;
} }
if (typeof document !== 'undefined') { if (typeof document !== 'undefined') {
/* eslint-disable-next-line compat/compat */ /* eslint-disable-next-line compat/compat */
if (('ontouchstart' in window) || (navigator.maxTouchPoints > 0)) { if (('ontouchstart' in window) || (navigator.maxTouchPoints > 0)) {
browser.touch = true; browser.touch = true;
} }
} }
browser.keyboard = hasKeyboard(browser); browser.keyboard = hasKeyboard(browser);
browser.supportsCssAnimation = supportsCssAnimation; browser.supportsCssAnimation = supportsCssAnimation;
browser.osx = userAgent.toLowerCase().indexOf('os x') !== -1; browser.osx = userAgent.toLowerCase().indexOf('os x') !== -1;
browser.iOS = browser.ipad || browser.iphone || browser.ipod; browser.iOS = browser.ipad || browser.iphone || browser.ipod;
if (browser.iOS) { if (browser.iOS) {
browser.iOSVersion = iOSversion(); browser.iOSVersion = iOSversion();
if (browser.iOSVersion && browser.iOSVersion.length >= 2) { if (browser.iOSVersion && browser.iOSVersion.length >= 2) {
browser.iOSVersion = browser.iOSVersion[0] + (browser.iOSVersion[1] / 10); browser.iOSVersion = browser.iOSVersion[0] + (browser.iOSVersion[1] / 10);
} }
} }
return browser; export default browser;
});