dom

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package dom wraps JS DOM functionality.

Index

Constants

View Source
const (
	EventBlur       EventName = "blur"
	EventChange               = "change"
	EventClick                = "click"
	EventClickRight           = "contextmenu"
	EventFocusIn              = "focusin"
	EventFocusOut             = "focusout"
	EventInput                = "input"
	EventKeyDown              = "keydown"
	EventKeyUp                = "keyup"
	EventMouseDown            = "mousedown"
	EventMouseEnter           = "mouseenter"
	EventMouseLeave           = "mouseleave"
	EventMouseMove            = "mousemove"
	EventMouseUp              = "mouseup"
	EventMouseWheel           = "mousewheel"
)

Variables

This section is empty.

Functions

func CaretMove

func CaretMove(pos int)

CaretMove moves caret position inside the current selection.

func GetUrl

func GetUrl() url.URL

func Handle

func Handle(event EventName, h Handler)

func HandleRemove

func HandleRemove(event EventName, h Handler)

func InsertText

func InsertText(str string)

InsertText inserts the given string at the current cursor position.

func SelectText

func SelectText(start, end int)

SelectText selects text inside the current active element.

Types

type Base

type Base interface {
	Base() Element
}

type Element

type Element struct {
	js.Value // underlying JS object
}

A Base represents a JS DOM element and forms the basis of this package. It wraps js.Value and gives access to all its funcionality.

func GetId

func GetId(id string) (Element, error)

GetId returns the element with the given ID in the document. Returns an error if the ID doesn't exist.

func GetKind

func GetKind(kind ElementKind) []Element

GetKind returns all elements of the specified kind (tag).

func (Element) Add

func (x Element) Add(pos int, e ...Base)

Add adds the given elements as subelements, at the given position.

func (Element) Append

func (x Element) Append(e ...Base)

Append adds the given elements as final subelement.

func (Element) Base

func (x Element) Base() Element

func (Element) Blur

func (x Element) Blur()

func (Element) Class

func (x Element) Class() string

func (Element) ClassSet

func (x Element) ClassSet(name string)

func (Element) Delete

func (x Element) Delete(i int)

Delete removes the subelement at index i.

func (Element) EditableSet

func (x Element) EditableSet(t bool)

func (Element) Focus

func (x Element) Focus()

func (Element) Handle

func (x Element) Handle(event EventName, h Handler)

Handle subscribes the given Handler to the specified event.

func (Element) HandleRemove

func (x Element) HandleRemove(event EventName, h Handler)

HandleRemove unsubscribes the given Handler from the specified event.

func (Element) Height

func (x Element) Height() uint16

func (Element) HeightVisible added in v0.2.4

func (x Element) HeightVisible() uint16

func (Element) Id

func (x Element) Id() string

func (Element) IdSet

func (x Element) IdSet(id string)

func (Element) Kind

func (x Element) Kind() ElementKind

func (Element) Len

func (x Element) Len() int

Len returns the number of subelement.

func (Element) Next

func (x Element) Next() Element

Next returns the next element in the same node. Returns an empty Element if there is none.

func (Element) Previous

func (x Element) Previous() Element

Previous returns the previous element in the same node. Returns an empty Element if there is none.

func (Element) Remove

func (x Element) Remove(e ...Base)

Remove removes the specified subelements.

func (Element) RemoveSelf

func (x Element) RemoveSelf()

RemoveSelf removes the target Element from the dom

func (Element) Replace

func (x Element) Replace(newElem, oldElem Base)

func (Element) SpellcheckSet

func (x Element) SpellcheckSet(val bool)

func (Element) Style

func (x Element) Style(style ...css.Style)

Style sets the value of the specified style component.

func (Element) Sub

func (x Element) Sub(i int) Element

func (Element) SubKind

func (x Element) SubKind(kind ElementKind) []Element

func (Element) Super

func (x Element) Super() Element

func (Element) TabIndexSet added in v0.2.4

func (x Element) TabIndexSet(i int)

func (Element) Text

func (x Element) Text() string

Text returns the inner HTML text node value. Panics if x does not contain a text node.

func (Element) TextSet

func (x Element) TextSet(s string)

TextSet sets the inner HTML of x as a text node with the provided value.

func (Element) Width

func (x Element) Width() uint16

func (Element) WidthVisible added in v0.2.4

func (x Element) WidthVisible() uint16

type ElementKind

type ElementKind string

type Event

type Event struct {
	js.Value
}

An Event wraps a JS event object

func (Event) Cancel

func (x Event) Cancel()

func (Event) CancelDefault

func (x Event) CancelDefault()

func (Event) Target

func (x Event) Target() Element

type EventName

type EventName string

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

A Handler wraps a JS event handler function.

func MakeHandler

func MakeHandler(fn func(Event)) Handler

MakeHandler wraps a Go function to be used as a DOM event handler. fn must be non blocking, otherwise the application will deadlock. Notably, http requests block.

func (Handler) Delete

func (x Handler) Delete()

Delete releases the underlying JS function.

type KeyboardEvent

type KeyboardEvent struct {
	Event
}

func (KeyboardEvent) Ctrl

func (x KeyboardEvent) Ctrl() bool

Ctrl returns true if the Ctrl key is being pressed.

func (KeyboardEvent) Key

func (x KeyboardEvent) Key() string

type MouseEvent

type MouseEvent struct {
	Event
}

func (MouseEvent) Button added in v0.2.4

func (x MouseEvent) Button() byte

func (MouseEvent) XAbs added in v0.2.4

func (x MouseEvent) XAbs() uint16

func (MouseEvent) XRel added in v0.2.4

func (x MouseEvent) XRel() uint16

func (MouseEvent) YAbs added in v0.2.4

func (x MouseEvent) YAbs() uint16

func (MouseEvent) YRel added in v0.2.4

func (x MouseEvent) YRel() uint16

type Svg

type Svg struct {
	Element
}

func MakeSvg

func MakeSvg() Svg

func (Svg) Append

func (x Svg) Append(e ...svg.Element)

func (Svg) Sub

func (x Svg) Sub(i int) js.Value

type WheelEvent added in v0.2.4

type WheelEvent struct {
	Event
}

func (WheelEvent) Y added in v0.2.4

func (x WheelEvent) Y() int8

Directories

Path Synopsis
Package elements provides definitions for common DOM elements.
Package elements provides definitions for common DOM elements.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL