From 4c0f0e48a635ba08a80fbebdb19258a0f675a910 Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Wed, 14 Mar 2018 23:00:17 +0200 Subject: [PATCH] godoc: add vet support to playground.js Playground needs godoc to support calls to /vet endpoint in playground.js. Optional parameter "vetEl" is added to the function "playground". If it's passed then the js installs the click handler to the element. There is a corresponding CL 100776 for the playground code. Updates golang/go#7597 Change-Id: Ica2e7cb9d76f6f19a1805c182e666b8142762da9 Reviewed-on: https://go-review.googlesource.com/100775 Reviewed-by: Andrew Bonventre --- godoc/static/playground.js | 27 +++++++++++++++++++++++++++ godoc/static/static.go | 27 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/godoc/static/playground.js b/godoc/static/playground.js index e8242a08..85c43556 100644 --- a/godoc/static/playground.js +++ b/godoc/static/playground.js @@ -238,6 +238,7 @@ function PlaygroundOutput(el) { // shareEl - share button element (optional) // shareURLEl - share URL text input element (optional) // shareRedirect - base URL to redirect to on share (optional) + // vetEl - vet button element (optional) // toysEl - toys select element (optional) // enableHistory - enable using HTML5 history API (optional) // transport - playground transport to use (default is HTTPTransport) @@ -368,6 +369,11 @@ function PlaygroundOutput(el) { if (running) running.Kill(); output.removeClass("error").text('Waiting for remote server...'); } + function noError() { + lineClear(); + if (running) running.Kill(); + output.removeClass("error").text('No errors.'); + } function run() { loading(); running = transport.Run(body(), highlightOutput(PlaygroundOutput(output[0]))); @@ -394,6 +400,26 @@ function PlaygroundOutput(el) { }); } + function vet() { + loading(); + var data = {"body": body()}; + $.ajax("/vet", { + data: data, + type: "POST", + dataType: "json", + success: function(data) { + if (data.Errors) { + setError(data.Errors); + } else { + noError(); + } + }, + error: function() { + setError('Error communicating with remote server.'); + } + }); + } + var shareURL; // jQuery element to show the shared URL. var sharing = false; // true if there is a pending request. var shareCallbacks = []; @@ -441,6 +467,7 @@ function PlaygroundOutput(el) { $(opts.runEl).click(run); $(opts.fmtEl).click(fmt); + $(opts.vetEl).click(vet); if (opts.shareEl !== null && (opts.shareURLEl !== null || opts.shareRedirect !== null)) { if (opts.shareURLEl) { diff --git a/godoc/static/static.go b/godoc/static/static.go index 19d6db2d..df995130 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -2432,6 +2432,7 @@ function PlaygroundOutput(el) { // shareEl - share button element (optional) // shareURLEl - share URL text input element (optional) // shareRedirect - base URL to redirect to on share (optional) + // vetEl - vet button element (optional) // toysEl - toys select element (optional) // enableHistory - enable using HTML5 history API (optional) // transport - playground transport to use (default is HTTPTransport) @@ -2562,6 +2563,11 @@ function PlaygroundOutput(el) { if (running) running.Kill(); output.removeClass("error").text('Waiting for remote server...'); } + function noError() { + lineClear(); + if (running) running.Kill(); + output.removeClass("error").text('No errors.'); + } function run() { loading(); running = transport.Run(body(), highlightOutput(PlaygroundOutput(output[0]))); @@ -2588,6 +2594,26 @@ function PlaygroundOutput(el) { }); } + function vet() { + loading(); + var data = {"body": body()}; + $.ajax("/vet", { + data: data, + type: "POST", + dataType: "json", + success: function(data) { + if (data.Errors) { + setError(data.Errors); + } else { + noError(); + } + }, + error: function() { + setError('Error communicating with remote server.'); + } + }); + } + var shareURL; // jQuery element to show the shared URL. var sharing = false; // true if there is a pending request. var shareCallbacks = []; @@ -2635,6 +2661,7 @@ function PlaygroundOutput(el) { $(opts.runEl).click(run); $(opts.fmtEl).click(fmt); + $(opts.vetEl).click(vet); if (opts.shareEl !== null && (opts.shareURLEl !== null || opts.shareRedirect !== null)) { if (opts.shareURLEl) {