示例#1
0
文件: dom.go 项目: influx6/gu
// TriggerBindEvent connects the giving event with the provided dom target.
func (dm *DOMRenderer) TriggerBindEvent(event *gjs.Object, root *gjs.Object, source *trees.Event) {
	target := event.Get("target")

	children := root.Call("querySelectorAll", source.Target())
	if children == nil || children == gjs.Undefined {
		return
	}

	kids := js.DOMObjectToList(children)
	var match bool

	for _, item := range kids {
		if item != target {
			continue
		}

		match = true
		break
	}

	// if we match then run the listeners registered.
	if match {
		dispatch.Dispatch(trees.EventBroadcast{
			EventID: source.EventID,
			Event:   trees.NewWrapperEvent(event),
		})
	}
}
示例#2
0
文件: dom.go 项目: influx6/gu
// BindEvent connects the event with the provided event object and root.
func (dm *DOMRenderer) BindEvent(source *trees.Event, root *gjs.Object) {
	source.Link = func(ev *gjs.Object) { dm.TriggerBindEvent(ev, root, source) }

	root.Call("addEventListener", source.Type, source.Link, true)

	source.Handle.AddEnd(func() {
		root.Call("removeEventListener", source.Type, source.Link, true)
	})
}