]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
[attach addon] Improve documentation
authorParis <paris@sourcelair.com>
Mon, 13 Apr 2015 16:47:04 +0000 (19:47 +0300)
committerParis <paris@sourcelair.com>
Mon, 13 Apr 2015 16:47:04 +0000 (19:47 +0300)
addons/attach/attach.js

index 5d74b17ca5b74b317e9d9b680e15cfd8c0bc2d9d..5b3b4dc2b864382baa8d10a7f11da9ef893b8369 100644 (file)
         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);
     };
 
     /**
-     * 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;
 
         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