Commit 493538ad authored by Andrew Gerrand's avatar Andrew Gerrand

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
parent 1184407f
......@@ -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();
}
}
......
......@@ -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;
}
});
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment