From 59ed15b2f746c234757c64265a274d08ecfbb27a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 15 Jan 2015 22:28:05 +0900 Subject: [PATCH] Bug fix: Use prevent default properly --- internal/ui/ui_js.go | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index a6efeffbf..d4151d4fa 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -81,23 +81,6 @@ func init() { }) <-ch } - doc.Call("addEventListener", "keydown", func(e js.Object) bool { - code := e.Get("keyCode").Int() - // Backspace - if code == 8 { - return false - } - // Functions - if 112 <= code && code <= 123 { - return false - } - // Alt and arrows - if code == 37 && code == 39 { - // Don't need to check Alt. - return false - } - return true - }) canvas = doc.Call("createElement", "canvas") canvas.Set("width", 16) @@ -136,30 +119,30 @@ func init() { canvas.Get("style").Set("outline", "none") // Keyboard - canvas.Call("addEventListener", "keydown", func(e js.Object) bool { + canvas.Call("addEventListener", "keydown", func(e js.Object) { + e.Call("preventDefault") code := e.Get("keyCode").Int() currentInput.keyDown(code) - return false }) - canvas.Call("addEventListener", "keyup", func(e js.Object) bool { + canvas.Call("addEventListener", "keyup", func(e js.Object) { + e.Call("preventDefault") code := e.Get("keyCode").Int() currentInput.keyUp(code) - return false }) // Mouse - canvas.Call("addEventListener", "mousedown", func(e js.Object) bool { + canvas.Call("addEventListener", "mousedown", func(e js.Object) { + e.Call("preventDefault") button := e.Get("button").Int() currentInput.mouseDown(button) - return false }) - canvas.Call("addEventListener", "mouseup", func(e js.Object) bool { + canvas.Call("addEventListener", "mouseup", func(e js.Object) { + e.Call("preventDefault") button := e.Get("button").Int() currentInput.mouseUp(button) - return false }) - canvas.Call("addEventListener", "contextmenu", func(e js.Object) bool { - return false + canvas.Call("addEventListener", "contextmenu", func(e js.Object) { + e.Call("preventDefault") }) // Gamepad