Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce HTMLElement & Update Element #21

Merged
merged 1 commit into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 188 additions & 14 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,190 @@ type Element struct {
NodeBase
}

func (e *Element) SetInnerHTML(s string) {
e.v.Set("innerHTML", s)
// Properties

// Attributes returns a NamedNodeMap object containing the assigned attributes of the corresponding HTML element.
// func (e *Element) Attributes() NamedNodeMap {
// return e.v.Get("attributes")
// }

// ClassList returns a DOMTokenList containing the list of class attributes.
func (e *Element) ClassList() *TokenList {
return AsTokenList(e.v.Get("classList"))
}

// ClassName is a DOMString representing the class of the element.
func (e *Element) ClassName() string {
return e.v.Get("className").String()
}

// SetClassName is a DOMString representing the class of the element.
func (e *Element) SetClassName(v string) {
e.v.Set("className", v)
}

// ClientHeight returns a Number representing the inner height of the element.
func (e *Element) ClientHeight() int {
return e.v.Get("clientHeight").Int()
}

// ClientLeft returns a Number representing the width of the left border of the element.
func (e *Element) ClientLeft() int {
return e.v.Get("clientLeft").Int()
}

// ClientTop returns a Number representing the width of the top border of the element.
func (e *Element) ClientTop() int {
return e.v.Get("clientTop").Int()
}

// ClientWidth returns a Number representing the inner width of the element.
func (e *Element) ClientWidth() int {
return e.v.Get("clientWidth").Int()
}

// ComputedName returns a DOMString containing the label exposed to accessibility.
func (e *Element) ComputedName() string {
return e.v.Get("computedName").String()
}

// ComputedRole returns a DOMString containing the ARIA role that has been applied to a particular element.
func (e *Element) ComputedRole() string {
return e.v.Get("computedRole").String()
}

// Id is a DOMString representing the id of the element.
func (e *Element) Id() string {
return e.v.Get("id").String()
}

// SetId is a DOMString representing the id of the element.
func (e *Element) SetId(v string) {
e.v.Set("id", v)
}

// InnerHTML is a DOMString representing the markup of the element's content.
func (e *Element) InnerHTML() string {
return e.v.Get("innerHTML").String()
}

// SetInnerHTML is a DOMString representing the markup of the element's content.
func (e *Element) SetInnerHTML(v string) {
e.v.Set("innerHTML", v)
}

// LocalName a DOMString representing the local part of the qualified name of the element.
func (e *Element) LocalName() string {
return e.v.Get("localName").String()
}

// NamespaceURI the namespace URI of the element, or null if it is no namespace.
func (e *Element) NamespaceURI() string {
return e.v.Get("namespaceURI").String()
}

// OuterHTML is a DOMString representing the markup of the element including its content. When used as a setter, replaces the element with nodes parsed from the given string.
func (e *Element) OuterHTML() string {
return e.v.Get("outerHTML").String()
}

// SetOuterHTML is a DOMString representing the markup of the element including its content. When used as a setter, replaces the element with nodes parsed from the given string.
func (e *Element) SetOuterHTML(v string) {
e.v.Set("outerHTML", v)
}

// Prefix a DOMString representing the namespace prefix of the element, or null if no prefix is specified.
func (e *Element) Prefix() string {
return e.v.Get("prefix").String()
}

// ScrollHeight returns a Number representing the scroll view height of an element.
func (e *Element) ScrollHeight() int {
return e.v.Get("scrollHeight").Int()
}

// ScrollLeft is a Number representing the left scroll offset of the element.
func (e *Element) ScrollLeft() int {
return e.v.Get("scrollLeft").Int()
}

// SetScrollLeft is a Number representing the left scroll offset of the element.
func (e *Element) SetScrollLeft(v int) {
e.v.Set("scrollLeft", v)
}

// ScrollLeftMax returns a Number representing the maximum left scroll offset possible for the element.
func (e *Element) ScrollLeftMax() int {
return e.v.Get("scrollLeftMax").Int()
}

// ScrollTop a Number representing number of pixels the top of the document is scrolled vertically.
func (e *Element) ScrollTop() int {
return e.v.Get("scrollTop").Int()
}

// SetScrollTop a Number representing number of pixels the top of the document is scrolled vertically.
func (e *Element) SetScrollTop(v int) {
e.v.Set("scrollTop", v)
}

// ScrollTopMax returns a Number representing the maximum top scroll offset possible for the element.
func (e *Element) ScrollTopMax() int {
return e.v.Get("scrollTopMax").Int()
}

// ScrollWidth returns a Number representing the scroll view width of the element.
func (e *Element) ScrollWidth() int {
return e.v.Get("scrollWidth").Int()
}

// Shadow returns the open shadow root that is hosted by the element, or null if no open shadow root is present.
func (e *Element) ShadowRoot() *ShadowRoot {
return AsShadowRoot(e.v.Get("shadowRoot"))
}

// Slot returns the name of the shadow DOM slot the element is inserted in.
func (e *Element) Slot() string {
return e.v.Get("slot").String()
}

// SetSlot returns the name of the shadow DOM slot the element is inserted in.
func (e *Element) SetSlot(v string) {
e.v.Set("slot", v)
}

// TabStop is a Boolean indicating if the element can receive input focus via the tab key.
func (e *Element) TabStop() bool {
return e.v.Get("tabStop").Bool()
}

// SetTabStop is a Boolean indicating if the element can receive input focus via the tab key.
func (e *Element) SetTabStop(v bool) {
e.v.Set("tabStop", v)
}

// TagName returns a String with the name of the tag for the given element.
func (e *Element) TagName() string {
return e.v.Get("tagName").String()
}

// UndoManager returns the UndoManager associated with the element.
func (e *Element) UndoManager() js.Value {
return e.v.Get("undoManager")
}

// UndoScope is a Boolean indicating if the element is an undo scope host, or not.
func (e *Element) UndoScope() bool {
return e.v.Get("undoScope").Bool()
}

// SetUndoScope is a Boolean indicating if the element is an undo scope host, or not.
func (e *Element) SetUndoScope(v bool) {
e.v.Set("undoScope", v)
}

// Methods

func (e *Element) SetAttribute(k string, v interface{}) {
e.v.Call("setAttribute", k, fmt.Sprint(v))
}
Expand All @@ -49,10 +229,6 @@ func (e *Element) RemoveAttribute(k string) {
e.v.Call("removeAttribute", k)
}

func (e *Element) Style() *Style {
return &Style{v: e.v.Get("style")}
}

func (e *Element) GetBoundingClientRect() Rect {
rv := e.v.Call("getBoundingClientRect")
x, y := rv.Get("x").Int(), rv.Get("y").Int()
Expand Down Expand Up @@ -82,20 +258,18 @@ func (e *Element) OnMouseUp(h MouseEventHandler) {
e.onMouseEvent("mouseup", int(sjs.StopPropagation), h)
}

func (e *Element) ClassList() *TokenList {
return AsTokenList(e.v.Get("classList"))
type AttachShadowOpts struct {
Open bool
DeligatesFocus bool
}

func (e *Element) AttachShadow(open bool) *ShadowRoot {
func (e *Element) AttachShadow(opts AttachShadowOpts) *ShadowRoot {
m := map[string]interface{}{}
if open {
if opts.Open {
m["mode"] = "open"
} else {
m["mode"] = "closed"
}
m["delegatesFocus"] = opts.DeligatesFocus
return AsShadowRoot(e.v.Call("attachShadow", js.ValueOf(m)))
}

func (e *Element) ShadowRoot() *ShadowRoot {
return AsShadowRoot(e.v.Get("shadowRoot"))
}
Loading