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
This commit is contained in:
Paris
2016-05-03 12:48:16 +03:00
parent fff56eea1b
commit dc67c94545
4 changed files with 46 additions and 106 deletions
+17 -32
View File
@@ -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;
});
+6 -21
View File
@@ -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;
});
+3 -18
View File
@@ -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;
});
+20 -35
View File
@@ -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;
});