]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/godoc: set up playground for examples that are already visible
authorAndrew Gerrand <adg@golang.org>
Mon, 1 Jul 2013 22:44:25 +0000 (08:44 +1000)
committerAndrew Gerrand <adg@golang.org>
Mon, 1 Jul 2013 22:44:25 +0000 (08:44 +1000)
This fixes an issue where linking directly to an example makes it not
runnable and visible only in a tiny window. To see the bug in action,
link: http://golang.org/pkg/strings/#example_Map
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/10679050

doc/godocs.js
lib/godoc/package.html

index 6875f74d8ca52a532951b5f77e148f6ad7238654..d82451047668577750575ccaf7fe4dd4e0d18f55 100644 (file)
@@ -182,7 +182,7 @@ function fixFocus() {
 function toggleHash() {
     var hash = $(window.location.hash);
     if (hash.is('.toggle')) {
-      hash.addClass('toggleVisible').removeClass('toggle');
+      hash.find('.toggleButton').first().click();
     }
 }
 
index aefbef9fd73213c2a36dd7b04fc2c5319e5d5691..d71e953ec560b092b3cbdfac5f3d5d66d8aab5f3 100644 (file)
@@ -231,15 +231,8 @@ $(document).ready(function() {
        'use strict';
        // Set up playground when each element is toggled.
        $('div.play').each(function (i, el) {
-               var built = false;
-               $(el).closest('.toggle').click(function() {
-                       // Only set up playground once.
-                       if (built) {
-                               return;
-                       }
-                       built = true;
-
-                       // Set up playground.
+               // Set up playground for this example.
+               var setup = function() {
                        var code = $('.code', el);
                        playground({
                                'codeEl':   code,
@@ -260,6 +253,22 @@ $(document).ready(function() {
                        code.on('keydown', resize);
                        code.on('keyup', resize);
                        code.keyup(); // resize now.
+               };
+               
+               // If example already visible, set up playground now.
+               if ($(el).is(':visible')) {
+                       setup();
+                       return;
+               }
+
+               // Otherwise, set up playground when example is expanded.
+               var built = false;
+               $(el).closest('.toggle').click(function() {
+                       // Only set up once.
+                       if (!built) {
+                               setup();
+                               built = true;
+                       }
                });
        });
 });