Exemple #1
0
// 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),
		})
	}
}
Exemple #2
0
// Render returns the markup for the subscription component.
func (s *Subscriber) Render() *Markup {
	return Section(
		CSS(SubscribeCSS, s),
		ClassAttr("subscription"),
		Form(
			ClassAttr("form", "form-control"),
			Section(
				ClassAttr("email"),
				Input(
					PlaceholderAttr("*****@*****.**"),
					TypeAttr("email"),
				),
			),
			Section(
				ClassAttr("buttons"),
				Button(
					Text("Subscribe"),
					ClassAttr("button", "named"),
					ClickEvent(func(event EventObject, tree *Markup) {
						event.PreventDefault()
						event.StopPropagation()

						doc := dom.GetWindow().Document()
						input, ok := doc.QuerySelector(".subscription .form .email input").(*dom.HTMLInputElement)

						if !ok {
							dispatch.Dispatch(SubscriptionSubmitEvent{
								Status: false,
							})

							return
						}

						dispatch.NavigateHash("/", "#subscriptions/submit", "#")

						dispatch.Dispatch(SubscriptionSubmitEvent{
							Email:  input.Value,
							Status: true,
						})

					}, ""),
				),
			),
		),
	)
}
Exemple #3
0
// DoView creates a gu.RenderView and applies it to the provided resource.
func DoView(vrs Viewable, targets string, deferRender bool, targetAlreadyInDom bool) gu.RenderView {
	var rs gu.Renderables

	switch vwo := vrs.(type) {
	case gu.Renderables:
		rs = vwo
		break
	case gu.Renderable:
		rs = gu.Renderables{vwo}
		break
	case func() gu.Renderable:
		rs = gu.Renderables{vwo()}
		break
	case func() gu.Renderables:
		rs = vwo()
		break
	default:
		panic("View must either recieve a function that returns Renderables or Renderables themselves")
	}

	current := getResources().MustCurrentResource()
	view := gu.CustomView("section", rs...)

	if vh, ok := view.(gu.ViewHooks); ok {
		current.ViewHooks = append(current.ViewHooks, vh)
	}

	if rvw, ok := view.(gu.Reactive); ok {
		rvw.React(func() {
			dispatch.Dispatch(&ResourceViewUpdate{
				View:     view,
				Target:   targets,
				Resource: current.UUID(),
			})
		})
	}

	current.Views = append(current.Views, view)

	if deferRender {
		current.DRenderables = append(current.DRenderables, targetRenderable{
			View:    view,
			Targets: targets,
		})

		return view
	}

	if !deferRender && targetAlreadyInDom {
		current.Renderables = append(current.Renderables, targetRenderable{
			View:    view,
			Targets: targets,
		})

		return view
	}

	if !deferRender && !targetAlreadyInDom && targets != "" {
		current.DRenderables = append(current.DRenderables, targetRenderable{
			View:    view,
			Targets: targets,
		})

		return view
	}

	current.Renderables = append(current.Renderables, targetRenderable{
		View:    view,
		Targets: targets,
	})

	return view
}