mirror of
https://github.com/taigrr/wasm-experiments
synced 2025-01-18 04:03:21 -08:00
32 lines
542 B
Go
32 lines
542 B
Go
package dom
|
|
|
|
import "github.com/dennwc/dom/js"
|
|
|
|
func GetWindow() *Window {
|
|
win := js.Get("window")
|
|
if !win.Valid() {
|
|
return nil
|
|
}
|
|
return &Window{v: win}
|
|
}
|
|
|
|
var _ EventTarget = (*Window)(nil)
|
|
|
|
type Window struct {
|
|
v js.Value
|
|
}
|
|
|
|
func (w *Window) JSRef() js.Ref {
|
|
return w.v.JSRef()
|
|
}
|
|
|
|
func (w *Window) AddEventListener(typ string, h EventHandler) {
|
|
w.v.Call("addEventListener", typ, js.NewEventCallback(func(v js.Value) {
|
|
h(convertEvent(v))
|
|
}))
|
|
}
|
|
|
|
func (w *Window) OnResize(fnc func(e Event)) {
|
|
w.AddEventListener("resize", fnc)
|
|
}
|