diff --git a/addons/fit/fit.js b/addons/fit/fit.js index af1fd6c1..7bc73cd2 100644 --- a/addons/fit/fit.js +++ b/addons/fit/fit.js @@ -14,22 +14,32 @@ Terminal.prototype.fit = function () { var container = this.rowContainer, subjectRow = this.rowContainer.firstElementChild, - rows = parseInt(container.offsetHeight / subjectRow.offsetHeight), + rows, contentBuffer, characterWidth, + characterHeight, cols; - + subjectRow.style.display = 'inline'; contentBuffer = subjectRow.textContent; - subjectRow.textContent = ' '; + subjectRow.innerHTML = ' '; /* Arbitrary character to calculate its dimensions */ characterWidth = parseInt(subjectRow.offsetWidth); + characterHeight = parseInt(subjectRow.offsetHeight); subjectRow.style.display = ''; cols = container.offsetWidth / characterWidth; cols = parseInt(cols); + + var parentElementStyle = window.getComputedStyle(this.element.parentElement), + parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')), + elementStyle = window.getComputedStyle(this.element), + elementPadding = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')), + availableHeight = parentElementHeight - elementPadding; + + rows = parseInt(availableHeight / characterHeight); this.resize(cols, rows); }; \ No newline at end of file diff --git a/demo/index.html b/demo/index.html index b09ffa8e..d1989497 100644 --- a/demo/index.html +++ b/demo/index.html @@ -3,7 +3,7 @@