mirror of
https://github.com/golang/go
synced 2024-11-21 21:14:47 -07:00
doc: support redirect-on-share
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5689056
This commit is contained in:
parent
d36426995a
commit
1a1940c870
@ -8,6 +8,7 @@
|
|||||||
// runEl - run button element
|
// runEl - run button element
|
||||||
// shareEl - share button element (optional)
|
// shareEl - share button element (optional)
|
||||||
// shareURLEl - share URL text input element (optional)
|
// shareURLEl - share URL text input element (optional)
|
||||||
|
// shareRedirect - base URL to redirect to on share (optional)
|
||||||
// preCompile - callback to mutate request data before compiling
|
// preCompile - callback to mutate request data before compiling
|
||||||
// postCompile - callback to read response data after compiling
|
// postCompile - callback to read response data after compiling
|
||||||
// simple - use plain textarea instead of CodeMirror.
|
// simple - use plain textarea instead of CodeMirror.
|
||||||
@ -163,7 +164,7 @@ function playground(opts) {
|
|||||||
}
|
}
|
||||||
$(opts['runEl']).click(run);
|
$(opts['runEl']).click(run);
|
||||||
|
|
||||||
if (opts['shareEl'] == null || opts['shareURLEl'] == null) {
|
if (opts['shareEl'] == null || (opts['shareURLEl'] == null && opts['shareRedirect'] == null)) {
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +172,10 @@ function playground(opts) {
|
|||||||
return (""+href).split("/").slice(0, 3).join("/");
|
return (""+href).split("/").slice(0, 3).join("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
var shareURL = $(opts['shareURLEl']).hide();
|
var shareURL;
|
||||||
|
if (opts['shareURLEl']) {
|
||||||
|
shareURL = $(opts['shareURLEl']).hide();
|
||||||
|
}
|
||||||
var sharing = false;
|
var sharing = false;
|
||||||
$(opts['shareEl']).click(function() {
|
$(opts['shareEl']).click(function() {
|
||||||
if (sharing) return;
|
if (sharing) return;
|
||||||
@ -184,12 +188,17 @@ function playground(opts) {
|
|||||||
sharing = false;
|
sharing = false;
|
||||||
if (xhr.status != 200) {
|
if (xhr.status != 200) {
|
||||||
alert("Server error; try again.");
|
alert("Server error; try again.");
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
if (opts['shareRedirect']) {
|
||||||
|
window.location = opts['shareRedirect'] + xhr.responseText;
|
||||||
|
}
|
||||||
|
if (shareURL) {
|
||||||
var url = origin(window.location) + "/p/" +
|
var url = origin(window.location) + "/p/" +
|
||||||
xhr.responseText;
|
xhr.responseText;
|
||||||
shareURL.show().val(url).focus().select();
|
shareURL.show().val(url).focus().select();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ function init() {
|
|||||||
"outputEl": "#output",
|
"outputEl": "#output",
|
||||||
"runEl": "#run",
|
"runEl": "#run",
|
||||||
"shareEl": "#share",
|
"shareEl": "#share",
|
||||||
"shareURLEl": "#shareURL"
|
"shareRedirect": "http://play.golang.org/"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user