本文整理汇总了Golang中honnef/co/go/js/dom.Event类的典型用法代码示例。如果您正苦于以下问题:Golang Event类的具体用法?Golang Event怎么用?Golang Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Keypress
func Keypress(model Model, event dom.Event) Model {
if t, ok := event.Target().(*dom.HTMLInputElement); ok {
// TODO: save/restore focus and cursor position
return Model(t.Value)
}
return model
}
示例2: CreateTodo
// CreateTodo is an event listener which creates a new todo and adds it to the
// todo list.
func (v *App) CreateTodo(ev dom.Event) {
input, ok := ev.Target().(*dom.HTMLInputElement)
if !ok {
panic("Could not convert event target to dom.HTMLInputElement")
}
v.Todos.AddTodo(input.Value)
document.QuerySelector(".new-todo").(dom.HTMLElement).Focus()
}
示例3: ToggleAll
// ToggleAll toggles all the todos in the list.
func (v *App) ToggleAll(ev dom.Event) {
input := ev.Target().(*dom.HTMLInputElement)
if !input.Checked {
v.Todos.UncheckAll()
} else {
v.Todos.CheckAll()
}
}
示例4: paliIME
func paliIME(event dom.Event) {
elm := event.Target().(*dom.HTMLInputElement)
if lastInput != "" && elm.Value != "" {
v := elm.Value
if len(v) == (len(lastInput) + 1) {
result := checkLastTwoCharacter(lastInput[len(lastInput)-1:], v[len(v)-1:])
if result != "" {
elm.Value = v[:len(v)-2] + result
}
}
}
lastInput = elm.Value
}
示例5: UpdateRepository
// UpdateRepository updates specified repository.
// repoRoot is the import path corresponding to the root of the repository.
func UpdateRepository(event dom.Event, repoRoot string) {
event.PreventDefault()
if event.(*dom.MouseEvent).Button != 0 {
return
}
repoUpdate := document.GetElementByID(repoRoot)
updateButton := repoUpdate.GetElementsByClassName("update-button")[0].(*dom.HTMLAnchorElement)
updateButton.SetTextContent("Updating...")
updateButton.AddEventListener("click", false, func(event dom.Event) { event.PreventDefault() })
updateButton.SetTabIndex(-1)
updateButton.Class().Add("disabled")
go func() {
req := xhr.NewRequest("POST", "/-/update")
req.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
err := req.Send(url.Values{"repo_root": {repoRoot}}.Encode())
if err != nil {
println(err.Error())
return
}
// Hide the "Updating..." label.
updateButton.Style().SetProperty("display", "none", "")
// Show "No Updates Available" if there are no remaining updates.
if !anyUpdatesRemaining() {
document.GetElementByID("no_updates").(dom.HTMLElement).Style().SetProperty("display", "", "")
}
// Move this Go package to "Installed Updates" list.
installedUpdates := document.GetElementByID("installed_updates").(dom.HTMLElement)
installedUpdates.Style().SetProperty("display", "", "")
installedUpdates.ParentNode().InsertBefore(repoUpdate, installedUpdates.NextSibling()) // Insert after.
}()
}
示例6: CreatePerson
func (v *NewPerson) CreatePerson(ev dom.Event) {
ev.PreventDefault()
formEl, ok := ev.CurrentTarget().(*dom.HTMLFormElement)
if !ok {
panic("Could not cast target to dom.HTMLFormElement: " + fmt.Sprintf("%T", ev.CurrentTarget()))
}
f, err := form.Parse(formEl)
if err != nil {
panic(err)
}
f.Validate("name").Required()
f.Validate("age").Required().IsInt().Greater(0)
if f.HasErrors() {
if errorsView == nil {
errorsView = NewErrors(f.Errors)
view.InsertBefore(errorsView, v)
}
errorsView.Errors = f.Errors
if err := errorsView.Render(); err != nil {
panic(err)
}
return
}
person := &models.Person{}
if err := f.Bind(person); err != nil {
panic(err)
}
restClient := rest.NewClient()
restClient.ContentType = rest.ContentJSON
go func() {
if err := restClient.Create(person); err != nil {
if httpErr, ok := err.(rest.HTTPError); ok {
fmt.Println(string(httpErr.Body))
}
panic(err)
}
v.Router.Navigate("/people")
}()
}
示例7: inputKeyUp
func inputKeyUp(event dom.Event) {
input := event.Target().(*dom.HTMLInputElement)
span := dom.GetWindow().Document().GetElementByID("foo2")
span.SetInnerHTML(input.Value)
}