blob: 53f5351a15844cdef8c018477a2ac036b7b1171a [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,c=!1;a||(console.warn("Must provide playground example element"),c=!0);var b=a.querySelector(PlayExampleClassName.EXAMPLE_ERROR);b||(c=!0);this._errorEl=b;(b=a.querySelector(PlayExampleClassName.PLAY_BUTTON))||(c=!0);this._playButtonEl=b;b=a.querySelector(PlayExampleClassName.EXAMPLE_INPUT);
b||(console.warn("Input element is not detected"),c=!0);this._inputEl=b;this._outputEl=a.querySelector(PlayExampleClassName.EXAMPLE_OUTPUT);c||this._playButtonEl.addEventListener("click",function(a){return d.handlePlayButtonClick(a)})};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(a){return a.text()}).then(function(a){window.open("//play.golang.org/p/"+a)}).catch(function(a){d.setErrorText(a)})};document.querySelectorAll(".js-exampleContainer").forEach(function(a){new PlaygroundExampleController(a)});