_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 <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Website-Publish: Russ Cox <rsc@golang.org>
This commit is contained in:
Russ Cox 2021-12-01 16:44:47 -05:00
Родитель a78844bf24
Коммит 1167ccddc1
1 изменённых файлов: 20 добавлений и 9 удалений

Просмотреть файл

@ -375,16 +375,24 @@ function PlaygroundOutput(el) {
.join('/');
}
var pushedPlay = window.location.pathname == '/play';
var pushedPlay = window.location.pathname == '/play/';
function inputChanged() {
if (pushedPlay) {
return;
}
pushedPlay = true;
$(opts.shareURLEl).hide();
$(opts.toysEl).show();
var path = window.location.pathname;
var i = path.indexOf('/play');
window.history.pushState(null, '', path.substr(0, i+5));
var i = path.indexOf('/play/');
var p = path.substr(0, i+6);
if (opts.versionEl !== null) {
var v = $(opts.versionEl).val();
if (v != '') {
p += '?v=' + v;
}
}
window.history.pushState(null, '', p);
}
function popState(e) {
if (e === null) {
@ -515,8 +523,10 @@ function PlaygroundOutput(el) {
window.location = opts.shareRedirect + xhr.responseText;
}
var path = '/play/p/' + xhr.responseText;
if (opts.versionEl !== null && $(opts.versionEl).val() != "") {
path += "?v=" + $(opts.versionEl).val();
}
var url = origin(window.location) + path;
for (var i = 0; i < shareCallbacks.length; i++) {
shareCallbacks[i](url);
}
@ -529,13 +539,11 @@ function PlaygroundOutput(el) {
.focus()
.select();
if (opts.toysEl !== null) {
$(opts.toysEl).hide();
}
if (rewriteHistory) {
var historyData = { code: sharingData };
window.history.pushState(historyData, '', path);
pushedEmpty = false;
pushedPlay = false;
}
}
},
@ -595,15 +603,18 @@ function PlaygroundOutput(el) {
}
if (opts.versionEl !== null) {
var select = $(opts.versionEl);
var v = (new URL(window.location)).searchParams.get('v');
if (v !== null && v != "") {
var select = $(opts.versionEl)
select.val(v);
if (select.val() != v) {
select.append($('<option>', {value: v, text: 'Backend: ' + v}));
select.val(v);
}
}
if (opts.enableHistory) {
select.bind('change', inputChanged);
}
}
}