_content, go.dev: fix hamburger menu
Follow up on https://golang.org/cl/343469.
Use different classes for the hamburger menu to set
event listeners on golang.org & go.dev to avoid
(mis-)listing the paths.
Fixes golang/go#47862.
Change-Id: I4bbf856cd86583bea402b1869583e90799a7d1f9
Reviewed-on: https://go-review.googlesource.com/c/website/+/344309
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
diff --git a/_content/lib/godoc/godocs.js b/_content/lib/godoc/godocs.js
index 2329aec..7984c52 100644
--- a/_content/lib/godoc/godocs.js
+++ b/_content/lib/godoc/godocs.js
@@ -14,19 +14,16 @@
'use strict';
var headerEl = document.querySelector('.js-header');
- var menuButtonEl = document.querySelector('.js-headerMenuButton');
-
- const path = window.location.pathname;
- if (path.indexOf("/blog/") == -1 && path.indexOf("/doc/") != -1) {
- menuButtonEl.addEventListener('click', function(e) {
- e.preventDefault();
- headerEl.classList.toggle('is-active');
- menuButtonEl.setAttribute(
- 'aria-expanded',
- headerEl.classList.contains('is-active')
- );
- });
- }
+ var menuButtonEl = document.querySelector('.js-golangorg-headerMenuButton');
+
+ menuButtonEl?.addEventListener('click', function(e) {
+ e.preventDefault();
+ headerEl.classList.toggle('is-active');
+ menuButtonEl.setAttribute(
+ 'aria-expanded',
+ headerEl.classList.contains('is-active')
+ );
+ });
/* Generates a table of contents: looks for h2 and h3 elements and generates
* links. "Decorates" the element with id=="nav" with this table of contents.
diff --git a/_content/site.tmpl b/_content/site.tmpl
index 30680ed..13cf8d1 100644
--- a/_content/site.tmpl
+++ b/_content/site.tmpl
@@ -42,7 +42,7 @@
</div>
<nav class="Header-nav {{if .title}}Header-nav--wide{{end}}">
<a href="/"><img class="Header-logo" src="/lib/godoc/images/go-logo-blue.svg" alt="Go"></a>
- <button class="Header-menuButton js-headerMenuButton" aria-label="Main menu" aria-expanded="false">
+ <button class="Header-menuButton js-golangorg-headerMenuButton" aria-label="Main menu" aria-expanded="false">
<div class="Header-menuButtonInner"></div>
</button>
<ul class="Header-menu">
diff --git a/go.dev/_content/js/godocs.js b/go.dev/_content/js/godocs.js
index ad4e4bf..7984c52 100644
--- a/go.dev/_content/js/godocs.js
+++ b/go.dev/_content/js/godocs.js
@@ -14,19 +14,16 @@
'use strict';
var headerEl = document.querySelector('.js-header');
- var menuButtonEl = document.querySelector('.js-headerMenuButton');
+ var menuButtonEl = document.querySelector('.js-golangorg-headerMenuButton');
- const path = window.location.pathname;
- if (path.indexOf("/blog/") == -1 && path.indexOf("/doc/") != -1) {
- menuButtonEl.addEventListener('click', function(e) {
- e.preventDefault();
- headerEl.classList.toggle('is-active');
- menuButtonEl.setAttribute(
- 'aria-expanded',
- headerEl.classList.contains('is-active')
- );
- });
- }
+ menuButtonEl?.addEventListener('click', function(e) {
+ e.preventDefault();
+ headerEl.classList.toggle('is-active');
+ menuButtonEl.setAttribute(
+ 'aria-expanded',
+ headerEl.classList.contains('is-active')
+ );
+ });
/* Generates a table of contents: looks for h2 and h3 elements and generates
* links. "Decorates" the element with id=="nav" with this table of contents.