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 | 493538adbfc5a580f9c5c92e2789769a7237e19a (patch) | |
tree | 4aff9c605c590b38396abba0383910f151e9ad6e /lib | |
parent | 1184407f2a2955fe2befd22896ee9bf49cd0defe (diff) | |
download | go-493538adbfc5a580f9c5c92e2789769a7237e19a.tar.gz go-493538adbfc5a580f9c5c92e2789769a7237e19a.zip |
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://golang.org/cl/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 aefbef9fd7..d71e953ec5 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; + } }); }); }); |