From bbb688313ec458cf96627e989bd13a2192a4b081 Mon Sep 17 00:00:00 2001 From: Paris Date: Mon, 13 Apr 2015 19:47:04 +0300 Subject: [PATCH] [attach addon] Improve documentation --- addons/attach/attach.js | 60 ++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/addons/attach/attach.js b/addons/attach/attach.js index 5d74b17c..5b3b4dc2 100644 --- a/addons/attach/attach.js +++ b/addons/attach/attach.js @@ -19,21 +19,30 @@ attach(this.Xterm); } })(function (Xterm) { + 'use strict'; + /** - * Attaches the current terminal to the given socket + * This module provides methods for attaching a terminal to a WebSocket + * stream. * - * @param {WebSocket} socket - The socket to attach the current terminal + * @module xterm/addons/attach/attach + */ + var exports = {}; + + /** + * Attaches the given terminal to the given socket. + * + * @param {Xterm} term - The terminal to be attached to the given socket. + * @param {WebSocket} socket - The socket to attach the current terminal. * @param {boolean} bidirectional - Whether the terminal should send data - * to the socket as well + * to the socket as well. * @param {boolean} buffered - Whether the rendering of incoming data * should happen instantly or at a maximum - * frequency of 1 rendering per 10ms + * frequency of 1 rendering per 10ms. */ - Xterm.prototype.attach = function (socket, bidirectional, buffered) { - var term = this; - + exports.attach = function (term, socket, biderectional, buffered) { bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional; - this.socket = socket; + term.socket = socket; term._flushBuffer = function () { term.write(term._attachSocketBuffer); @@ -74,14 +83,13 @@ }; /** - * Detaches the current terminal from the given socket + * Detaches the given terminal from the given socket * + * @param {Xterm} term - The terminal to be detached from the given socket. * @param {WebSocket} socket - The socket from which to detach the current - * terminal + * terminal. */ - Xterm.prototype.detach = function (socket) { - var term = this; - + exports.detach = function (term, socket) { term.off('data', term._sendData); socket = (typeof socket == 'undefined') ? term.socket : socket; @@ -92,4 +100,30 @@ delete term.socket; }; + + /** + * Attaches the current terminal to the given socket + * + * @param {WebSocket} socket - The socket to attach the current terminal. + * @param {boolean} bidirectional - Whether the terminal should send data + * to the socket as well. + * @param {boolean} buffered - Whether the rendering of incoming data + * should happen instantly or at a maximum + * frequency of 1 rendering per 10ms. + */ + Xterm.prototype.attach = function (socket, bidirectional, buffered) { + return exports.attach(this, socket, bidirectional, buffered); + }; + + /** + * Detaches the current terminal from the given socket. + * + * @param {WebSocket} socket - The socket from which to detach the current + * terminal. + */ + Xterm.prototype.detach = function (socket) { + return exports.detach(this, socket); + }; + + return exports; }); \ No newline at end of file