@@ -8,11 +8,11 @@ import (
"github.com/gopherjs/gopherjs/js"
"github.com/shurcooL/go/gopherjs_http/jsutil"
"honnef.co/go/js/dom"
)
func init() {
func setupScroll() {
js.Global.Set("AnchorScroll", jsutil.Wrap(AnchorScroll))
processHashSet := func() {
// Scroll to hash target.
targetID := strings.TrimPrefix(dom.GetWindow().Location().Hash, "#")
@@ -36,18 +36,14 @@ func init() {
processHashSet()
event.PreventDefault()
})
document.AddEventListener("keydown", false, func(event dom.Event) {
document.Body().AddEventListener("keydown", false, func(event dom.Event) {
if event.DefaultPrevented() {
return
}
// Ignore when some element other than body has focus (it means the user is typing elsewhere).
if !event.Target().IsEqualNode(document.Body()) {
return
}
switch ke := event.(*dom.KeyboardEvent); {
// Escape.
case ke.KeyCode == 27 && !ke.Repeat && !ke.CtrlKey && !ke.AltKey && !ke.MetaKey && !ke.ShiftKey:
if strings.TrimPrefix(dom.GetWindow().Location().Hash, "#") == "" {