From 84386416294922b948e91ebc3226271c1d049998 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Wed, 10 Oct 2012 11:17:47 +1100 Subject: [PATCH] godoc: add dropdown playground to nav bar R=gri, dsymonds, skybrian CC=golang-dev https://golang.org/cl/6631057 --- doc/godocs.js | 32 +++++++++++++++++ doc/style.css | 79 +++++++++++++++++++++++++++++++++++++++--- lib/godoc/godoc.html | 32 +++++++++++++++-- lib/godoc/package.html | 2 -- src/cmd/godoc/godoc.go | 6 ++-- 5 files changed, 140 insertions(+), 11 deletions(-) diff --git a/doc/godocs.js b/doc/godocs.js index 65305aa781..8d4a8aab82 100644 --- a/doc/godocs.js +++ b/doc/godocs.js @@ -130,6 +130,37 @@ function bindToggleLinks(selector, prefix) { }); } +function setupDropdownPlayground() { + if (!$('#page').is('.wide')) { + return; // don't show on front page + } + var button = $('#playgroundButton'); + var div = $('#playground'); + var setup = false; + button.toggle(function() { + button.addClass('active'); + div.show(); + if (setup) { + return; + } + setup = true; + playground({ + 'codeEl': $('.code', div), + 'outputEl': $('.output', div), + 'runEl': $('.run', div), + 'fmtEl': $('.fmt', div), + 'shareEl': $('.share', div), + 'shareRedirect': 'http://play.golang.org/p/' + }); + }, + function() { + button.removeClass('active'); + div.hide(); + }); + button.show(); + $('#menu').css('min-width', '+=60'); +} + $(document).ready(function() { bindSearchEvents(); generateTOC(); @@ -139,6 +170,7 @@ $(document).ready(function() { bindToggleLinks(".overviewLink", ""); bindToggleLinks(".examplesLink", ""); bindToggleLinks(".indexLink", ""); + setupDropdownPlayground(); }); })(); diff --git a/doc/style.css b/doc/style.css index 4dd10c4c9e..b9cb1ba613 100644 --- a/doc/style.css +++ b/doc/style.css @@ -130,22 +130,22 @@ div#heading a { div#topbar { background: #E0EBF5; height: 64px; + overflow: hidden; } body { text-align: center; } -div#page, +div#page > .container, div#topbar > .container { - clear: both; text-align: left; margin-left: auto; margin-right: auto; padding: 0 20px; width: 900px; } -div#page.wide, -div#topbar > .wide { +div#page.wide > .container, +div#topbar.wide > .container { width: auto; } div#plusone { @@ -153,6 +153,7 @@ div#plusone { } div#footer { + text-align: center; color: #666; font-size: 14px; margin: 40px 0; @@ -172,14 +173,20 @@ div#blog .read a { -moz-border-radius: 5px; border-radius: 5px; } +div#playground .buttons a, div#menu > a, div#menu > input { border: 1px solid #375EAB; } +div#playground .buttons a, div#menu > a { color: white; background: #375EAB; } +#playgroundButton.active { + background: white; + color: #375EAB; +} a#start, div#learn .buttons a, div.play .buttons a, @@ -214,9 +221,11 @@ div#menu > input.inactive { div.left { float: left; + clear: left; } div.right { float: right; + clear: right; } div.left, div.right { @@ -394,6 +403,7 @@ img.gopher { } h2 { clear: right; } +/* example and drop-down playground */ div.play { padding: 0 20px 40px 20px; } @@ -427,6 +437,10 @@ div.play .input textarea { overflow: hidden; } +div#playground .input textarea { + overflow: auto; + resize: auto; +} div.play .output { border-top: none !important; @@ -469,3 +483,60 @@ div.play .buttons a { padding: 10px; cursor: pointer; } + +/* drop-down playground */ +#playgroundButton, +div#playground { + /* start hidden; revealed by javascript */ + display: none; +} +div#playground { + position: absolute; + top: 63px; + right: 20px; + padding: 0 10px 10px 10px; + z-index: 1; + text-align: left; + background: #E0EBF5; + + border: 1px solid #B0BBC5; + border-top: none; + + -webkit-border-bottom-left-radius: 5px; + -webkit-border-bottom-right-radius: 5px; + -moz-border-radius-bottomleft: 5px; + -moz-border-radius-bottomright: 5px; + border-bottom-left-radius: 5px; + border-bottom-right-radius: 5px; +} +div#playground .code { + width: 520px; + height: 200px; +} +div#playground .output { + height: 100px; +} + +/* always show topbar for large screens */ +@media screen and (min-width: 130ex) and (min-height: 300px) { + /* 130ex -> wide enough so that title isn't below buttons */ + + div#topbar.wide { + position: fixed; + z-index: 1; + top: 0; + width: 100%; + height: 63px; + border-bottom: 1px solid #B0BBC5; + } + + div#page.wide { + position: fixed; + top: 64px; /* to match topbar */ + bottom: 0px; + overflow: auto; + margin-left: auto; + margin-right: auto; + } +} + diff --git a/lib/godoc/godoc.html b/lib/godoc/godoc.html index 6ee80c6c51..b7a772cb28 100644 --- a/lib/godoc/godoc.html +++ b/lib/godoc/godoc.html @@ -10,6 +10,9 @@ +{{if .Playground}} + +{{end}} {{if .SearchBox}} @@ -17,7 +20,7 @@ -
+
@@ -33,7 +39,26 @@
+{{if .Playground}} +
+
+
+
+ Run + Format + +
+
+{{end}} +
+
{{with .Title}}
@@ -50,8 +75,6 @@ {{/* Body is HTML-escaped elsewhere */}} {{printf "%s" .Body}} -
- +
+
+