dom

package
v0.2.14 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 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"
	EventFocus                = "focus"
	EventFocusIn              = "focusin"
	EventFocusOut             = "focusout"
	EventInput                = "input"
	EventKeyDown              = "keydown"
	EventKeyUp                = "keyup"
	EventMouseDown            = "mousedown"
	EventMouseEnter           = "mouseenter"
	EventMouseLeave           = "mouseleave"
	EventMouseMove            = "mousemove"
	EventMouseUp              = "mouseup"
	EventMouseWheel           = "mousewheel"
	EventResize               = "resize"
)

Variables

This section is empty.

Functions

func CaretMove

func CaretMove(pos int)

CaretMove moves caret position inside the current selection.

func Handle

func Handle(event EventName, h Handler)

Handle registers a document event listener.

func HandleRemove

func HandleRemove(event EventName, h Handler)

HandleRemove deregisters a document event listener.

func TextInsert added in v0.2.9

func TextInsert(str string)

TextInsert inserts the given string at the current cursor position.

func TextSelect added in v0.2.9

func TextSelect(start, end int)

TextSelect selects text inside the current active element.

func Url added in v0.2.9

func Url() url.URL

Url returns the current navigation URL.

func WindowHandle added in v0.2.9

func WindowHandle(event EventName, h Handler)

func WindowHandleRemove added in v0.2.9

func WindowHandleRemove(event EventName, h Handler)

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 ElementById added in v0.2.9

func ElementById(id string) (Element, error)

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

func ElementsByKind added in v0.2.9

func ElementsByKind(kind ElementKind) []Element

ElementsByKind 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) 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() bool

func (Element) FocusSet added in v0.2.9

func (x Element) FocusSet(v bool)

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 HandlerMake added in v0.2.9

func HandlerMake(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) Code added in v0.2.14

func (x KeyboardEvent) Code() string

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 SvgMake added in v0.2.9

func SvgMake() 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