dom

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

View Source
var Document = &Doc{
	doc: js.Global().Get("document"),
}

Document is the global HTML "document" element

View Source
var Window = &Win{
	window: js.Global().Get("window"),
}

Window is the global HTML "window" element

Functions

This section is empty.

Types

type Doc

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

Doc is a wrapper type to provide methods to manipulate the global HTML "document" element

func (*Doc) GetElementById

func (d *Doc) GetElementById(id string) Element

GetElementById returns the child Element with the matching id

func (*Doc) GetElementsByClassName

func (d *Doc) GetElementsByClassName(class string) []Element

GetElementsByClassName returns the child Elements with the matching class

type Element

type Element interface {
	// AddEventListener allows you to add a custom event listener
	// to an Element with the given name
	AddEventListener(name string, fn func(args ...js.Value) interface{})
	// On adds an event listener to a specific "on" event
	On(name OnEvent, fn func(args ...js.Value) interface{})
	// RemoveEventListener removes the event listener from an Element
	// with the given name. fn must match the same event listener that
	// was set for the given name whenever AddEventListener was called
	RemoveEventListener(name string, fn func(args ...js.Value) interface{}, isCapture bool)
	// DispatchEvent dispatches the provided Event to the Element
	// it is called on
	DispatchEvent(event *Event)
	// GetElementById returns the child Element with
	// the matching id
	GetElementById(id string) Element
	// GetElementsByClassName returns the child Elements with
	// the matching class
	GetElementsByClassName(class string) []Element
	// GetInnerHTML returns the inner HTML content of
	// the Element it was called on
	GetInnerHTML() string
	// SetInnerHTML sets the inner HTML content of
	// the Element it was called on
	SetInnerHTML(inner string)
	// GetOuterHTML returns the outer HTML content of
	// the Element it was called on
	GetOuterHTML() string
	// SetOuterHTML sets the outer HTML content of
	// the Element it was called on
	SetOuterHTML(outer string)
	// GetAttribute returns the given value
	// for the specified attr of the Element
	// it was called on
	GetAttribute(attr string) js.Value
	// SetAttribute sets the given value
	// for the specified attr of the Element
	// it was called on
	SetAttribute(attr string, val string)
	// GetId returns the ID of the Element
	// it was called on as a string
	GetId() string
	// GetClasses returns a slice of all
	// classes for a given Element
	GetClasses() []string
}

Element is an interface for interacting with specific HTML elements

type Event added in v0.3.0

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

Event is a new JavaScript Event

func NewEvent added in v0.3.0

func NewEvent(name string, opts *EventOptions) *Event

NewEvent creates a new *Event with the provided options

type EventOptions added in v0.3.0

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

EventOptions is used to configure options for a new Event

func NewEventOptions added in v0.3.0

func NewEventOptions(bubbles bool, cancelable bool, composed bool) *EventOptions

type OnEvent

type OnEvent string
const (
	// Window Events
	//
	OnAfterPrint   OnEvent = "onafterprint"
	OnBeforePrint  OnEvent = "onbeforeprint"
	OnBeforeUnload OnEvent = "onbeforeunload"
	OnHashChange   OnEvent = "onhashchange"
	Onload         OnEvent = "onload"
	OnMessage      OnEvent = "onmessage"
	OnOffline      OnEvent = "onoffline"
	OnOnline       OnEvent = "ononline"
	OnPageHide     OnEvent = "onpagehide"
	OnPageShow     OnEvent = "onpageshow"
	OnPopState     OnEvent = "onpopstate"
	OnResize       OnEvent = "onresize"
	OnStorage      OnEvent = "onstorage"
	OnUnload       OnEvent = "onunload"
	//
	// Form Events
	//
	OnBlur        OnEvent = "onblur"
	OnChange      OnEvent = "onchange"
	OnContextMenu OnEvent = "oncontextmenu"
	OnFocus       OnEvent = "onfocus"
	OnInput       OnEvent = "oninput"
	OnInvalid     OnEvent = "oninvalid"
	OnReset       OnEvent = "onreset"
	OnSearch      OnEvent = "onsearch"
	OnSelect      OnEvent = "onselect"
	OnSubmit      OnEvent = "onsubmit"
	//
	// Keyboard Events
	//
	OnKeyDown  OnEvent = "onkeydown"
	OnKeyPress OnEvent = "onkeypress"
	OnKeyUp    OnEvent = "onkeyup"
	//
	// Mouse Events
	//
	OnClick       OnEvent = "onclick"
	OnDoubleClick OnEvent = "ondblclick"
	OnMouseDown   OnEvent = "onmousedown"
	OnMouseMove   OnEvent = "onmousemove"
	OnMouseOut    OnEvent = "onmouseout"
	OnMouseOver   OnEvent = "onmouseover"
	OnMouseUp     OnEvent = "onmouseup"
	OnMouseWheel  OnEvent = "onmousewheel"
	OnWheel       OnEvent = "onwheel"
	//
	// Drag Events
	//
	OnDrag      OnEvent = "ondrag"
	OnDragEnd   OnEvent = "ondragend"
	OnDragEnter OnEvent = "ondragenter"
	OnDragLeave OnEvent = "ondragleave"
	OnDragOver  OnEvent = "ondragover"
	OnDragStart OnEvent = "ondragstart"
	OnDrop      OnEvent = "ondrop"
	OnScroll    OnEvent = "onscroll"
	//
	// Clipboard Events
	//
	OnCopy         OnEvent = "oncopy"
	OnCut          OnEvent = "oncut"
	OnPasteOnEvent         = "onpaste"
	//
	// Media Events
	//
	OnAbort          OnEvent = "onabort"
	OnCanPlay        OnEvent = "oncanplay"
	OnCanPlayThrough OnEvent = "oncanplaythrough"
	OnCueChange      OnEvent = "oncuechange"
	OnDurationChange OnEvent = "ondurationchange"
	OnEmptied        OnEvent = "onemptied"
	OnEnded          OnEvent = "onended"
	OnLoadedData     OnEvent = "onloadeddata"
	OnLoadedMetaData OnEvent = "onloadedmetadata"
	OnLoadStart      OnEvent = "onloadstart"
	OnPause          OnEvent = "onpause"
	OnPlay           OnEvent = "onplay"
	OnPlaying        OnEvent = "onplaying"
	OnProgress       OnEvent = "onprogress"
	OnRateChange     OnEvent = "onratechange"
	OnSeeked         OnEvent = "onseeked"
	OnSeeking        OnEvent = "onseeking"
	OnStalled        OnEvent = "onstalled"
	OnSuspended      OnEvent = "onsuspend"
	OnTimeUpdate     OnEvent = "ontimeupdate"
	OnVolumeChange   OnEvent = "onvolumechange"
	OnWaiting        OnEvent = "onwaiting"
	//
	// Misc
	//
	OnToggle OnEvent = "ontoggle"
	OnError  OnEvent = "onerror"
)

type Win

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

Win is a wrapper type to provide methods to manipulate the global HTML "window" element

func (*Win) GetElementById

func (w *Win) GetElementById(id string) Element

GetElementById returns the child Element with the matching id

func (*Win) GetElementsByClassName

func (w *Win) GetElementsByClassName(class string) []Element

GetElementsByClassName returns the child Elements with the matching class

func (*Win) On

func (w *Win) On(name OnEvent, fn func(args ...js.Value) interface{})

On adds an event listener to a specific "on" event

Jump to

Keyboard shortcuts

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