diff options
-rw-r--r-- | static/play/play.js | 19 | ||||
-rw-r--r-- | static/script.js | 29 | ||||
-rw-r--r-- | static/style.css | 7 | ||||
-rw-r--r-- | template/root.tmpl | 1 |
4 files changed, 49 insertions, 7 deletions
diff --git a/static/play/play.js b/static/play/play.js index d4540dc..a30ca74 100644 --- a/static/play/play.js +++ b/static/play/play.js @@ -16,7 +16,7 @@ var s = ""; for (var i = 0; i < node.childNodes.length; i++) { var n = node.childNodes[i]; - if (n.nodeType === 1 && n.tagName === "PRE") { + if (n.nodeType === 1 && n.tagName === "SPAN" && n.className != "number") { var innerText = n.innerText === undefined ? "textContent" : "innerText"; s += n[innerText] + "\n"; continue; @@ -35,18 +35,27 @@ var outpre = document.createElement('pre'); var stopFunc; + $(output).resizable({ + handles: "n,w,nw", + minHeight: 27, + minWidth: 135, + maxHeight: 608, + maxWidth: 990 + }); + function onKill() { if (stopFunc) { stopFunc(); } } - - function onRun() { + + function onRun(e) { onKill(); outpre.innerHTML = ""; output.style.display = "block"; run.style.display = "none"; - stopFunc = runFunc(text(code), outpre); + var options = {Race: e.shiftKey}; + stopFunc = runFunc(text(code), outpre, options); } function onClose() { @@ -97,7 +106,7 @@ } if (play.length > 0) { if (window.connectPlayground) { - runFunc = window.connectPlayground("ws://localhost:3999/socket"); + runFunc = window.connectPlayground("ws://" + window.location.host + "/socket"); } else { // If this message is logged, // we have neglected to include socket.js or playground.js. diff --git a/static/script.js b/static/script.js new file mode 100644 index 0000000..8c61b5a --- /dev/null +++ b/static/script.js @@ -0,0 +1,29 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +$(function() { + // Insert line numbers for all playground elements. + $('.playground').each(function() { + var $spans = $(this).find('> pre > span'); + + // Compute width of number column (including trailing space). + var max = 0; + $spans.each(function() { + var n = $(this).attr('num')*1; + if (n > max) max = n; + }); + var width = 2; + while (max > 10) { + max = max / 10; + width++; + } + + // Insert line numbers with space padding. + $spans.each(function() { + var n = $(this).attr('num')+" "; + while (n.length < width) n = " "+n; + $('<span class="number">').text(n).insertBefore(this); + }); + }); +}); diff --git a/static/style.css b/static/style.css index db90fdb..7ab117c 100644 --- a/static/style.css +++ b/static/style.css @@ -119,8 +119,11 @@ body { height: 100%; overflow: auto; } +.playground .number { + color: #999; +} .code, .playground, .output { - margin: 20px; + margin: 20px 0; padding: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; @@ -145,7 +148,7 @@ body { position: relative; float: right; top: -50px; - right: 30px; + right: 10px; } .output .buttons { top: -60px; diff --git a/template/root.tmpl b/template/root.tmpl index 5b2f80e..84ad217 100644 --- a/template/root.tmpl +++ b/template/root.tmpl @@ -87,6 +87,7 @@ <script src="/static/jquery.js"></script> <script src="/static/play/playground.js"></script> <script src="/static/play/play.js"></script> +<script src="/static/script.js"></script> </html> {{end}} |