Documentation
¶
Overview ¶
Package dom provides a basic DOM manipulation wrapper using syscall/js.
Index ¶
- func AddClass(elemID, class string)
- func AddElementTo(target, elem Handle)
- func AddEventListener(elem Handle, event string, cb js.Value)
- func AddEventListenerByID(id, event string, cb js.Value)
- func AddNewStyleElement(css string)
- func AddToBody(elem Handle)
- func Alert(msg string)
- func GetString(elemID, key string) string
- func Hide(id string)
- func Init()
- func Log(messages []string)
- func RemoveAllChildElementsFrom(target Handle)
- func RemoveClass(elemID, class string)
- func SetFocus(id string)
- func SetValue(elemID, key, value string)
- func Show(id string)
- func StartAnimationLoop(cb js.Value) (stop func())
- type Context2D
- type Handle
- func CanvasCreate(parent Handle, width, height int) Handle
- func CanvasGetContext(canvas Handle) Handle
- func CreateButton(text string) Handle
- func CreateDiv() Handle
- func CreateElement(tag string) Handle
- func CreateImg(src string) Handle
- func CreateParagraph() Handle
- func CreateParagraphWithText(text string) Handle
- func GetElementByID(id string) Handle
- func WrapElementWithNewDiv(element Handle, classes []string) Handle
- func (h Handle) AddClassTo(class string)
- func (h Handle) Get(key string) string
- func (h Handle) IsValid() bool
- func (h Handle) RemoveClassFrom(class string)
- func (h Handle) ReplaceClasses(classes []string)
- func (h Handle) Set(key string, value any)
- func (h Handle) SetInnerHTML(html string)
- func (h Handle) SetInnerText(text string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddClass ¶
func AddClass(elemID, class string)
------------------------------------------------------------------------------------------------ AddClass adds a CSS class to the element looked up by ID.
func AddElementTo ¶
func AddElementTo(target, elem Handle)
------------------------------------------------------------------------------------------------ AddElementTo appends a child element to a target element.
func AddEventListener ¶
------------------------------------------------------------------------------------------------ AddEventListener registers an event listener on the element.
func AddEventListenerByID ¶
------------------------------------------------------------------------------------------------ AddEventListenerByID registers an event listener on the element matching the ID.
func AddNewStyleElement ¶
func AddNewStyleElement(css string)
------------------------------------------------------------------------------------------------ AddNewStyleElement injects a style block with raw CSS rules into document head.
func AddToBody ¶
func AddToBody(elem Handle)
------------------------------------------------------------------------------------------------ AddToBody appends a child element to the document body.
func Alert ¶
func Alert(msg string)
------------------------------------------------------------------------------------------------ Alert triggers a browser modal dialog with the specified message.
func GetString ¶
------------------------------------------------------------------------------------------------ GetString retrieves a string property from an element by ID.
func Hide ¶
func Hide(id string)
------------------------------------------------------------------------------------------------ Hide sets display to "none" on the element matching the ID.
func Init ¶
func Init()
------------------------------------------------------------------------------------------------ Init captures global JS references from the browser.
func Log ¶
func Log(messages []string)
------------------------------------------------------------------------------------------------ Log logs a slice of strings to the browser developer console.
func RemoveAllChildElementsFrom ¶
func RemoveAllChildElementsFrom(target Handle)
------------------------------------------------------------------------------------------------ RemoveAllChildElementsFrom removes all children from the target element.
func RemoveClass ¶
func RemoveClass(elemID, class string)
------------------------------------------------------------------------------------------------ RemoveClass removes a CSS class from the element looked up by ID.
func SetFocus ¶
func SetFocus(id string)
------------------------------------------------------------------------------------------------ SetFocus calls focus() on the element matching the ID.
func SetValue ¶
func SetValue(elemID, key, value string)
------------------------------------------------------------------------------------------------ SetValue sets a string property on an element by ID.
func Show ¶
func Show(id string)
------------------------------------------------------------------------------------------------ Show sets display to "block" on the element matching the ID.
func StartAnimationLoop ¶
------------------------------------------------------------------------------------------------ StartAnimationLoop drives a 60 FPS animation cycle via requestAnimationFrame. It returns a stop function; calling it halts the loop and releases the JS closure.
Types ¶
type Context2D ¶
type Context2D struct {
Ctx Handle
}
------------------------------------------------------------------------------------------------ Context2D wraps the canvas 2D rendering context.
func (Context2D) Arc ¶
------------------------------------------------------------------------------------------------ Arc draws a circular arc on the rendering context.
func (Context2D) BeginPath ¶
func (c Context2D) BeginPath()
------------------------------------------------------------------------------------------------ BeginPath begins a new path in the rendering context.
type Handle ¶
------------------------------------------------------------------------------------------------ Handle represents a reference to a live JS object in the browser.
------------------------------------------------------------------------------------------------ Global element references.
var Invalid Handle
------------------------------------------------------------------------------------------------ Invalid represents a null/invalid handle.
func CanvasCreate ¶
------------------------------------------------------------------------------------------------ CanvasCreate creates a canvas element and appends it to parent.
func CanvasGetContext ¶
------------------------------------------------------------------------------------------------ CanvasGetContext retrieves the 2D rendering context of the canvas.
func CreateButton ¶
------------------------------------------------------------------------------------------------ CreateButton creates a button element of type "button" with pre-set inner text.
func CreateDiv ¶
func CreateDiv() Handle
------------------------------------------------------------------------------------------------ CreateDiv creates a new div element.
func CreateElement ¶
------------------------------------------------------------------------------------------------ CreateElement creates a new HTML element of the given tag name.
func CreateImg ¶
------------------------------------------------------------------------------------------------ CreateImg creates an img element with pre-set src.
func CreateParagraph ¶
func CreateParagraph() Handle
------------------------------------------------------------------------------------------------ CreateParagraph creates a new p element.
func CreateParagraphWithText ¶
------------------------------------------------------------------------------------------------ CreateParagraphWithText creates a new p element with pre-set inner text.
func GetElementByID ¶
------------------------------------------------------------------------------------------------ GetElementByID returns the element handle matching the specified ID.
func WrapElementWithNewDiv ¶
------------------------------------------------------------------------------------------------ WrapElementWithNewDiv wraps an existing element in a new div with the given classes.
func (Handle) AddClassTo ¶
------------------------------------------------------------------------------------------------ AddClassTo adds a CSS class to the element.
func (Handle) Get ¶
------------------------------------------------------------------------------------------------ Get gets a JS property on the handle as a string.
func (Handle) IsValid ¶
------------------------------------------------------------------------------------------------ IsValid checks if the handle is valid (truthy in the JS sense).
func (Handle) RemoveClassFrom ¶
------------------------------------------------------------------------------------------------ RemoveClassFrom removes a CSS class from the element.
func (Handle) ReplaceClasses ¶
------------------------------------------------------------------------------------------------ ReplaceClasses replaces all classes on the element with the given list.
func (Handle) Set ¶
------------------------------------------------------------------------------------------------ Set sets a JS property on the handle to an arbitrary value.
func (Handle) SetInnerHTML ¶
------------------------------------------------------------------------------------------------ SetInnerHTML sets the inner HTML of an element.
func (Handle) SetInnerText ¶
------------------------------------------------------------------------------------------------ SetInnerText sets the inner text of an element.