Quellcode durchsuchen

minimal editing/evaluation support.

Lucas Stadler vor 12 Jahren
Ursprung
Commit
37863d415c
1 geänderte Dateien mit 53 neuen und 0 gelöschten Zeilen
  1. 53 0
      js/pixl/public/trixl.html

+ 53 - 0
js/pixl/public/trixl.html

@ -4,6 +4,8 @@
4 4
	<title>.trixl</title>
5 5
	<meta charset="utf-8" />
6 6
	<style>
7
		body { overflow: hidden; }
8
7 9
		#stage {
8 10
			position: absolute;
9 11
			top: 0;
@ -453,13 +455,19 @@
453 455
		trixl.speed = { move: 0.1, turn: 0.01 }
454 456
455 457
		trixl.input = {};
458
		trixl.input.active = true;
456 459
		trixl.input.keys = new Set();
460
457 461
		document.addEventListener("keydown", function(ev) {
458 462
			trixl.input.keys.add(ev.keyCode);
459 463
			var isPressed = function(keyCode) {
460 464
				return trixl.input.keys.has(keyCode);
461 465
			}
462 466
467
			if (!trixl.input.active) {
468
				return;
469
			}
470
463 471
			if (isPressed(32)) { // space
464 472
				if (trixl.step.reqId == null) {
465 473
					trixl.start();
@ -538,5 +546,50 @@
538 546
			xhr.send();
539 547
		}
540 548
	</script>
549
	<script>
550
		trixl.ui = {}
551
		var editor = trixl.ui.editor = document.createElement("textarea");
552
		trixl.ui.editor.style = "position: absolute; top: 0; right: 0; height: 100%; width: 30%; overflow: hidden; background-color: transparent";
553
		trixl.ui.editor.style.display = "none";
554
555
		document.body.appendChild(trixl.ui.editor);
556
557
		editor.onfocus = function() { trixl.input.active = false; }
558
		editor.onblur = function() { trixl.input.active = true; }
559
560
		editor.value = localStorage["org.papill0n.trixl.script"] || "";
561
		editor.onchange = function() {
562
			localStorage["org.papill0n.trixl.script"] = editor.value;
563
		}
564
565
		document.addEventListener("keydown", function(ev) {
566
			if (ev.keyCode == 69) { // e
567
				if (editor != document.activeElement) {
568
					if (editor.style.display == "none") {
569
						editor.style.display = "inherit";
570
						editor.focus();
571
					} else {
572
						editor.style.display = "none";
573
					}
574
575
					ev.preventDefault();
576
				}
577
			}
578
579
			if (ev.ctrlKey && ev.keyCode == 13) { // ctrl+enter
580
				if (editor == document.activeElement) {
581
					var sel = editor.value.substr(editor.selectionStart, editor.selectionEnd);
582
					eval(sel);
583
				}
584
			}
585
586
			if (ev.keyCode == 27) { // escape
587
				if (editor == document.activeElement) {
588
					editor.style.display = "none";
589
					editor.blur();
590
				}
591
			}
592
		});
593
	</script>
541 594
</body>
542 595
</html>