1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:57:57 -07:00

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
This commit is contained in:
Andrew Gerrand 2013-07-02 08:44:25 +10:00
parent 1184407f2a
commit 493538adbf
2 changed files with 19 additions and 10 deletions

View 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();
}
}

View 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;
}
});
});
});