-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.go
68 lines (51 loc) · 1.34 KB
/
link.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package dhtml
import "html"
// simple <a> element
type LinkElement struct {
tag *Tag
}
// force interfaces implementation
var _ ElementI = (*LinkElement)(nil)
func NewLink(href string) *LinkElement {
return &LinkElement{tag: NewTag("a").Attribute("href", href)}
}
func (e *LinkElement) Target(target string) *LinkElement {
e.tag.Attribute("target", target)
return e
}
func (e *LinkElement) Label(v any) *LinkElement {
e.tag.Append(v)
return e
}
func (e *LinkElement) Title(title string) *LinkElement {
e.tag.Title(title)
return e
}
func (e *LinkElement) Class(v ...any) *LinkElement {
e.tag.Class(v...)
return e
}
func (e *LinkElement) GetTags() TagList {
return e.tag.GetTags()
}
// =======================================================================
// <a> tag with onclick="return confirm('message');"
type ConfirmLinkElement struct {
LinkElement
}
// force interfaces implementation
var _ ElementI = (*ConfirmLinkElement)(nil)
// Html form just to render it
func NewConfirmLink(href, confirmMessage string) *ConfirmLinkElement {
l := &ConfirmLinkElement{
LinkElement: *NewLink(href),
}
if confirmMessage == "" {
confirmMessage = "Are you sure?"
}
l.tag.AttributeUnsafe("onclick", "return confirm(\""+html.EscapeString(confirmMessage)+"\");")
return l
}
func (e *ConfirmLinkElement) GetTags() TagList {
return e.tag.GetTags()
}