diff --git a/godoc/static/playground.js b/godoc/static/playground.js index bc82c1c6..70e0c802 100644 --- a/godoc/static/playground.js +++ b/godoc/static/playground.js @@ -228,6 +228,7 @@ function PlaygroundOutput(el) { // outputEl - program output element // runEl - run button element // fmtEl - fmt button element (optional) + // fmtImportEl - fmt "imports" checkbox element (optional) // shareEl - share button element (optional) // shareURLEl - share URL text input element (optional) // shareRedirect - base URL to redirect to on share (optional) @@ -343,10 +344,15 @@ function PlaygroundOutput(el) { loading(); running = transport.Run(body(), highlightOutput(PlaygroundOutput(output[0]))); } + function fmt() { loading(); + var data = {"body": body()}; + if ($(opts.fmtImportEl).is(":checked")) { + data["imports"] = "true"; + } $.ajax("/fmt", { - data: {"body": body()}, + data: data, type: "POST", dataType: "json", success: function(data) { @@ -362,7 +368,7 @@ function PlaygroundOutput(el) { $(opts.runEl).click(run); $(opts.fmtEl).click(fmt); - + if (opts.shareEl !== null && (opts.shareURLEl !== null || opts.shareRedirect !== null)) { var shareURL; if (opts.shareURLEl) { diff --git a/godoc/static/static.go b/godoc/static/static.go index bcfc5352..bb3afbc6 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -1166,6 +1166,7 @@ function PlaygroundOutput(el) { // outputEl - program output element // runEl - run button element // fmtEl - fmt button element (optional) + // fmtImportEl - fmt "imports" checkbox element (optional) // shareEl - share button element (optional) // shareURLEl - share URL text input element (optional) // shareRedirect - base URL to redirect to on share (optional) @@ -1281,10 +1282,15 @@ function PlaygroundOutput(el) { loading(); running = transport.Run(body(), highlightOutput(PlaygroundOutput(output[0]))); } + function fmt() { loading(); + var data = {"body": body()}; + if ($(opts.fmtImportEl).is(":checked")) { + data["imports"] = "true"; + } $.ajax("/fmt", { - data: {"body": body()}, + data: data, type: "POST", dataType: "json", success: function(data) { @@ -1300,7 +1306,7 @@ function PlaygroundOutput(el) { $(opts.runEl).click(run); $(opts.fmtEl).click(fmt); - + if (opts.shareEl !== null && (opts.shareURLEl !== null || opts.shareRedirect !== null)) { var shareURL; if (opts.shareURLEl) {