mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
improve document/element/context handling.
This commit is contained in:
+13
-5
@@ -138,7 +138,7 @@ function Terminal(options) {
|
||||
|
||||
EventEmitter.call(this);
|
||||
|
||||
if (arguments.length > 1) {
|
||||
if (typeof options === 'number') {
|
||||
options = {
|
||||
cols: arguments[0],
|
||||
rows: arguments[1],
|
||||
@@ -148,9 +148,10 @@ function Terminal(options) {
|
||||
|
||||
this._options = options || {};
|
||||
|
||||
this.context = options.context || window;
|
||||
this.document = options.document || document;
|
||||
this.parent = options.body || options.parent || document.body;
|
||||
// this.context = options.context || window;
|
||||
// this.document = options.document || document;
|
||||
this.parent = options.body || options.parent
|
||||
|| (document ? document.body : null);
|
||||
|
||||
this.cols = options.cols || Terminal.geometry[0];
|
||||
this.rows = options.rows || Terminal.geometry[1];
|
||||
@@ -450,7 +451,14 @@ Terminal.prototype.open = function(parent) {
|
||||
, i = 0
|
||||
, div;
|
||||
|
||||
this.parent = parent || this.parent || document.body;
|
||||
this.parent = parent || this.parent;
|
||||
|
||||
if (!this.parent) {
|
||||
throw new Error('Terminal requires a parent element.');
|
||||
}
|
||||
|
||||
this.context = this.parent.ownerDocument.defaultView;
|
||||
this.document = this.parent.ownerDocument;
|
||||
|
||||
this.element = this.document.createElement('div');
|
||||
this.element.className = 'terminal';
|
||||
|
||||
Reference in New Issue
Block a user