]> Cypherpunks repositories - gostls13.git/commitdiff
doc: support redirect-on-share
authorAndrew Gerrand <adg@golang.org>
Tue, 21 Feb 2012 22:16:54 +0000 (09:16 +1100)
committerAndrew Gerrand <adg@golang.org>
Tue, 21 Feb 2012 22:16:54 +0000 (09:16 +1100)
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5689056

doc/play/playground.js
doc/root.html

index 6f1a5c7a2eeaea964231654ca15a84276a4b7ab2..e060e203c4a1443e90bca79ee85f3eb81b64969c 100644 (file)
@@ -8,6 +8,7 @@
 //     runEl - run button element
 //     shareEl - share button 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
 //     postCompile - callback to read response data after compiling
 //      simple - use plain textarea instead of CodeMirror.
@@ -163,7 +164,7 @@ function playground(opts) {
        }
        $(opts['runEl']).click(run);
 
-       if (opts['shareEl'] == null || opts['shareURLEl'] == null) {
+       if (opts['shareEl'] == null || (opts['shareURLEl'] == null && opts['shareRedirect'] == null)) {
                return editor;
        }
 
@@ -171,7 +172,10 @@ function playground(opts) {
                return (""+href).split("/").slice(0, 3).join("/");
        }
 
-       var shareURL = $(opts['shareURLEl']).hide();
+       var shareURL;
+       if (opts['shareURLEl']) {
+               shareURL = $(opts['shareURLEl']).hide();
+       }
        var sharing = false;
        $(opts['shareEl']).click(function() {
                if (sharing) return;
@@ -184,11 +188,16 @@ function playground(opts) {
                                sharing = false;
                                if (xhr.status != 200) {
                                        alert("Server error; try again.");
-                                       return
+                                       return;
+                               }
+                               if (opts['shareRedirect']) {
+                                       window.location = opts['shareRedirect'] + xhr.responseText;
+                               }
+                               if (shareURL) {
+                                       var url = origin(window.location) + "/p/" +
+                                               xhr.responseText;
+                                       shareURL.show().val(url).focus().select();
                                }
-                               var url = origin(window.location) + "/p/" +
-                                       xhr.responseText;
-                               shareURL.show().val(url).focus().select();
                        }
                });
        });
index 20bd62b2741125cc74be06d8b592e08d14cf6ff3..1c6bcd101c7d814bd5426dd7ec21b4911d6f6e59 100644 (file)
@@ -113,12 +113,12 @@ function init() {
 
        // Set up playground.
        playground({
-               "simple":     true,
-               "codeEl":     "#code",
-               "outputEl":   "#output",
-               "runEl":      "#run",
-               "shareEl":    "#share",
-               "shareURLEl": "#shareURL"
+               "simple":        true,
+               "codeEl":        "#code",
+               "outputEl":      "#output",
+               "runEl":         "#run",
+               "shareEl":       "#share",
+               "shareRedirect": "http://play.golang.org/"
        });
 }