diff --git a/godoc/static/godocs.js b/godoc/static/godocs.js index 10183cba35..7e353d902a 100644 --- a/godoc/static/godocs.js +++ b/godoc/static/godocs.js @@ -305,9 +305,36 @@ function updateVersionTags() { } } +function addPermalinks() { + function addPermalink(source, parent) { + var id = source.attr("id"); + if (id == "" || id.indexOf("tmp_") === 0) { + // Auto-generated permalink. + return; + } + if (parent.find("> .permalink").length) { + // Already attached. + return; + } + parent.append(" ").append($("").attr("href", "#" + id)); + } + + $("#page .container").find("h2[id], h3[id]").each(function() { + var el = $(this); + addPermalink(el, el); + }); + + $("#page .container").find("dl[id]").each(function() { + var el = $(this); + // Add the anchor to the "dt" element. + addPermalink(el, el.find("> dt").first()); + }); +} + $(document).ready(function() { bindSearchEvents(); generateTOC(); + addPermalinks(); bindToggles(".toggle"); bindToggles(".toggleVisible"); bindToggleLinks(".exampleLink", "example_"); diff --git a/godoc/static/static.go b/godoc/static/static.go index f6e267e65d..2d5fbe4003 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -875,9 +875,36 @@ function updateVersionTags() { } } +function addPermalinks() { + function addPermalink(source, parent) { + var id = source.attr("id"); + if (id.indexOf("tmp_") === 0) { + // Auto-generated permalink. + return; + } + if (parent.find("> .permalink").length) { + // Already attached. + return; + } + parent.append(" ").append($(" ").attr("href", "#" + id)); + } + + $("#page .container").find("h2[id], h3[id]").each(function() { + var el = $(this); + addPermalink(el, el); + }); + + $("#page .container").find("dl[id]").each(function() { + var el = $(this); + // Add the anchor to the "dt" element. + addPermalink(el, el.find("> dt").first()); + }); +} + $(document).ready(function() { bindSearchEvents(); generateTOC(); + addPermalinks(); bindToggles(".toggle"); bindToggles(".toggleVisible"); bindToggleLinks(".exampleLink", "example_"); @@ -1599,8 +1626,8 @@ function cgAddChild(tree, ul, cgn) { {{if $.IsMain}} - {{comment_html .Doc}} {{/* command documentation */}} + {{comment_html .Doc}} {{else}} {{/* package documentation */}}
@@ -2849,7 +2876,7 @@ a:hover, .permalink { display: none; } -h2:hover .permalink, h3:hover .permalink { +:hover > .permalink { display: inline; } diff --git a/godoc/static/style.css b/godoc/static/style.css index fd26bd85fc..b21bc24f8d 100644 --- a/godoc/static/style.css +++ b/godoc/static/style.css @@ -46,7 +46,7 @@ a:hover, .permalink { display: none; } -h2:hover .permalink, h3:hover .permalink { +:hover > .permalink { display: inline; }