From 493538adbfc5a580f9c5c92e2789769a7237e19a Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Tue, 2 Jul 2013 08:44:25 +1000 Subject: [PATCH] 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 --- doc/godocs.js | 2 +- lib/godoc/package.html | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/doc/godocs.js b/doc/godocs.js index 6875f74d8ca..d8245104766 100644 --- a/doc/godocs.js +++ b/doc/godocs.js @@ -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(); } } diff --git a/lib/godoc/package.html b/lib/godoc/package.html index aefbef9fd73..d71e953ec56 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; + } }); }); });