Skip to content

Commit 1f2f193

Browse files
committed
fixed up the CSS for the console, with classnames for applying/overriding styles
1 parent a698015 commit 1f2f193

File tree

4 files changed

+587
-489
lines changed

4 files changed

+587
-489
lines changed

lib/Browser.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ module.exports = (function fakeBrowser() {
1919
localName: tag,
2020
style: {},
2121
setAttribute: __empty_func__,
22-
appendChild: __empty_func__
22+
appendChild: __empty_func__,
23+
classList: {
24+
add: __empty_func__,
25+
remove: __empty_func__,
26+
contains: __empty_func__
27+
}
2328
};
2429
};
2530

processing.js

Lines changed: 85 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -378,39 +378,90 @@ module.exports = {
378378
},{}],5:[function(require,module,exports){
379379
// the logger for println()
380380
module.exports = function PjsConsole(document) {
381-
var e = {}, added = false;
382-
e.BufferMax = 200;
381+
var e = { BufferMax: 200 },
382+
style = document.createElement("style"),
383+
added = false;
383384

384-
e.wrapper = document.createElement("div");
385+
style.textContent = [
386+
".pjsconsole.hidden {",
387+
" display: none!important;",
388+
"}"
389+
].join('\n');
385390

386-
e.wrapper.setAttribute("style", "opacity:.75;display:block;position:fixed;bottom:0px;left:0px;right:0px;height:50px;background-color:#aaa");
391+
e.wrapper = document.createElement("div");
392+
style.textContent += [
393+
"",
394+
".pjsconsole {",
395+
" opacity: .75;",
396+
" display: block;",
397+
" position: fixed;",
398+
" bottom: 0px;",
399+
" left: 0px;",
400+
" right: 0px;",
401+
" height: 50px;",
402+
" background-color: #aaa;",
403+
"}"
404+
].join('\n');
405+
e.wrapper.classList.add("pjsconsole");
387406

388407
e.dragger = document.createElement("div");
389-
390-
e.dragger.setAttribute("style", "display:block;border:3px black raised;cursor:n-resize;position:absolute;top:0px;left:0px;right:0px;height:5px;background-color:#333");
408+
style.textContent += [
409+
"",
410+
".pjsconsole .dragger {",
411+
" display: block;",
412+
" border: 3px black raised;",
413+
" cursor: n-resize;",
414+
" position: absolute;",
415+
" top: 0px;",
416+
" left: 0px;",
417+
" right: 0px;",
418+
" height: 5px;",
419+
" background-color: #333;",
420+
"}"
421+
].join('\n');
422+
e.dragger.classList.add("dragger");
391423

392424
e.closer = document.createElement("div");
393-
394-
e.closer.onmouseover = function () {
395-
e.closer.style.setProperty("background-color", "#ccc");
396-
};
397-
398-
e.closer.onmouseout = function () {
399-
e.closer.style.setProperty("background-color", "#ddd");
400-
};
401-
425+
style.textContent += [
426+
"",
427+
".pjsconsole .closer {",
428+
" opacity: .5;",
429+
" display: block;",
430+
" border: 3px black raised;",
431+
" position: absolute;",
432+
" top: 10px;",
433+
" right: 30px;",
434+
" height: 20px;",
435+
" width: 20px;",
436+
" background-color: #ddd;",
437+
" color: #000;",
438+
" line-height: 20px;",
439+
" text-align: center;",
440+
" cursor: pointer",
441+
"}"
442+
].join('\n');
443+
e.closer.classList.add("closer");
402444
e.closer.innerHTML = "✖";
403445

404-
e.closer.setAttribute("style", "opacity:.5;display:block;border:3px black raised;position:absolute;top:10px;right:30px;height:20px;width:20px;background-color:#ddd;color:#000;line-height:20px;text-align:center;cursor:pointer;");
405-
406446
e.javaconsole = document.createElement("div");
407-
408-
e.javaconsole.setAttribute("style", "overflow-x: auto;display:block;position:absolute;left:10px;right:0px;bottom:5px;top:10px;overflow-y:scroll;height:40px;");
447+
style.textContent += [
448+
"",
449+
".pjsconsole .console {",
450+
" overflow-x: auto;",
451+
" display: block;",
452+
" position: absolute;",
453+
" left: 10px;",
454+
" right: 0px;",
455+
" bottom: 5px;",
456+
" top: 10px;",
457+
" overflow-y: scroll;",
458+
" height: 40px;",
459+
"}"
460+
].join('\n');
461+
e.javaconsole.setAttribute("class", "console");
409462

410463
e.wrapper.appendChild(e.dragger);
411-
412464
e.wrapper.appendChild(e.javaconsole);
413-
414465
e.wrapper.appendChild(e.closer);
415466

416467
e.dragger.onmousedown = function (t) {
@@ -440,33 +491,28 @@ module.exports = function PjsConsole(document) {
440491
if (e.BufferArray[e.BufferArray.length - 1]) e.BufferArray[e.BufferArray.length - 1] += (t) + "";
441492
else e.BufferArray.push(t);
442493
e.javaconsole.innerHTML = e.BufferArray.join('');
443-
if (e.wrapper.style.visibility === "hidden") {
444-
e.wrapper.style.visibility = "visible";
445-
}
446-
if (e.wrapper.style.visibility === "hidden") {
447-
e.wrapper.style.visibility = "visible";
448-
}
494+
e.showconsole();
449495
};
450496

451497
e.println = function () {
452-
if(!added) { document.body.appendChild(e.wrapper); }
498+
if(!added) {
499+
document.body.appendChild(style);
500+
document.body.appendChild(e.wrapper);
501+
}
453502
var args = Array.prototype.slice.call(arguments);
454503
args.push('<br>');
455504
e.print.apply(e, args);
456-
if (e.BufferArray.length > e.BufferMax) e.BufferArray.splice(0, 1);
457-
else e.javaconsole.scrollTop = e.javaconsole.scrollHeight;
458-
};
459-
e.showconsole = function () {
460-
e.wrapper.style.visibility = "visible";
505+
if (e.BufferArray.length > e.BufferMax) {
506+
e.BufferArray.splice(0, 1);
507+
} else {
508+
e.javaconsole.scrollTop = e.javaconsole.scrollHeight;
509+
}
461510
};
462511

463-
e.hideconsole = function () {
464-
e.wrapper.style.visibility = "hidden";
465-
};
512+
e.showconsole = function () { e.wrapper.classList.remove("hidden"); };
513+
e.hideconsole = function () { e.wrapper.classList.add("hidden"); };
466514

467-
e.closer.onclick = function () {
468-
e.hideconsole();
469-
};
515+
e.closer.onclick = function () { e.hideconsole(); };
470516

471517
e.hideconsole();
472518

0 commit comments

Comments
 (0)