Merge pull request #125 from sourcelair/addon-loader

Implement addon loader (CommonJS + RequireJS)
This commit is contained in:
Paris Kasidiaris
2016-06-14 00:58:23 +03:00
committed by GitHub
3 changed files with 31 additions and 1 deletions
+20
View File
@@ -759,6 +759,26 @@
this.emit('open');
};
/**
* Attempts to load an add-on using CommonJS or RequireJS (whichever is available).
* @param {string} addon The name of the addon to load
* @static
*/
Terminal.loadAddon = function(addon, callback) {
if (typeof exports === 'object' && typeof module === 'object') {
// CommonJS
return require(__dirname + '/../addons/' + addon);
} else if (typeof define == 'function') {
// RequireJS
return require(['../addons/' + addon + '/' + addon], callback);
} else {
console.error('Cannot load a module without a CommonJS or RequireJS environment.');
return false;
}
};
// XTerm mouse events
// http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
// To better understand these
+10
View File
@@ -0,0 +1,10 @@
var assert = require('chai').assert;
var Terminal = require('../../src/xterm');
describe('xterm.js addons', function() {
it('should load addons with Terminal.loadAddon', function () {
Terminal.loadAddon('attach');
// Test that function was loaded successfully
assert.equal(typeof Terminal.prototype.attach, 'function');
});
});
+1 -1
View File
@@ -79,7 +79,7 @@ describe('xterm.js', function() {
xterm.handler = function() {};
xterm.showCursor = function() {};
xterm.clearSelection = function() {};
})
});
describe('On Mac OS', function() {
beforeEach(function() {