diff options
author | Andrew Gerrand <adg@golang.org> | 2013-07-02 08:44:25 +1000 |
---|---|---|
committer | Andrew Gerrand <adg@golang.org> | 2013-07-02 08:44:25 +1000 |
commit | 924c63fd45fbc91b2c0b1724817aa479ac736108 (patch) | |
tree | fa33b0fd8bb764e4d0bd5655253fa46c4eb15e30 /lib | |
parent | 41751a78880d49e12ee37e9d38571d36e75b4b30 (diff) | |
download | go-924c63fd45fbc91b2c0b1724817aa479ac736108.tar.gz |
cmd/godoc: set up playground for examples that are already visible
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,
visit this link: http://golang.org/pkg/strings/#example_Map
R=golang-dev, r
CC=golang-dev
https://codereview.appspot.com/10679050
Diffstat (limited to 'lib')
-rw-r--r-- | lib/godoc/package.html | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/godoc/package.html b/lib/godoc/package.html index aefbef9fd..d71e953ec 100644 --- a/lib/godoc/package.html +++ b/lib/godoc/package.html @@ -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; + } }); }); }); |