Skip to content

Commit 698dcb4

Browse files
Freeze because of size calculations when iframe is not visible fix, dependencies update
1 parent 6934d9a commit 698dcb4

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"printableName": "Cache Web Terminal",
66
"description": "Web-based terminal emulator for Caché administering.",
77
"author": "ZitRo",
8-
"version": "4.0.0-beta.10",
8+
"version": "4.0.0-beta.11",
99
"gaID": "UA-83005064-2",
1010
"releaseNumber": 26,
1111
"scripts": {
@@ -20,16 +20,16 @@
2020
"babel-polyfill": "^6.9.1",
2121
"babel-preset-es2015": "^6.9.0",
2222
"babelify": "^7.3.0",
23-
"browserify": "^13.0.1",
23+
"browserify": "^13.1.1",
2424
"gulp": "^3.9.1",
2525
"gulp-cssnano": "^2.1.2",
2626
"gulp-minify-css": "^1.2.4",
2727
"gulp-preprocess": "^2.0.0",
2828
"gulp-rename": "^1.2.2",
2929
"gulp-replace": "^0.5.4",
3030
"gulp-rimraf": "^0.2.0",
31-
"gulp-sass": "^2.3.1",
32-
"gulp-uglify": "^1.5.3",
31+
"gulp-sass": "^3.0.0",
32+
"gulp-uglify": "^2.0.0",
3333
"preprocessify": "^1.0.1",
3434
"vinyl-buffer": "^1.0.0",
3535
"vinyl-source-stream": "^1.1.0"

src/client/js/output/index.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,10 @@ function output (plainText = "") {
409409
*/
410410
export function getLineByIndex (index) {
411411

412-
var toPush = Math.max(index - lines.length + 1, 0);
412+
let toPush = Math.max(index - lines.length + 1, 0);
413+
414+
if (index > 100)
415+
throw new Error(`Petuh inc.`);
413416

414417
if (toPush > 0)
415418
pushLines(toPush);
@@ -463,10 +466,11 @@ export function scrollDown () {
463466
*/
464467
function sizeChanged () {
465468

466-
var tel = document.createElement("span"),
469+
let tel = document.createElement("span"),
467470
testScrollbar = document.createElement("div"),
468471
scrollBarWidth,
469-
lastOverflowProperty = elements.output.style.overflowY;
472+
lastOverflowProperty = elements.output.style.overflowY,
473+
ow, oh;
470474

471475
elements.output.style.overflowY = "scroll";
472476
testScrollbar.className = LINE_CLASS_NAME;
@@ -478,15 +482,29 @@ function sizeChanged () {
478482
tel.innerHTML = "XXXXXXXXXX";
479483
testScrollbar.appendChild(tel);
480484

481-
SYMBOL_WIDTH = tel.offsetWidth / 10;
482-
SYMBOL_HEIGHT = tel.offsetHeight;
485+
SYMBOL_WIDTH = (tel.offsetWidth / 10) || 8.8;
486+
SYMBOL_HEIGHT = tel.offsetHeight || 19;
483487

484-
WIDTH = Math.floor( (elements.terminal.offsetWidth - scrollBarWidth) / SYMBOL_WIDTH );
485-
HEIGHT = Math.floor( elements.terminal.offsetHeight / SYMBOL_HEIGHT );
488+
WIDTH = (ow = Math.floor( (elements.terminal.offsetWidth - scrollBarWidth) / SYMBOL_WIDTH ))
489+
|| SYMBOL_HEIGHT * 32;
490+
HEIGHT = (oh = Math.floor( elements.terminal.offsetHeight / SYMBOL_HEIGHT ))
491+
|| SYMBOL_WIDTH * 80;
486492

487493
elements.input.style.width = `${ WIDTH * SYMBOL_WIDTH }px`;
488494

489495
elements.output.removeChild(testScrollbar);
496+
497+
// In case of custom styling when integrating WebTerminal to other solutions, the WebTerminal
498+
// may be hidden on the page by default. This will cause WebTerminal to set up wrong
499+
// width/height (= 0). This block yields the size calculation until the parent element appears
500+
// on the page.
501+
if (!ow || !oh) {
502+
setTimeout(sizeChanged, 25);
503+
let m = `[WebTerminal] Size calculations delayed for 25s due to WebTerminal is not`
504+
+ ` attached to the page. If this message doesn't stop appearing, check if`
505+
+ ` WebTerminal's iFrame is visible and is attached to the DOM.`;
506+
try { console.warn(m); } catch (e) { console.log(m); }
507+
}
490508

491509
// elements.output.style.width = `${ WIDTH * SYMBOL_WIDTH + scrollBarWidth }px`;
492510
// elements.output.style.height = `${ HEIGHT * SYMBOL_HEIGHT }px`; = 100%

0 commit comments

Comments
 (0)