summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-10-11 21:18:29 +0300
committerFatih Acet <acetfatih@gmail.com>2016-10-11 21:18:29 +0300
commitdfecbf06b7f39a1ed4a40a77fa3782cce13e8b1d (patch)
tree2c7c47868e742c2f6601c2dd349cfa4f6d6f510d
parenta44ab2e400af81ce98f9822b9ac0d31ce1de56d1 (diff)
downloadgitlab-ce-dfecbf06b7f39a1ed4a40a77fa3782cce13e8b1d.tar.gz
Wrap gl.Terminal with a IIFE.
-rw-r--r--app/assets/javascripts/terminal/terminal.js.es696
1 files changed, 50 insertions, 46 deletions
diff --git a/app/assets/javascripts/terminal/terminal.js.es6 b/app/assets/javascripts/terminal/terminal.js.es6
index d1bbab64b2c..f797f1ac637 100644
--- a/app/assets/javascripts/terminal/terminal.js.es6
+++ b/app/assets/javascripts/terminal/terminal.js.es6
@@ -1,63 +1,67 @@
-window.gl = window.gl || {};
+((global) => {
-gl.Terminal = class {
+ class GLTerminal {
- constructor(options) {
- this.options = options || {};
+ constructor(options) {
+ this.options = options || {};
- options.cursorBlink = options.cursorBlink || true;
- options.screenKeys = options.screenKeys || true;
- options.cols = options.cols || 100;
- options.rows = options.rows || 40;
- this.container = document.querySelector(options.selector);
+ options.cursorBlink = options.cursorBlink || true;
+ options.screenKeys = options.screenKeys || true;
+ options.cols = options.cols || 100;
+ options.rows = options.rows || 40;
+ this.container = document.querySelector(options.selector);
- this.setSocketUrl();
- this.createTerminal();
- }
+ this.setSocketUrl();
+ this.createTerminal();
+ }
- setSocketUrl() {
- const {protocol, hostname, port} = window.location;
- const wsProtocol = protocol === 'https:' ? 'wss://' : 'ws://';
- const path = this.container.dataset.projectPath;
+ setSocketUrl() {
+ const {protocol, hostname, port} = window.location;
+ const wsProtocol = protocol === 'https:' ? 'wss://' : 'ws://';
+ const path = this.container.dataset.projectPath;
- this.socketUrl = `${wsProtocol}${hostname}:${port}${path}/deployments/4/terminal_websocket`
- }
+ this.socketUrl = `${wsProtocol}${hostname}:${port}${path}/deployments/4/terminal_websocket`
+ }
- createTerminal() {
- this.terminal = new Terminal(this.options);
- this.socket = new WebSocket(this.socketUrl);
+ createTerminal() {
+ this.terminal = new Terminal(this.options);
+ this.socket = new WebSocket(this.socketUrl);
- this.terminal.open(this.container);
- this.terminal.fit();
+ this.terminal.open(this.container);
+ this.terminal.fit();
- this.socket.onopen = () => { this.runTerminal() };
- this.socket.onclose = () => { this.handleSocketFailure() };
- this.socket.onerror = () => { this.handleSocketFailure() };
- }
+ this.socket.onopen = () => { this.runTerminal() };
+ this.socket.onclose = () => { this.handleSocketFailure() };
+ this.socket.onerror = () => { this.handleSocketFailure() };
+ }
- runTerminal() {
- const {cols, rows} = this.terminal.proposeGeometry();
- const {offsetWidth, offsetHeight} = this.terminal.element;
+ runTerminal() {
+ const {cols, rows} = this.terminal.proposeGeometry();
+ const {offsetWidth, offsetHeight} = this.terminal.element;
- this.charWidth = Math.ceil(offsetWidth / cols);
- this.charHeight = Math.ceil(offsetHeight / rows);
+ this.charWidth = Math.ceil(offsetWidth / cols);
+ this.charHeight = Math.ceil(offsetHeight / rows);
- this.terminal.attach(this.socket);
- this.isTerminalInitialized = true;
- this.setTerminalSize(cols, rows);
- }
+ this.terminal.attach(this.socket);
+ this.isTerminalInitialized = true;
+ this.setTerminalSize(cols, rows);
+ }
- setTerminalSize (cols, rows) {
- const width = `${(cols * this.charWidth).toString()}px`;
- const height = `${(rows * this.charHeight).toString()}px`;
+ setTerminalSize (cols, rows) {
+ const width = `${(cols * this.charWidth).toString()}px`;
+ const height = `${(rows * this.charHeight).toString()}px`;
- this.container.style.width = width;
- this.container.style.height = height;
- this.terminal.resize(cols, rows);
- }
+ this.container.style.width = width;
+ this.container.style.height = height;
+ this.terminal.resize(cols, rows);
+ }
+
+ handleSocketFailure() {
+ console.error('There is a problem with Terminal connection. Please try again!');
+ }
- handleSocketFailure() {
- console.error('There is a problem with Terminal connection. Please try again!');
}
-}
+ global.Terminal = GLTerminal;
+
+})(window.gl || (window.gl = {}))