improve document/element/context handling.

This commit is contained in:
Christopher Jeffrey
2013-08-10 06:46:42 -05:00
parent 1bb83a207d
commit 2f212c6e4d
+13 -5
View File
@@ -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';