diff --git a/godoc/static/godocs.js b/godoc/static/godocs.js
index e39ea740ac..85c322dd67 100644
--- a/godoc/static/godocs.js
+++ b/godoc/static/godocs.js
@@ -329,6 +329,28 @@ function addPermalinks() {
});
}
+$(".js-expandAll").click(function() {
+ if ($(this).hasClass("collapsed")) {
+ toggleExamples('toggle');
+ $(this).text("(Collapse All)");
+ } else {
+ toggleExamples('toggleVisible');
+ $(this).text("(Expand All)");
+ }
+ $(this).toggleClass("collapsed")
+});
+
+function toggleExamples(className) {
+ // We need to explicitly iterate through divs starting with "example_"
+ // to avoid toggling Overview and Index collapsibles.
+ $("[id^='example_']").each(function() {
+ // Check for state and click it only if required.
+ if ($(this).hasClass(className)) {
+ $(this).find('.toggleButton').first().click();
+ }
+ });
+}
+
$(document).ready(function() {
generateTOC();
addPermalinks();
diff --git a/godoc/static/package.html b/godoc/static/package.html
index 06f533ae0b..4537c00f61 100644
--- a/godoc/static/package.html
+++ b/godoc/static/package.html
@@ -90,6 +90,7 @@
{{if $.Examples}}
Examples
+
(Expand All)
{{range $.Examples}}
- {{example_name .Name}}
diff --git a/godoc/static/static.go b/godoc/static/static.go
index 88feb3f21c..bb50de9480 100644
--- a/godoc/static/static.go
+++ b/godoc/static/static.go
@@ -912,6 +912,28 @@ function addPermalinks() {
});
}
+$(".js-expandAll").click(function() {
+ if ($(this).hasClass("collapsed")) {
+ toggleExamples('toggle');
+ $(this).text("(Collapse All)");
+ } else {
+ toggleExamples('toggleVisible');
+ $(this).text("(Expand All)");
+ }
+ $(this).toggleClass("collapsed")
+});
+
+function toggleExamples(className) {
+ // We need to explicitly iterate through divs starting with "example_"
+ // to avoid toggling Overview and Index collapsibles.
+ $("[id^='example_']").each(function() {
+ // Check for state and click it only if required.
+ if ($(this).hasClass(className)) {
+ $(this).find('.toggleButton').first().click();
+ }
+ });
+}
+
$(document).ready(function() {
generateTOC();
addPermalinks();
@@ -1710,6 +1732,7 @@ function cgAddChild(tree, ul, cgn) {
{{if $.Examples}}
Examples
+
(Expand All)
{{range $.Examples}}
- {{example_name .Name}}
@@ -3042,12 +3065,14 @@ pre .ln {
}
a,
-.exampleHeading .text {
+.exampleHeading .text,
+.expandAll {
color: #375EAB;
text-decoration: none;
}
a:hover,
-.exampleHeading .text:hover {
+.exampleHeading .text:hover,
+.expandAll:hover {
text-decoration: underline;
}
.article a {
@@ -3164,6 +3189,20 @@ div#nav table td {
text-decoration: none;
}
+#pkg-examples h3 {
+ float: left;
+}
+
+#pkg-examples dl {
+ clear: both;
+}
+
+.expandAll {
+ cursor: pointer;
+ float: left;
+ margin: 1.25rem 0;
+}
+
div#topbar {
background: #E0EBF5;
height: 4rem;
diff --git a/godoc/static/style.css b/godoc/static/style.css
index 3d1b1a0125..20cd576ab1 100644
--- a/godoc/static/style.css
+++ b/godoc/static/style.css
@@ -40,12 +40,14 @@ pre .ln {
}
a,
-.exampleHeading .text {
+.exampleHeading .text,
+.expandAll {
color: #375EAB;
text-decoration: none;
}
a:hover,
-.exampleHeading .text:hover {
+.exampleHeading .text:hover,
+.expandAll:hover {
text-decoration: underline;
}
.article a {
@@ -162,6 +164,20 @@ div#nav table td {
text-decoration: none;
}
+#pkg-examples h3 {
+ float: left;
+}
+
+#pkg-examples dl {
+ clear: both;
+}
+
+.expandAll {
+ cursor: pointer;
+ float: left;
+ margin: 1.25rem 0;
+}
+
div#topbar {
background: #E0EBF5;
height: 4rem;