From bc361d114109e4f22524d5c2b9024440fda7415d Mon Sep 17 00:00:00 2001 From: maddalax Date: Wed, 25 Sep 2024 17:03:12 -0500 Subject: [PATCH] add tip about lang inject --- htmgo-site/md/docs/4_interactivity/2_events.md | 12 ++++++++++++ htmgo-site/pages/index.go | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/htmgo-site/md/docs/4_interactivity/2_events.md b/htmgo-site/md/docs/4_interactivity/2_events.md index 809cf9e..ff23731 100644 --- a/htmgo-site/md/docs/4_interactivity/2_events.md +++ b/htmgo-site/md/docs/4_interactivity/2_events.md @@ -91,3 +91,15 @@ func MyButton() *h.Element { } ``` +tip: If you are using Jetbrains IDE's, you can write `// language=js` as a comment above the function call (h.EvalJS) and it will automatically give you syntax highlighting on the raw JS. + +```go +// language=js +h.EvalJs(` + if(Math.random() > 0.5) { + self.innerHTML = "Success!"; + } + `, +), +``` + diff --git a/htmgo-site/pages/index.go b/htmgo-site/pages/index.go index 0aad8e1..aee2dcf 100644 --- a/htmgo-site/pages/index.go +++ b/htmgo-site/pages/index.go @@ -5,6 +5,21 @@ import ( "htmgo-site/pages/base" ) +func Test() *h.Element { + return h.Button( + h.Text("Submit"), + h.OnClick( + // language=js + h.EvalJs(` + if(Math.random() > 0.5) { + self.innerHTML = "Success!"; + } + `, + ), + ), + ) +} + func IndexPage(ctx *h.RequestContext) *h.Page { return h.NewPage( base.RootPage(h.Div( @@ -29,6 +44,7 @@ func IndexPage(ctx *h.RequestContext) *h.Page { ), ), ), + Test(), h.Div( h.Class("border-b border-b-slate-200 h-1"), h.Div(