blob: 5f26ee07c96301e1c8b4bbd45aa26d22c4e8b926 [file] [log] [blame]
/*
Copyright 2020 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.
*/
var PlayExampleClassName={EXAMPLE_INPUT:".Documentation-exampleCode",EXAMPLE_OUTPUT:".Documentation-exampleOutput",EXAMPLE_ERROR:".Documentation-exampleError",PLAY_BUTTON:".Documentation-examplePlayButton"},PlaygroundExampleController=function(a){var d=this,b=!1;a||(console.warn("Must provide playground example element"),b=!0);var c=a.querySelector(PlayExampleClassName.EXAMPLE_ERROR);c||(b=!0);this._errorEl=c;(c=a.querySelector(PlayExampleClassName.PLAY_BUTTON))||(b=!0);this._playButtonEl=c;c=a.querySelector(PlayExampleClassName.EXAMPLE_INPUT);
c||(console.warn("Input element is not detected"),b=!0);this._inputEl=c;this._outputEl=a.querySelector(PlayExampleClassName.EXAMPLE_OUTPUT);b||this._playButtonEl.addEventListener("click",function(e){return d.handlePlayButtonClick(e)})};PlaygroundExampleController.prototype.setOutputText=function(a){this._outputEl&&(this._outputEl.textContent=a)};PlaygroundExampleController.prototype.setErrorText=function(a){this._errorEl.textContent=a;this.setOutputText("An error has occurred\u2026")};
PlaygroundExampleController.prototype.handlePlayButtonClick=function(a){var d=this;this.setOutputText("Waiting for remote server\u2026");fetch("/play/",{method:"POST",body:this._inputEl.textContent}).then(function(b){return b.text()}).then(function(b){window.open("//play.golang.org/p/"+b)}).catch(function(b){d.setErrorText(b)})};document.querySelectorAll(".js-exampleContainer").forEach(function(a){new PlaygroundExampleController(a)});