dom

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package dom provides APIs for interacting with the DOM.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Doc is the default 'document' object.  This should be used for regular
	// code. See NewDocForTesting() for a Document object that can be used in
	// unit tests.
	Doc = js.Global().Get("document")

	// Console is the default 'console' object for the browser.
	Console = js.Global().Get("console")

	// Object refers to Javascript's Object class.
	Object = js.Global().Get("Object")

	// JSON refers to Javascript's JSON class.
	JSON = js.Global().Get("JSON")
)

Functions

func DefaultQueryString added in v0.0.12

func DefaultQueryString() string

DefaultQueryString returns the query string used to request the current document. This is likely not available during unit tests, but is available in normal operation.

func ExpandArgs added in v0.0.20

func ExpandArgs(args []js.Value, target ...*js.Value)

ExpandArgs unpacks function arguments to target values.

func FromJSON added in v0.0.20

func FromJSON(s string) js.Value

FromJSON converts the supplied JSON string to a Javascript value.

func Log added in v0.0.20

func Log(format string, objs ...interface{})

Log logs general information to the Javascript Console.

func LogDebug added in v0.0.20

func LogDebug(format string, objs ...interface{})

LogDebug logs a debug message to the Javascript Console.

func LogError added in v0.0.20

func LogError(format string, objs ...interface{})

LogError logs an error to the Javascript Console.

func ObjectKeys added in v0.0.20

func ObjectKeys(val js.Value) ([]string, error)

ObjectKeys returns the keys for a given object.

func SetTimeout added in v0.0.20

func SetTimeout(timeout time.Duration, callback func())

SetTimeout registers a callback to be invoked when the timeout has expired.

func SingleArg added in v0.0.20

func SingleArg(args []js.Value) js.Value

SingleArg unpacks a single function argument and returns it.

func ToJSON added in v0.0.20

func ToJSON(val js.Value) string

ToJSON converts the supplied value to a JSON string.

Types

type DOM

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

DOM provides an API for interacting with the DOM for a Document.

func New

func New(doc js.Value) *DOM

New returns a DOM instance for interacting with the specified Document object.

func (*DOM) AppendChild

func (d *DOM) AppendChild(parent, child js.Value, populate func(child js.Value))

AppendChild adds the child object. If non-nil, the populate() function is invoked on the child to initialize it.

func (*DOM) Close

func (d *DOM) Close(o js.Value)

Close closes the specified dialog.

func (*DOM) DoClick

func (d *DOM) DoClick(o js.Value)

DoClick simulates a click. Any callback registered by OnClick() will be invoked.

func (*DOM) GetElement

func (d *DOM) GetElement(id string) js.Value

GetElement returns the element with the specified ID.

func (*DOM) GetElementsByTag added in v0.0.12

func (d *DOM) GetElementsByTag(tag string) []js.Value

GetElementsByTag returns the elements with the speciied tag.

func (*DOM) NewElement

func (d *DOM) NewElement(tag string) js.Value

NewElement returns a new element with the specified tag (e.g., 'tr', 'td').

func (*DOM) NewText

func (d *DOM) NewText(text string) js.Value

NewText returns a new text element with the specified text.

func (*DOM) OnClick

func (d *DOM) OnClick(o js.Value, callback func(evt Event))

OnClick registers a callback to be invoked when the specified object is clicked.

func (*DOM) OnDOMContentLoaded

func (d *DOM) OnDOMContentLoaded(callback func())

OnDOMContentLoaded registers a callback to be invoked when the DOM has finished loading.

func (*DOM) RemoveChildren

func (d *DOM) RemoveChildren(p js.Value)

RemoveChildren removes all children of the specified node.

func (*DOM) RemoveEventListeners added in v0.0.8

func (d *DOM) RemoveEventListeners(o js.Value) js.Value

RemoveEventListeners removes all event listeners from an object and its children. This is accomplished by cloning the object, which has the side effect of *not* cloning the event listeners. The newly-created object is returned.

func (*DOM) SetValue

func (d *DOM) SetValue(o js.Value, value string)

SetValue sets the of the object.

func (*DOM) ShowModal

func (d *DOM) ShowModal(o js.Value)

ShowModal shows the specified dialog as a modal dialog.

func (*DOM) TextContent

func (d *DOM) TextContent(o js.Value) string

TextContent returns the text content of the specified object (and its children).

func (*DOM) Value

func (d *DOM) Value(o js.Value) string

Value returns the value of an object as a string.

type Event added in v0.0.20

type Event struct {
	js.Value
}

Event provides an API for interacting with events.

type URLSearchParams added in v0.0.12

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

URLSearchParams is a thin wrapper around the URLSearchParams API. See https://url.spec.whatwg.org/#urlsearchparams.

func NewURLSearchParams added in v0.0.12

func NewURLSearchParams(queryString string) *URLSearchParams

NewURLSearchParams returns a URLSearchParams for the specified query string.

func (*URLSearchParams) Has added in v0.0.12

func (u *URLSearchParams) Has(param string) bool

Has indicates if the query string contains the specified parameter.

Directories

Path Synopsis
Package testing provides utilities for using the DOM in unit tests.
Package testing provides utilities for using the DOM in unit tests.

Jump to

Keyboard shortcuts

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