Skip to content

Commit cc46515

Browse files
committed
Merge pull request #15 from gopherjs/fix/suboptimal-sharing-url
Use location of topmost window.
2 parents 5501e13 + 2a33516 commit cc46515

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

‎playground/playground.go‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ var output []Line
2424
constsnippetStoreHost="snippets.gotools.org"
2525

2626
funcmain(){
27+
varlocation=dom.GetWindow().Top().Location() // We might be inside an iframe, but want to use the location of topmost window.
28+
2729
codeReady:=make(chanstruct{}) // Used to synchronize when "code" value is ready.
2830

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

3133
app.NewController("PlaygroundCtrl", func(scope*angularjs.Scope){
32-
ifstrings.HasPrefix(dom.GetWindow().Location().Hash, "#/"){
33-
id:=dom.GetWindow().Location().Hash[2:]
34+
ifstrings.HasPrefix(location.Hash, "#/"){
35+
id:=location.Hash[2:]
3436

3537
req:=xhr.NewRequest("GET", "http://"+snippetStoreHost+"/p/"+id)
3638
req.ResponseType=xhr.ArrayBuffer
@@ -75,7 +77,7 @@ func main(){
7577
codeArea:=angularjs.ElementById("code")
7678
codeArea.On("input", func(e*angularjs.Event){
7779
scope.Set("showShareUrl", false)
78-
dom.GetWindow().Location().Hash=""
80+
location.Hash=""
7981
})
8082
codeArea.On("keydown", func(e*angularjs.Event){
8183
toInsert:=""
@@ -98,7 +100,7 @@ func main(){
98100
}
99101
iftoInsert!=""{
100102
scope.Set("showShareUrl", false)
101-
dom.GetWindow().Location().Hash=""
103+
location.Hash=""
102104

103105
start:=codeArea.Prop("selectionStart").Int()
104106
end:=codeArea.Prop("selectionEnd").Int()
@@ -232,9 +234,9 @@ func main(){
232234
scope.Apply(func(){
233235
id:=string(data)
234236

235-
dom.GetWindow().Location().Hash="#/"+id
237+
location.Hash="#/"+id
236238

237-
scope.Set("shareUrl", dom.GetWindow().Location().Str())
239+
scope.Set("shareUrl", location.Str())
238240
scope.Set("showShareUrl", true)
239241
// TODO: Do this better using AngularJS.
240242
// Perhaps using http://stackoverflow.com/questions/14833326/how-to-set-focus-on-input-field/18295416.

‎playground/playground.js‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54536,7 +54536,7 @@ $packages["github.com/gopherjs/gopherjs/compiler"] = (function(){
5453654536
return new ImportContext.Ptr((_map = new $Map(), _key = "unsafe", _map[_key] ={k: _key, v: types.Unsafe }, _map), importFunc);
5453754537
};
5453854538
Compile = $pkg.Compile = function(importPath, files, fileSet, importContext, minify){
54539-
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;
54539+
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;
5454054540
info = new types.Info.Ptr(new $Map(), new $Map(), new $Map(), new $Map(), new $Map(), false, sliceType$10.nil);
5454154541
importError = $ifaceNil;
5454254542
errList = ErrorList.nil;
@@ -64604,13 +64604,14 @@ $packages["main"] = (function(){
6460464604
time = $packages["time"];
6460564605
Line = $pkg.Line = $newType(4, $kindMap, "main.Line", "Line", "main", null);
6460664606
main = function(){
64607-
var codeReady, app;
64607+
var location, codeReady, app;
64608+
location = dom.GetWindow().Top().Location();
6460864609
codeReady = new chanType(0);
6460964610
app = angularjs.NewModule("playground", sliceType$1.nil, $throwNilPointerError);
6461064611
app.NewController("PlaygroundCtrl", (function(scope){
6461164612
var id, req, packages, pkgsToLoad, importContext, fileSet, pkgsReceived, codeArea, run;
64612-
if (strings.HasPrefix($internalize(dom.GetWindow().Location().URLUtils.Object.hash, $String), "#/")){
64613-
id = $internalize(dom.GetWindow().Location().URLUtils.Object.hash, $String).substring(2);
64613+
if (strings.HasPrefix($internalize(location.URLUtils.Object.hash, $String), "#/")){
64614+
id = $internalize(location.URLUtils.Object.hash, $String).substring(2);
6461464615
req = xhr.NewRequest("GET", "http://snippets.gotools.org/p/" + id);
6461564616
req.Object.responseType = $externalize("arraybuffer", $String);
6461664617
$go((function($b){
@@ -64657,7 +64658,7 @@ $packages["main"] = (function(){
6465764658
codeArea = angularjs.ElementById("code");
6465864659
codeArea.On("input", (function(e){
6465964660
scope.Object.showShareUrl = $externalize(false, $Bool);
64660-
dom.GetWindow().Location().URLUtils.Object.hash = $externalize("", $String);
64661+
location.URLUtils.Object.hash = $externalize("", $String);
6466164662
}));
6466264663
codeArea.On("keydown", (function(e){
6466364664
var toInsert, _ref, start, code, i, c, start$1, end, code$1;
@@ -64681,7 +64682,7 @@ $packages["main"] = (function(){
6468164682
}
6468264683
if (!(toInsert === "")){
6468364684
scope.Object.showShareUrl = $externalize(false, $Bool);
64684-
dom.GetWindow().Location().URLUtils.Object.hash = $externalize("", $String);
64685+
location.URLUtils.Object.hash = $externalize("", $String);
6468564686
start$1 = $parseInt(codeArea.Prop("selectionStart")) >> 0;
6468664687
end = $parseInt(codeArea.Prop("selectionEnd")) >> 0;
6468764688
code$1 = $internalize(scope.Object.code, $String);
@@ -64833,8 +64834,8 @@ $packages["main"] = (function(){
6483364834
scope.Apply((function(){
6483464835
var id$1;
6483564836
id$1 = $bytesToString(data);
64836-
dom.GetWindow().Location().URLUtils.Object.hash = $externalize("#/" + id$1, $String);
64837-
scope.Object.shareUrl = $externalize($internalize(dom.GetWindow().Location().Object, $String), $String);
64837+
location.URLUtils.Object.hash = $externalize("#/" + id$1, $String);
64838+
scope.Object.shareUrl = $externalize($internalize(location.Object, $String), $String);
6483864839
scope.Object.showShareUrl = $externalize(true, $Bool);
6483964840
$go((function($b){
6484064841
var $this = this, $args = arguments, $r, $s = 0;

0 commit comments

Comments
(0)