mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
Migrate core/utils/useragent.js to goog.module syntax (#5435)
* Migrate core/utils/useragent.js to ES6 const/let * Migrate core/utils/useragent.js to goog.module * Migrate core/utils/useragent.js named requires * clang-format core/utils/useragent.js
This commit is contained in:
committed by
GitHub
parent
c31895dc60
commit
2d89a36e7d
@@ -16,100 +16,140 @@
|
|||||||
* @name Blockly.utils.userAgent
|
* @name Blockly.utils.userAgent
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
goog.provide('Blockly.utils.userAgent');
|
goog.module('Blockly.utils.userAgent');
|
||||||
|
goog.module.declareLegacyNamespace();
|
||||||
|
|
||||||
goog.require('Blockly.utils.global');
|
const global = goog.require('Blockly.utils.global');
|
||||||
|
|
||||||
|
|
||||||
/** @const {boolean} */
|
/**
|
||||||
Blockly.utils.userAgent.IE;
|
* @type {string}
|
||||||
|
* The raw useragent string.
|
||||||
|
*/
|
||||||
|
let rawUserAgent;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.EDGE;
|
let isIe;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.JAVA_FX;
|
let isEdge;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.CHROME;
|
let isJavaFx;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.WEBKIT;
|
let isChrome;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.GECKO;
|
let isWebKit;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.ANDROID;
|
let isGecko;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.IPAD;
|
let isAndroid;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.IPOD;
|
let isIPad;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.IPHONE;
|
let isIPod;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.MAC;
|
let isIPhone;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.TABLET;
|
let isMac;
|
||||||
|
|
||||||
/** @const {boolean} */
|
/** @type {boolean} */
|
||||||
Blockly.utils.userAgent.MOBILE;
|
let isTablet;
|
||||||
|
|
||||||
|
/** @type {boolean} */
|
||||||
|
let isMobile;
|
||||||
|
|
||||||
(function(raw) {
|
(function(raw) {
|
||||||
Blockly.utils.userAgent.raw = raw;
|
rawUserAgent = raw;
|
||||||
var rawUpper = Blockly.utils.userAgent.raw.toUpperCase();
|
const rawUpper = rawUserAgent.toUpperCase();
|
||||||
/**
|
/**
|
||||||
* Case-insensitive test of whether name is in the useragent string.
|
* Case-insensitive test of whether name is in the useragent string.
|
||||||
* @param {string} name Name to test.
|
* @param {string} name Name to test.
|
||||||
* @return {boolean} True if name is present.
|
* @return {boolean} True if name is present.
|
||||||
*/
|
*/
|
||||||
function has(name) {
|
function has(name) {
|
||||||
return rawUpper.indexOf(name.toUpperCase()) != -1;
|
return rawUpper.indexOf(name.toUpperCase()) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Browsers. Logic from:
|
// Browsers. Logic from:
|
||||||
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/browser.js
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/browser.js
|
||||||
Blockly.utils.userAgent.IE = has('Trident') || has('MSIE');
|
isIe = has('Trident') || has('MSIE');
|
||||||
Blockly.utils.userAgent.EDGE = has('Edge');
|
isEdge = has('Edge');
|
||||||
// Useragent for JavaFX:
|
// Useragent for JavaFX:
|
||||||
// Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.44
|
// Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.44
|
||||||
// (KHTML, like Gecko) JavaFX/8.0 Safari/537.44
|
// (KHTML, like Gecko) JavaFX/8.0 Safari/537.44
|
||||||
Blockly.utils.userAgent.JAVA_FX = has('JavaFX');
|
isJavaFx = has('JavaFX');
|
||||||
Blockly.utils.userAgent.CHROME = (has('Chrome') || has('CriOS')) &&
|
isChrome = (has('Chrome') || has('CriOS')) && !isEdge;
|
||||||
!Blockly.utils.userAgent.EDGE;
|
|
||||||
|
|
||||||
// Engines. Logic from:
|
// Engines. Logic from:
|
||||||
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/engine.js
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/engine.js
|
||||||
Blockly.utils.userAgent.WEBKIT = has('WebKit') &&
|
isWebKit = has('WebKit') && !isEdge;
|
||||||
!Blockly.utils.userAgent.EDGE;
|
isGecko = has('Gecko') && !isWebKit && !isIe && !isEdge;
|
||||||
Blockly.utils.userAgent.GECKO = has('Gecko') &&
|
|
||||||
!Blockly.utils.userAgent.WEBKIT &&
|
|
||||||
!Blockly.utils.userAgent.IE &&
|
|
||||||
!Blockly.utils.userAgent.EDGE;
|
|
||||||
|
|
||||||
// Platforms. Logic from:
|
// Platforms. Logic from:
|
||||||
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/platform.js and
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/platform.js
|
||||||
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/extra.js
|
// and
|
||||||
Blockly.utils.userAgent.ANDROID = has('Android');
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/extra.js
|
||||||
var maxTouchPoints = Blockly.utils.global['navigator'] &&
|
isAndroid = has('Android');
|
||||||
Blockly.utils.global['navigator']['maxTouchPoints'];
|
const maxTouchPoints =
|
||||||
Blockly.utils.userAgent.IPAD = has('iPad') ||
|
global['navigator'] && global['navigator']['maxTouchPoints'];
|
||||||
has('Macintosh') && maxTouchPoints > 0;
|
isIPad = has('iPad') || has('Macintosh') && maxTouchPoints > 0;
|
||||||
Blockly.utils.userAgent.IPOD = has('iPod');
|
isIPod = has('iPod');
|
||||||
Blockly.utils.userAgent.IPHONE = has('iPhone') &&
|
isIPhone = has('iPhone') && !isIPad && !isIPod;
|
||||||
!Blockly.utils.userAgent.IPAD && !Blockly.utils.userAgent.IPOD;
|
isMac = has('Macintosh');
|
||||||
Blockly.utils.userAgent.MAC = has('Macintosh');
|
|
||||||
|
|
||||||
// Devices. Logic from:
|
// Devices. Logic from:
|
||||||
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/device.js
|
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/device.js
|
||||||
Blockly.utils.userAgent.TABLET = Blockly.utils.userAgent.IPAD ||
|
isTablet = isIPad || (isAndroid && !has('Mobile')) || has('Silk');
|
||||||
(Blockly.utils.userAgent.ANDROID && !has('Mobile')) || has('Silk');
|
isMobile = !isTablet && (isIPod || isIPhone || isAndroid || has('IEMobile'));
|
||||||
Blockly.utils.userAgent.MOBILE = !Blockly.utils.userAgent.TABLET &&
|
})((global['navigator'] && global['navigator']['userAgent']) || '');
|
||||||
(Blockly.utils.userAgent.IPOD || Blockly.utils.userAgent.IPHONE ||
|
|
||||||
Blockly.utils.userAgent.ANDROID || has('IEMobile'));
|
/** @const {string} */
|
||||||
})((Blockly.utils.global['navigator'] && Blockly.utils.global['navigator']['userAgent']) || '');
|
exports.raw = rawUserAgent;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.IE = isIe;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.EDGE = isEdge;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.JavaFx = isJavaFx;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.CHROME = isChrome;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.WEBKIT = isWebKit;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.GECKO = isGecko;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.ANDROID = isAndroid;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.IPAD = isIPad;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.IPOD = isIPod;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.IPHONE = isIPhone;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.MAC = isMac;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.TABLET = isTablet;
|
||||||
|
|
||||||
|
/** @const {boolean} */
|
||||||
|
exports.MOBILE = isMobile;
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Block
|
|||||||
goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], [], {'lang': 'es6', 'module': 'goog'});
|
goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], [], {'lang': 'es6', 'module': 'goog'});
|
||||||
goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'});
|
goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'});
|
||||||
goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
|
goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
|
||||||
goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']);
|
goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global'], {'lang': 'es6', 'module': 'goog'});
|
||||||
goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []);
|
goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []);
|
||||||
goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.Names', 'Blockly.VariableModel', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.Names', 'Blockly.VariableModel', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||||
goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils'], {'lang': 'es6', 'module': 'goog'});
|
goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils'], {'lang': 'es6', 'module': 'goog'});
|
||||||
|
|||||||
Reference in New Issue
Block a user