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:
Andrew Gerrand 2013-12-18 09:32:51 +11:00
Родитель 676ac131e1
Коммит 1de4f6df60
2 изменённых файлов: 16 добавлений и 4 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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) {