From dc67c9454505a995e2fcc3cbd01a85e9f91e879a Mon Sep 17 00:00:00 2001 From: Paris Date: Tue, 3 May 2016 12:48:16 +0300 Subject: [PATCH] Change CommonJS package structure Instead of making Xterm prototype extending optional, just require Xterm and pass it as parameter to the function just like it is being done with RequireJS --- addons/attach/attach.js | 49 ++++++++++------------------- addons/fit/fit.js | 27 ++++------------ addons/fullscreen/fullscreen.js | 21 ++----------- addons/linkify/linkify.js | 55 ++++++++++++--------------------- 4 files changed, 46 insertions(+), 106 deletions(-) diff --git a/addons/attach/attach.js b/addons/attach/attach.js index 775535cf..24a45eae 100644 --- a/addons/attach/attach.js +++ b/addons/attach/attach.js @@ -11,7 +11,7 @@ /* * CommonJS environment */ - module.exports = attach.call(this); + module.exports = attach(require('../../src/xterm')); } else if (typeof define == 'function') { /* * Require.js is available @@ -107,43 +107,28 @@ }; /** - * Extends the given terminal prototype with the public methods of this add-on. + * Attaches the current terminal to the given socket * - * @param {function} Xterm - The prototype to be extended. + * @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. */ - exports.extendXtermPrototype = function (Xterm) { - /** - * 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); - }; + Xterm.prototype.attach = function (socket, bidirectional, buffered) { + return exports.attach(this, socket, bidirectional, buffered); }; /** - * If the Xterm parameter is a function, then extend it with the methods declared in this - * add-on. + * Detaches the current terminal from the given socket. + * + * @param {WebSocket} socket - The socket from which to detach the current + * terminal. */ - if (typeof Xterm == 'function') { - exports.extendXtermPrototype(Xterm); - } + Xterm.prototype.detach = function (socket) { + return exports.detach(this, socket); + }; return exports; }); diff --git a/addons/fit/fit.js b/addons/fit/fit.js index 3bcf0907..deefd1fd 100644 --- a/addons/fit/fit.js +++ b/addons/fit/fit.js @@ -16,7 +16,7 @@ /* * CommonJS environment */ - module.exports = fit.call(this); + module.exports = fit(require('../../src/xterm')); } else if (typeof define == 'function') { /* * Require.js is available @@ -74,28 +74,13 @@ term.resize(geometry.cols, geometry.rows); }; - /** - * Extends the given terminal prototype with the public methods of this add-on. - * - * @param {function} Xterm - The prototype to be extended. - */ - exports.extendXtermPrototype = function (Xterm) { - Xterm.prototype.proposeGeometry = function () { - return exports.proposeGeometry(this); - }; - - Xterm.prototype.fit = function () { - return exports.fit(this); - }; + Xterm.prototype.proposeGeometry = function () { + return exports.proposeGeometry(this); }; - /** - * If the Xterm parameter is a function, then extend it with the methods declared in this - * add-on. - */ - if (typeof Xterm == 'function') { - exports.extendXtermPrototype(Xterm); - } + Xterm.prototype.fit = function () { + return exports.fit(this); + }; return exports; }); diff --git a/addons/fullscreen/fullscreen.js b/addons/fullscreen/fullscreen.js index 1d5a568b..2689e616 100644 --- a/addons/fullscreen/fullscreen.js +++ b/addons/fullscreen/fullscreen.js @@ -15,7 +15,7 @@ /* * CommonJS environment */ - module.exports = fullscreen.call(this); + module.exports = fullscreen(require('../../src/xterm')); } else if (typeof define == 'function') { /* * Require.js is available @@ -44,24 +44,9 @@ term.element.classList[fn]('fullscreen'); }; - /** - * Extends the given terminal prototype with the public methods of this add-on. - * - * @param {function} Xterm - The prototype to be extended. - */ - exports.extendXtermPrototype = function (Xterm) { - Xterm.prototype.toggleFullscreen = function (fullscreen) { - exports.toggleFullScreen(this, fullscreen); - }; + Xterm.prototype.toggleFullscreen = function (fullscreen) { + exports.toggleFullScreen(this, fullscreen); }; - /** - * If the Xterm parameter is a function, then extend it with the methods declared in this - * add-on. - */ - if (typeof Xterm == 'function') { - exports.extendXtermPrototype(Xterm); - } - return exports; }); diff --git a/addons/linkify/linkify.js b/addons/linkify/linkify.js index 86849409..152404d4 100644 --- a/addons/linkify/linkify.js +++ b/addons/linkify/linkify.js @@ -3,7 +3,7 @@ /* * CommonJS environment */ - module.exports = linkify.call(this); + module.exports = linkify(require('../../src/xterm')); } else if (typeof define == 'function') { /* * Require.js is available @@ -11,8 +11,8 @@ define(['../../src/xterm'], linkify); } else { /* - * Plain browser environment - */ + * Plain browser environment + */ linkify(this.Xterm); } })(function (Xterm) { @@ -159,44 +159,29 @@ */ /** - * Extends the given terminal prototype with the public methods of this add-on. + * Converts all valid URLs found in the current terminal linte into + * hyperlinks. * - * @param {function} Xterm - The prototype to be extended. + * @memberof Xterm + * @param {number|HTMLDivElement} line - The terminal line that should get + * "linkified". + * @param {boolean} lenient - The regex type that will be used to identify links. If lenient is + * false, the regex requires a protocol clause. Defaults to true. */ - exports.extendXtermPrototype = function (Xterm) { - /** - * Converts all valid URLs found in the current terminal linte into - * hyperlinks. - * - * @memberof Xterm - * @param {number|HTMLDivElement} line - The terminal line that should get - * "linkified". - * @param {boolean} lenient - The regex type that will be used to identify links. If lenient is - * false, the regex requires a protocol clause. Defaults to true. - */ - Xterm.prototype.linkifyTerminalLine = function (line, lenient) { - return exports.linkifyTerminalLine(this, line, lenient); - }; - - /** - * Converts all valid URLs found in the current terminal into hyperlinks. - * - * @memberof Xterm - * @param {boolean} lenient - The regex type that will be used to identify links. If lenient is - * false, the regex requires a protocol clause. Defaults to true. - */ - Xterm.prototype.linkify = function (lenient) { - return exports.linkify(this, lenient); - }; + Xterm.prototype.linkifyTerminalLine = function (line, lenient) { + return exports.linkifyTerminalLine(this, line, lenient); }; /** - * If the Xterm parameter is a function, then extend it with the methods declared in this - * add-on. + * Converts all valid URLs found in the current terminal into hyperlinks. + * + * @memberof Xterm + * @param {boolean} lenient - The regex type that will be used to identify links. If lenient is + * false, the regex requires a protocol clause. Defaults to true. */ - if (typeof Xterm == 'function') { - exports.extendXtermPrototype(Xterm); - } + Xterm.prototype.linkify = function (lenient) { + return exports.linkify(this, lenient); + }; return exports; });