Skip to content

Commit 1167ccd

Browse files
committed
_content: update /play/ url to show ?v= for gotip usage
Show ?v=gotip when 'Go dev branch' is selected in the dropdown, and then also add it to playground shares. Change-Id: I38e74a9cc6285b71269f9edf2e958e1bb46def55 Reviewed-on: https://go-review.googlesource.com/c/website/+/368361 Trust: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]> Website-Publish: Russ Cox <[email protected]>
1 parent a78844b commit 1167ccd

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

_content/js/playground.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,24 @@ function PlaygroundOutput(el) {
375375
.join('/');
376376
}
377377

378-
var pushedPlay = window.location.pathname == '/play';
378+
var pushedPlay = window.location.pathname == '/play/';
379379
function inputChanged() {
380380
if (pushedPlay) {
381381
return;
382382
}
383383
pushedPlay = true;
384384
$(opts.shareURLEl).hide();
385+
$(opts.toysEl).show();
385386
var path = window.location.pathname;
386-
var i = path.indexOf('/play');
387-
window.history.pushState(null, '', path.substr(0, i+5));
387+
var i = path.indexOf('/play/');
388+
var p = path.substr(0, i+6);
389+
if (opts.versionEl !== null) {
390+
var v = $(opts.versionEl).val();
391+
if (v != '') {
392+
p += '?v=' + v;
393+
}
394+
}
395+
window.history.pushState(null, '', p);
388396
}
389397
function popState(e) {
390398
if (e === null) {
@@ -515,8 +523,10 @@ function PlaygroundOutput(el) {
515523
window.location = opts.shareRedirect + xhr.responseText;
516524
}
517525
var path = '/play/p/' + xhr.responseText;
526+
if (opts.versionEl !== null && $(opts.versionEl).val() != "") {
527+
path += "?v=" + $(opts.versionEl).val();
528+
}
518529
var url = origin(window.location) + path;
519-
520530
for (var i = 0; i < shareCallbacks.length; i++) {
521531
shareCallbacks[i](url);
522532
}
@@ -529,13 +539,11 @@ function PlaygroundOutput(el) {
529539
.focus()
530540
.select();
531541

532-
if (opts.toysEl !== null) {
533-
$(opts.toysEl).hide();
534-
}
542+
$(opts.toysEl).hide();
535543
if (rewriteHistory) {
536544
var historyData = { code: sharingData };
537545
window.history.pushState(historyData, '', path);
538-
pushedEmpty = false;
546+
pushedPlay = false;
539547
}
540548
}
541549
},
@@ -595,15 +603,18 @@ function PlaygroundOutput(el) {
595603
}
596604

597605
if (opts.versionEl !== null) {
606+
var select = $(opts.versionEl);
598607
var v = (new URL(window.location)).searchParams.get('v');
599608
if (v !== null && v != "") {
600-
var select = $(opts.versionEl)
601609
select.val(v);
602610
if (select.val() != v) {
603611
select.append($('<option>', {value: v, text: 'Backend: ' + v}));
604612
select.val(v);
605613
}
606614
}
615+
if (opts.enableHistory) {
616+
select.bind('change', inputChanged);
617+
}
607618
}
608619
}
609620

0 commit comments

Comments
 (0)