本文整理汇总了Golang中honnef/co/go/js/dom.GetWindow函数的典型用法代码示例。如果您正苦于以下问题:Golang GetWindow函数的具体用法?Golang GetWindow怎么用?Golang GetWindow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetWindow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunPreparation
func RunPreparation() {
Time = NewClock()
dom.GetWindow().AddEventListener("onbeforeunload", false, func(e dom.Event) {
dom.GetWindow().Alert("You're closing")
})
}
示例2: main
func main() {
dom.GetWindow().AddEventListener("load", false, func(dom.Event) {
go func() {
if err := rpcInit(); err != nil {
xjs.Alert("Failed to connect to RPC server: %s", err)
return
}
title, err := RPC.ServerName()
if err != nil {
xjs.Alert("Error retrieving server name: %s", err)
return
}
body := dom.GetWindow().Document().(dom.HTMLDocument).Body()
body.Underlying().Set("spellcheck", "false")
xjs.RemoveChildren(body)
body.AppendChild(xdom.H1())
SetTitle(title)
body.AppendChild(tabs.New([]tabs.Tab{
{"Servers", ServersTab()},
{"Maps", MapsTab()},
{"Generators", GeneratorsTab},
{"Settings", settingsTab},
}))
}()
})
}
示例3: SetTitle
func SetTitle(title string) {
title += " Server"
xjs.SetInnerText(dom.GetWindow().Document().(dom.HTMLDocument).Body().ChildNodes()[0], title)
tDoc, ok := dom.GetWindow().Document().(dom.HTMLDocument)
if ok {
tDoc.SetTitle(title)
}
}
示例4: setupEvents
func setupEvents() {
dom.GetWindow().Document().GetElementByID("init").
AddEventListener("click", false, func(dom.Event) {
go initialize()
})
dom.GetWindow().Document().GetElementByID("step").
AddEventListener("click", false, func(dom.Event) {
step()
})
dom.GetWindow().Document().GetElementByID("run").
AddEventListener("click", false, func(dom.Event) {
go run()
})
}
示例5: On
// On adds an event handler to an HTML element.
func (s HTML) On(event string, rootUpdateFunc, updateFunc, actionFunc interface{}) HTML {
id := s.ID()
s.initFuncs = append(s.initFuncs, func() {
el := dom.GetWindow().Document().GetElementByID(id)
if el == nil {
log.Printf("unable to find DOM element id=%q", id)
return
}
el.AddEventListener(event, false, func(de dom.Event) {
go func() {
u := reflect.ValueOf(updateFunc)
// log.Printf("GML: updateFunc=%#v, u=%#v", updateFunc, u)
a := reflect.ValueOf(actionFunc)
// log.Printf("GML: actionFunc=%#v, a=%#v, a.Type=%q", actionFunc, a, a.Type())
args := []reflect.Value{a}
if reflect.TypeOf(updateFunc).NumIn() == 2 {
var e interface{} = de
args = append(args, reflect.ValueOf(e))
}
newModel := u.Call(args)
// log.Printf("GML: in click handler! len(newModel)=%v", len(newModel))
// log.Printf("GML: in click handler! newModel[0]=%v", newModel[0])
// log.Printf("GML: in click handler! newModel[0].Type=%v", newModel[0].Type())
if view, ok := newModel[0].Interface().(Viewer); ok {
Render(view, rootUpdateFunc)
}
}()
})
})
return s
}
示例6: draggable
func draggable(elm *dom.HTMLDivElement) {
var startX, startY, initialMouseX, initialMouseY int
var fmove, fup func(*js.Object)
elm.Style().SetProperty("position", "absolute", "")
d := dom.GetWindow().Document()
mousemove := func(event dom.Event) {
event.PreventDefault()
e := event.(*dom.MouseEvent)
dx := e.ClientX - initialMouseX
dy := e.ClientY - initialMouseY
elm.Style().SetProperty("top", strconv.Itoa(startY+dy)+"px", "")
elm.Style().SetProperty("left", strconv.Itoa(startX+dx)+"px", "")
}
mouseup := func(event dom.Event) {
d.RemoveEventListener("mousemove", false, fmove)
d.RemoveEventListener("mouseup", false, fup)
}
elm.AddEventListener("mousedown", false, func(event dom.Event) {
event.PreventDefault()
e := event.(*dom.MouseEvent)
startX = int(elm.OffsetLeft())
startY = int(elm.OffsetTop())
initialMouseX = e.ClientX
initialMouseY = e.ClientY
fmove = d.AddEventListener("mousemove", false, mousemove)
fup = d.AddEventListener("mouseup", false, mouseup)
})
}
示例7: SelectMenuOnInput
func SelectMenuOnInput(event dom.Event, object dom.HTMLElement, defaultOption, queryParameter string) {
rawQuery := strings.TrimPrefix(dom.GetWindow().Location().Search, "?")
query, _ := url.ParseQuery(rawQuery)
selectElement := object.(*dom.HTMLSelectElement)
selected := selectElement.SelectedOptions()[0].Text
if selected == defaultOption {
query.Del(queryParameter)
} else {
query.Set(queryParameter, selected)
}
dom.GetWindow().Location().Search = "?" + query.Encode()
}
示例8: CheckboxOnChange
func CheckboxOnChange(event dom.Event, object dom.HTMLElement, defaultValue bool, queryParameter string) {
rawQuery := strings.TrimPrefix(dom.GetWindow().Location().Search, "?")
query, _ := url.ParseQuery(rawQuery)
inputElement := object.(*dom.HTMLInputElement)
selected := inputElement.Checked
if selected == defaultValue {
query.Del(queryParameter)
} else {
query.Set(queryParameter, "")
}
dom.GetWindow().Location().Search = "?" + query.Encode()
}
示例9: main
func main() {
d := dom.GetWindow().Document()
p := d.GetElementByID("pali").(*dom.HTMLInputElement)
p.Focus()
p.AddEventListener("keyup", false, paliIME)
}
示例10: main
func main() {
d := dom.GetWindow().Document()
p := d.GetElementByID("foo").(*dom.HTMLInputElement)
p.Focus()
p.AddEventListener("keyup", false, inputKeyUp)
}
示例11: addKeyboardEvents
func (v *PageView) addKeyboardEvents() {
window := dom.GetWindow()
document := window.Document().(dom.HTMLDocument)
window.AddEventListener("keydown", true, func(e dom.Event) {
k := e.(*dom.KeyboardEvent)
switch document.ActiveElement().TagName() {
case "INPUT", "TEXTAREA", "SELECT":
if k.KeyCode == 27 {
// escape
document.ActiveElement().Blur()
}
return
default:
switch k.KeyCode {
case 65:
// "a"
addCollectionItem(v.Ctx, v.App, v.App.Nodes.Selected())
case 37, 38, 39, 40:
// up, down, left, right
k.PreventDefault()
go func() {
v.KeyPress(k.KeyCode)
}()
}
}
})
}
示例12: getRawInfo
func getRawInfo() string {
return dom.
GetWindow().
Document().(dom.HTMLDocument).
GetElementByID("body").(*dom.HTMLBodyElement).
GetAttribute("info")
}
示例13: misc
func misc(mType string, id int, o *overlay.Overlay, deleteFunc func(int) error) func(dom.Element) {
return func(c dom.Element) {
download := xdom.A()
download.Href = "http://" + js.Global.Get("location").Get("host").String() + "/download/" + mType + "/" + strconv.Itoa(id) + ".zip"
download.Target = "_blank"
del := xdom.Button()
del.AddEventListener("click", false, func(dom.Event) {
del.Disabled = true
if dom.GetWindow().Confirm("Are you sure?") {
go func() {
err := deleteFunc(id)
if err != nil {
del.Disabled = false
xjs.Alert("Error while deleting %s: %s", mType, err)
} else {
o.Close()
}
}()
}
})
xjs.AppendChildren(c,
xjs.AppendChildren(xdom.Fieldset(),
xjs.SetInnerText(xdom.Legend(), "Download"),
xjs.SetInnerText(xdom.Div(), "Click the following link to download the "+mType+" as a zip file."),
xjs.SetInnerText(download, download.Href),
),
xjs.AppendChildren(xdom.Fieldset(),
xjs.SetInnerText(xdom.Legend(), "Delete"),
xjs.SetInnerText(xdom.Div(), "The following button will permanently delete the "+mType+" (this cannot be undone)."),
xjs.SetInnerText(del, "Delete "+mType),
),
)
}
}
示例14: main
func main() {
New(&DOMRenderer{
Document: dom.GetWindow().Document(),
}).Init(true)
}
示例15: main
func main() {
d := dom.GetWindow().Document()
foo := d.GetElementByID("foo").(*dom.HTMLDivElement)
foo.AddEventListener("click", false, func(event dom.Event) {
foo.Style().SetProperty("display", "none", "")
})
}