mirror_xterm.js/addons/fullscreen/fullscreen.js
Paris fff56eea1b Extend Xterm prototype only when Xterm is a function
Add-ons attempted to extend the `Xterm` prototype no matter what. This was an issue when importing add-ons through CommonJS, where `Xterm` is not available in the global scope.
2016-05-03 12:36:21 +03:00

68 lines
1.7 KiB
JavaScript

/*
* Fullscreen addon for xterm.js
*
* Implements the toggleFullscreen function.
*
* If the `fullscreen` argument has been supplied, then
* if it is true, the fullscreen mode gets turned on,
* if it is false or null, the fullscreen mode gets turned off.
*
* If the `fullscreen` argument has not been supplied, the
* fullscreen mode is being toggled.
*/
(function (fullscreen) {
if (typeof exports === 'object' && typeof module === 'object') {
/*
* CommonJS environment
*/
module.exports = fullscreen.call(this);
} else if (typeof define == 'function') {
/*
* Require.js is available
*/
define(['../../src/xterm'], fullscreen);
} else {
/*
* Plain browser environment
*/
fullscreen(this.Xterm);
}
})(function (Xterm) {
var exports = {};
exports.toggleFullScreen = function (term, fullscreen) {
var fn;
if (typeof fullscreen == 'undefined') {
fn = (term.element.classList.contains('fullscreen')) ? 'remove' : 'add';
} else if (!fullscreen) {
fn = 'remove';
} else {
fn = 'add';
}
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);
};
};
/**
* 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;
});