2 * Provides basic details on the JavaScript environment.
4 * @author Alexander Ebert
5 * @copyright 2001-2018 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/Environment
9 define([], function() {
12 var _browser
= 'other';
14 var _platform
= 'desktop';
18 * @exports WoltLabSuite/Core/Environment
22 * Determines environment variables.
25 if (typeof window
.chrome
=== 'object') {
26 // this detects Opera as well, we could check for window.opr if we need to
30 var styles
= window
.getComputedStyle(document
.documentElement
);
31 for (var i
= 0, length
= styles
.length
; i
< length
; i
++) {
32 var property
= styles
[i
];
34 if (property
.indexOf('-ms-') === 0) {
35 // it is tempting to use 'msie', but it wouldn't really represent 'Edge'
36 _browser
= 'microsoft';
38 else if (property
.indexOf('-moz-') === 0) {
41 else if (_browser
!== 'firefox' && property
.indexOf('-webkit-') === 0) {
47 var ua
= window
.navigator
.userAgent
.toLowerCase();
48 if (ua
.indexOf('crios') !== -1) {
52 else if (/(?:iphone|ipad|ipod)/.test(ua
)) {
56 else if (ua
.indexOf('android') !== -1) {
57 _platform
= 'android';
59 else if (ua
.indexOf('iemobile') !== -1) {
60 _browser
= 'microsoft';
61 _platform
= 'windows';
64 if (_platform
=== 'desktop' && (ua
.indexOf('mobile') !== -1 || ua
.indexOf('tablet') !== -1)) {
69 _touch
= (!!('ontouchstart' in window
) || (!!('msMaxTouchPoints' in window
.navigator
) && window
.navigator
.msMaxTouchPoints
> 0) || window
.DocumentTouch
&& document
instanceof DocumentTouch
);
73 * Returns the lower-case browser identifier.
76 * - chrome: Chrome and Opera
78 * - microsoft: Internet Explorer and Microsoft Edge
81 * @return {string} browser identifier
88 * Returns the available editor's name or an empty string.
90 * @return {string} editor name
97 * Returns the browser platform.
102 * - ios: iPhone, iPad and iPod
103 * - windows: Windows on phones/tablets
105 * @return {string} browser platform
107 platform: function() {
112 * Returns true if browser is potentially used with a touchscreen.
114 * Warning: Detecting touch is unreliable and should be avoided at all cost.
116 * @deprecated 3.0 - exists for backward-compatibility only, will be removed in the future
118 * @return {boolean} true if a touchscreen is present