-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjs.go
More file actions
32 lines (24 loc) · 702 Bytes
/
js.go
File metadata and controls
32 lines (24 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//go:build !tinygo && js && wasm
// +build !tinygo,js,wasm
package gfx
import "syscall/js"
// JS gives access to js.Global and js.TypedArrayOf
var JS = JavaScript{
Global: js.Global,
}
// JavaScript is a type that contains fields with Global and TypedArrayOf funcs.
type JavaScript struct {
Global func() js.Value
}
func (j JavaScript) Document() js.Value {
return j.Global().Get("document")
}
// Body returns the js.Value for document.body
// The (first) optional innerHTML argument can be used to set body.innerHTML.
func (j JavaScript) Body(innerHTML ...string) js.Value {
body := j.Document().Get("body")
if len(innerHTML) > 0 {
body.Set("innerHTML", innerHTML[0])
}
return body
}