-
Notifications
You must be signed in to change notification settings - Fork 6
/
htmltitleelement.go
96 lines (72 loc) · 1.9 KB
/
htmltitleelement.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package htmltitleelement
import (
"sync"
"syscall/js"
"github.com/realPy/hogosuru/baseobject"
"github.com/realPy/hogosuru/document"
"github.com/realPy/hogosuru/element"
"github.com/realPy/hogosuru/htmlelement"
)
var singleton sync.Once
var htmltitleelementinterface js.Value
//HtmlTemplatelement struct
type HtmlTitleElement struct {
htmlelement.HtmlElement
}
type HtmlTitleElementFrom interface {
HtmlTitleElement() HtmlTitleElement
}
func (h HtmlTitleElement) HtmlTitleElement() HtmlTitleElement {
return h
}
func GetInterface() js.Value {
singleton.Do(func() {
var err error
if htmltitleelementinterface, err = js.Global().GetWithErr("HTMLTitleElement"); err != nil {
htmltitleelementinterface = js.Null()
}
})
baseobject.Register(htmltitleelementinterface, func(v js.Value) (interface{}, error) {
return NewFromJSObject(v)
})
return htmltitleelementinterface
}
func New(d document.Document) (HtmlTitleElement, error) {
var err error
var h HtmlTitleElement
var e element.Element
if e, err = d.CreateElement("title"); err == nil {
h, err = NewFromElement(e)
}
return h, err
}
func NewFromElement(elem element.Element) (HtmlTitleElement, error) {
var h HtmlTitleElement
var err error
if hci := GetInterface(); !hci.IsNull() {
if elem.BaseObject.JSObject().InstanceOf(hci) {
h.BaseObject = h.SetObject(elem.BaseObject.JSObject())
} else {
err = ErrNotAnHTMLTitleElement
}
} else {
err = ErrNotImplemented
}
return h, err
}
func NewFromJSObject(obj js.Value) (HtmlTitleElement, error) {
var h HtmlTitleElement
if hci := GetInterface(); !hci.IsNull() {
if obj.InstanceOf(hci) {
h.BaseObject = h.SetObject(obj)
return h, nil
}
}
return h, ErrNotAnHTMLTitleElement
}
func (h HtmlTitleElement) Text() (string, error) {
return h.GetAttributeString("text")
}
func (h HtmlTitleElement) SetText(value string) error {
return h.SetAttributeString("text", value)
}