Move all browser/platform detecting in utils/Browser.js

This commit is contained in:
Paris Kasidiaris
2016-11-04 18:41:00 +02:00
parent 356377975b
commit d426c99866
3 changed files with 32 additions and 29 deletions
+9
View File
@@ -9,9 +9,18 @@
* @module xterm/utils/Browser
*/
import { contains } from './Generic.js';
let userAgent = navigator.userAgent;
let platform = navigator.platform;
export let isFirefox = !!~userAgent.indexOf('Firefox');
export let isMSIE = !!~userAgent.indexOf('MSIE');
// Find the users platform. We use this to interpret the meta key
// and ISO third level shifts.
// http://stackoverflow.com/q/19877924/577598
export let isMac = contains(platform, ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']);
export let isIpad = platform === 'iPad';
export let isIphone = platform === 'iPhone';
export let isMSWindows = contains(platform, ['Windows', 'Win16', 'Win32', 'WinCE']);
+19
View File
@@ -0,0 +1,19 @@
/**
* xterm.js: xterm, in the browser
* Copyright (c) 2016, SourceLair Private Company <www.sourcelair.com> (MIT License)
*/
/**
* Generic utilities module. This module contains generic methods that can be helpful at
* different parts of the code base.
* @module xterm/utils/Generic
*/
export let contains = function(el, arr) {
for (var i = 0; i < arr.length; i += 1) {
if (el === arr[i]) {
return true;
}
}
return false;
};