diff --git a/src/utils/Browser.js b/src/utils/Browser.js index bc78968..e7b1180 100644 --- a/src/utils/Browser.js +++ b/src/utils/Browser.js @@ -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']); diff --git a/src/utils/Generic.js b/src/utils/Generic.js new file mode 100644 index 0000000..5097b61 --- /dev/null +++ b/src/utils/Generic.js @@ -0,0 +1,19 @@ +/** + * xterm.js: xterm, in the browser + * Copyright (c) 2016, SourceLair Private Company (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; +}; diff --git a/src/xterm.js b/src/xterm.js index e1840f2..63f0ac2 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -35,7 +35,7 @@ import { CompositionHelper } from './CompositionHelper.js'; import { EventEmitter } from './EventEmitter.js'; import { Viewport } from './Viewport.js'; import { rightClickHandler, pasteHandler, copyHandler } from './handlers/Clipboard.js'; -import { isFirefox, isMSIE } from './utils/Browser'; +import { isFirefox, isMSIE, isMac, isIpad, isIphone, isMSWindows } from './utils/Browser'; /** * Terminal Emulation References: @@ -536,22 +536,6 @@ Terminal.prototype.open = function(parent) { this.document = this.parent.ownerDocument; this.body = this.document.getElementsByTagName('body')[0]; - // Find the users platform. We use this to interpret the meta key - // and ISO third level shifts. - // http://stackoverflow.com/q/19877924/577598 - if (this.context.navigator && this.context.navigator.platform) { - this.isMac = contains( - this.context.navigator.platform, - ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'] - ); - this.isIpad = this.context.navigator.platform === 'iPad'; - this.isIphone = this.context.navigator.platform === 'iPhone'; - this.isMSWindows = contains( - this.context.navigator.platform, - ['Windows', 'Win16', 'Win32', 'WinCE'] - ); - } - //Create main element container this.element = this.document.createElement('div'); this.element.classList.add('terminal'); @@ -2720,7 +2704,7 @@ Terminal.prototype.evaluateKeyEscapeSequence = function(ev) { // ^] - group sep result.key = String.fromCharCode(29); } - } else if (!this.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) { + } else if (!isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) { // On Mac this is a third level shift. Use instead. if (ev.keyCode >= 65 && ev.keyCode <= 90) { result.key = '\x1b' + String.fromCharCode(ev.keyCode + 32); @@ -4875,15 +4859,6 @@ Terminal.charsets.ISOLatin = null; // /A * Helpers */ -function contains(el, arr) { - for (var i = 0; i < arr.length; i += 1) { - if (el === arr[i]) { - return true; - } - } - return false; -} - function on(el, type, handler, capture) { if (!Array.isArray(el)) { el = [el]; @@ -4938,8 +4913,8 @@ function indexOf(obj, el) { function isThirdLevelShift(term, ev) { var thirdLevelKey = - (term.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) || - (term.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey); + (isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) || + (isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey); if (ev.type == 'keypress') { return thirdLevelKey;