Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ var output []Line
const snippetStoreHost = "snippets.gotools.org"

func main() {
var location = dom.GetWindow().Top().Location() // We might be inside an iframe, but want to use the location of topmost window.

codeReady := make(chan struct{}) // Used to synchronize when "code" value is ready.

app := angularjs.NewModule("playground", nil, nil)

app.NewController("PlaygroundCtrl", func(scope *angularjs.Scope) {
if strings.HasPrefix(dom.GetWindow().Location().Hash, "#/") {
id := dom.GetWindow().Location().Hash[2:]
if strings.HasPrefix(location.Hash, "#/") {
id := location.Hash[2:]

req := xhr.NewRequest("GET", "http://"+snippetStoreHost+"/p/"+id)
req.ResponseType = xhr.ArrayBuffer
Expand Down Expand Up @@ -75,7 +77,7 @@ func main() {
codeArea := angularjs.ElementById("code")
codeArea.On("input", func(e *angularjs.Event) {
scope.Set("showShareUrl", false)
dom.GetWindow().Location().Hash = ""
location.Hash = ""
})
codeArea.On("keydown", func(e *angularjs.Event) {
toInsert := ""
Expand All @@ -98,7 +100,7 @@ func main() {
}
if toInsert != "" {
scope.Set("showShareUrl", false)
dom.GetWindow().Location().Hash = ""
location.Hash = ""

start := codeArea.Prop("selectionStart").Int()
end := codeArea.Prop("selectionEnd").Int()
Expand Down Expand Up @@ -232,9 +234,9 @@ func main() {
scope.Apply(func() {
id := string(data)

dom.GetWindow().Location().Hash = "#/" + id
location.Hash = "#/" + id

scope.Set("shareUrl", dom.GetWindow().Location().Str())
scope.Set("shareUrl", location.Str())
scope.Set("showShareUrl", true)
// TODO: Do this better using AngularJS.
// Perhaps using http://stackoverflow.com/questions/14833326/how-to-set-focus-on-input-field/18295416.
Expand Down
17 changes: 9 additions & 8 deletions playground/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -54536,7 +54536,7 @@ $packages["github.com/gopherjs/gopherjs/compiler"] = (function() {
return new ImportContext.Ptr((_map = new $Map(), _key = "unsafe", _map[_key] = { k: _key, v: types.Unsafe }, _map), importFunc);
};
Compile = $pkg.Compile = function(importPath, files, fileSet, importContext, minify) {
var info, importError, errList, previousErr, config, _tuple, typesPkg, err, pos, _tuple$1, last, ok, x, _key, gcData, encodedFileSet, err$1, _map, _key$1, c, _ref, _i, _keys, _entry, name, _key$2, importDecls, importedPaths, _ref$1, _i$1, importedPkg, _key$3, _ref$2, _i$2, impPath, _entry$1, id, call, _key$4, _key$5, _entry$2, _entry$3, functions, vars, _ref$3, _i$3, file, _ref$4, _i$4, _keys$1, _entry$4, k, v, _key$6, _ref$5, _i$5, decl, d, _ref$6, _entry$5, sig, recvType, _tuple$2, ptr, isPtr, _entry$6, o, context, _key$7, _ref$7, _ref$8, _i$6, spec, _entry$7, o$1, _ref$9, _i$7, spec$1, _ref$10, _i$8, name$1, _entry$8, o$2, done, _ref$11, _i$9, _keys$2, _entry$9, context$1, _ref$12, _i$10, _keys$3, _entry$10, obj, calls, _entry$11, _ref$13, _i$11, call$1, collectDependencies, varDecls, varsWithInit, _ref$14, _i$12, init$1, _ref$15, _i$13, o$3, _key$8, _ref$16, _i$14, d$1, o$4, _tuple$3, _entry$12, ok$1, _ref$17, _i$15, d$2, lhs, init$2, _ref$18, _i$16, i, o$5, ident, _key$9, _key$10, v$1, x$1, funcDecls, mainFunc, _ref$19, _i$17, o$6, d$3, context$2, fun, _entry$13, _entry$14, _ref$20, recvType$1, _tuple$4, ptr$1, isPointer, _tuple$5, namedRecvType, id$1, _key$11, call$2, typeDecls, _ref$21, _i$18, d$4, o$7, typeName, anonTypeDecls, _ref$22, _i$19, d$5, t, _entry$15, allDecls, _ref$23, _i$20, d$6;
var info, importError, errList, previousErr, config, _tuple, typesPkg, err, pos, _tuple$1, last, ok, x, _key, gcData, encodedFileSet, err$1, _map, _key$1, c, _ref, _i, _keys, _entry, name, _key$2, importDecls, importedPaths, _ref$1, _i$1, importedPkg, _key$3, _ref$2, _i$2, impPath, _entry$1, id, call, _key$4, _key$5, _entry$2, _entry$3, functions, vars, _ref$3, _i$3, file, _ref$4, _i$4, _keys$1, _entry$4, k, v, _key$6, _ref$5, _i$5, decl, d, _ref$6, _entry$5, sig, recvType, _tuple$2, ptr, isPtr, _entry$6, o, context, _key$7, _ref$7, _ref$8, _i$6, spec, _entry$7, o$1, _ref$9, _i$7, spec$1, _ref$10, _i$8, name$1, _entry$8, o$2, done, _ref$11, _i$9, _keys$2, _entry$9, context$1, _ref$12, _i$10, _keys$3, _entry$10, obj, calls, _entry$11, _ref$13, _i$11, call$1, collectDependencies, varDecls, varsWithInit, _ref$14, _i$12, init$1, _ref$15, _i$13, o$3, _key$8, _ref$16, _i$14, d$1, o$4, _tuple$3, _entry$12, ok$1, _ref$17, _i$15, d$2, lhs, init$2, _ref$18, _i$16, i, o$5, ident, _key$9, _key$10, v$1, x$1, funcDecls, mainFunc, _ref$19, _i$17, d$3, context$2, o$6, fun, _entry$13, _entry$14, _ref$20, recvType$1, _tuple$4, ptr$1, isPointer, _tuple$5, namedRecvType, id$1, _key$11, call$2, typeDecls, _ref$21, _i$18, d$4, o$7, typeName, anonTypeDecls, _ref$22, _i$19, d$5, t, _entry$15, allDecls, _ref$23, _i$20, d$6;
info = new types.Info.Ptr(new $Map(), new $Map(), new $Map(), new $Map(), new $Map(), false, sliceType$10.nil);
importError = $ifaceNil;
errList = ErrorList.nil;
Expand Down Expand Up @@ -64604,13 +64604,14 @@ $packages["main"] = (function() {
time = $packages["time"];
Line = $pkg.Line = $newType(4, $kindMap, "main.Line", "Line", "main", null);
main = function() {
var codeReady, app;
var location, codeReady, app;
location = dom.GetWindow().Top().Location();
codeReady = new chanType(0);
app = angularjs.NewModule("playground", sliceType$1.nil, $throwNilPointerError);
app.NewController("PlaygroundCtrl", (function(scope) {
var id, req, packages, pkgsToLoad, importContext, fileSet, pkgsReceived, codeArea, run;
if (strings.HasPrefix($internalize(dom.GetWindow().Location().URLUtils.Object.hash, $String), "#/")) {
id = $internalize(dom.GetWindow().Location().URLUtils.Object.hash, $String).substring(2);
if (strings.HasPrefix($internalize(location.URLUtils.Object.hash, $String), "#/")) {
id = $internalize(location.URLUtils.Object.hash, $String).substring(2);
req = xhr.NewRequest("GET", "http://snippets.gotools.org/p/" + id);
req.Object.responseType = $externalize("arraybuffer", $String);
$go((function($b) {
Expand Down Expand Up @@ -64657,7 +64658,7 @@ $packages["main"] = (function() {
codeArea = angularjs.ElementById("code");
codeArea.On("input", (function(e) {
scope.Object.showShareUrl = $externalize(false, $Bool);
dom.GetWindow().Location().URLUtils.Object.hash = $externalize("", $String);
location.URLUtils.Object.hash = $externalize("", $String);
}));
codeArea.On("keydown", (function(e) {
var toInsert, _ref, start, code, i, c, start$1, end, code$1;
Expand All @@ -64681,7 +64682,7 @@ $packages["main"] = (function() {
}
if (!(toInsert === "")) {
scope.Object.showShareUrl = $externalize(false, $Bool);
dom.GetWindow().Location().URLUtils.Object.hash = $externalize("", $String);
location.URLUtils.Object.hash = $externalize("", $String);
start$1 = $parseInt(codeArea.Prop("selectionStart")) >> 0;
end = $parseInt(codeArea.Prop("selectionEnd")) >> 0;
code$1 = $internalize(scope.Object.code, $String);
Expand Down Expand Up @@ -64833,8 +64834,8 @@ $packages["main"] = (function() {
scope.Apply((function() {
var id$1;
id$1 = $bytesToString(data);
dom.GetWindow().Location().URLUtils.Object.hash = $externalize("#/" + id$1, $String);
scope.Object.shareUrl = $externalize($internalize(dom.GetWindow().Location().Object, $String), $String);
location.URLUtils.Object.hash = $externalize("#/" + id$1, $String);
scope.Object.shareUrl = $externalize($internalize(location.Object, $String), $String);
scope.Object.showShareUrl = $externalize(true, $Bool);
$go((function($b) {
var $this = this, $args = arguments, $r, $s = 0;
Expand Down