go.tools/godoc/static: add 'fmtImportEl' option to playground
The 'fmtImportEl' option lets the called specify a checkbox element that determines whether to send the 'imports=true' key/value pair when calling '/fmt'. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/43240043
This commit is contained in:
parent
676ac131e1
commit
1de4f6df60
|
|
@ -228,6 +228,7 @@ function PlaygroundOutput(el) {
|
||||||
// outputEl - program output element
|
// outputEl - program output element
|
||||||
// runEl - run button element
|
// runEl - run button element
|
||||||
// fmtEl - fmt button element (optional)
|
// fmtEl - fmt button element (optional)
|
||||||
|
// fmtImportEl - fmt "imports" checkbox element (optional)
|
||||||
// shareEl - share button element (optional)
|
// shareEl - share button element (optional)
|
||||||
// shareURLEl - share URL text input element (optional)
|
// shareURLEl - share URL text input element (optional)
|
||||||
// shareRedirect - base URL to redirect to on share (optional)
|
// shareRedirect - base URL to redirect to on share (optional)
|
||||||
|
|
@ -343,10 +344,15 @@ function PlaygroundOutput(el) {
|
||||||
loading();
|
loading();
|
||||||
running = transport.Run(body(), highlightOutput(PlaygroundOutput(output[0])));
|
running = transport.Run(body(), highlightOutput(PlaygroundOutput(output[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
function fmt() {
|
function fmt() {
|
||||||
loading();
|
loading();
|
||||||
|
var data = {"body": body()};
|
||||||
|
if ($(opts.fmtImportEl).is(":checked")) {
|
||||||
|
data["imports"] = "true";
|
||||||
|
}
|
||||||
$.ajax("/fmt", {
|
$.ajax("/fmt", {
|
||||||
data: {"body": body()},
|
data: data,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
|
@ -362,7 +368,7 @@ function PlaygroundOutput(el) {
|
||||||
|
|
||||||
$(opts.runEl).click(run);
|
$(opts.runEl).click(run);
|
||||||
$(opts.fmtEl).click(fmt);
|
$(opts.fmtEl).click(fmt);
|
||||||
|
|
||||||
if (opts.shareEl !== null && (opts.shareURLEl !== null || opts.shareRedirect !== null)) {
|
if (opts.shareEl !== null && (opts.shareURLEl !== null || opts.shareRedirect !== null)) {
|
||||||
var shareURL;
|
var shareURL;
|
||||||
if (opts.shareURLEl) {
|
if (opts.shareURLEl) {
|
||||||
|
|
|
||||||
|
|
@ -1166,6 +1166,7 @@ function PlaygroundOutput(el) {
|
||||||
// outputEl - program output element
|
// outputEl - program output element
|
||||||
// runEl - run button element
|
// runEl - run button element
|
||||||
// fmtEl - fmt button element (optional)
|
// fmtEl - fmt button element (optional)
|
||||||
|
// fmtImportEl - fmt "imports" checkbox element (optional)
|
||||||
// shareEl - share button element (optional)
|
// shareEl - share button element (optional)
|
||||||
// shareURLEl - share URL text input element (optional)
|
// shareURLEl - share URL text input element (optional)
|
||||||
// shareRedirect - base URL to redirect to on share (optional)
|
// shareRedirect - base URL to redirect to on share (optional)
|
||||||
|
|
@ -1281,10 +1282,15 @@ function PlaygroundOutput(el) {
|
||||||
loading();
|
loading();
|
||||||
running = transport.Run(body(), highlightOutput(PlaygroundOutput(output[0])));
|
running = transport.Run(body(), highlightOutput(PlaygroundOutput(output[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
function fmt() {
|
function fmt() {
|
||||||
loading();
|
loading();
|
||||||
|
var data = {"body": body()};
|
||||||
|
if ($(opts.fmtImportEl).is(":checked")) {
|
||||||
|
data["imports"] = "true";
|
||||||
|
}
|
||||||
$.ajax("/fmt", {
|
$.ajax("/fmt", {
|
||||||
data: {"body": body()},
|
data: data,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
|
@ -1300,7 +1306,7 @@ function PlaygroundOutput(el) {
|
||||||
|
|
||||||
$(opts.runEl).click(run);
|
$(opts.runEl).click(run);
|
||||||
$(opts.fmtEl).click(fmt);
|
$(opts.fmtEl).click(fmt);
|
||||||
|
|
||||||
if (opts.shareEl !== null && (opts.shareURLEl !== null || opts.shareRedirect !== null)) {
|
if (opts.shareEl !== null && (opts.shareURLEl !== null || opts.shareRedirect !== null)) {
|
||||||
var shareURL;
|
var shareURL;
|
||||||
if (opts.shareURLEl) {
|
if (opts.shareURLEl) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue