domini

package module
v0.0.0-...-6fc4ff9 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 1 Imported by: 0

README

domini -- Mini DOM Interface For Golang/WASM

This is an unstable alpha version. No guarantees whatsoever.

A minimalistiv package to access the web page's DOM from a go web app when using WebAssembly (wasm). With this package the following cumbersome, verbose line of code

  doc := js.Global().Get("document)
  doc.Call("getElementById", "msg").Get("style").Call("setProperty", "display", "block", "") 

becomes a lot more tidy:

  doc := domini.GetWindow().Document()
  doc.GetElementById("msg").Style().SetProperty("display", "block", "")

As you can see, this is a little shorter, much easier to read, and hell of a lot faster to type as most of the typing can be done by the source code completion of your editor. Also less error-prone as the compiler can check method names where there were string arguments before.

Install this package using go get or require it as a as module.

Documentation

Rendered for js/wasm

Overview

Package domini is minimalistiv package to access the web pages DOM from a go web app when using WebAssembly (wasm)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Null

func Null() js.Value

func Undefined

func Undefined() js.Value

Types

type Class

type Class interface {
	Underlyer
	Add(classes ...string)
	Remove(classes ...string)
	Contains(class string) bool
}

Class represents the class list of an HTML element

type Document

type Document interface {
	Underlyer
	EventTarget
	EventSource
	Queryer
	GetElementByID(id string) HTMLElement
	Body() HTMLElement
	DocumentElement() HTMLElement
	CreateElement(tag string) HTMLElement
	CreateElementNS(ns, tag string) HTMLElement
}

Document represents the DOM root element

type Event

type Event interface {
	Underlyer
	PreventDefault()
	StopPropagation()
}

Event represents a DOM event

func NewEvent

func NewEvent(t string) Event

NewEvent returns a new event of type t

type EventSource

type EventSource interface {
	DispatchEvent(ev Event)
}

EventSource is implemented by all elements that dispatch events

type EventTarget

type EventTarget interface {
	AddEventListener(event string, useCapture bool, function func(Event)) js.Func
	RemoveEventListener(event string, useCapture bool, cb js.Func)
}

EventTarget is implemented by all elements that receive events

type HTMLElement

type HTMLElement interface {
	Underlyer
	EventTarget
	EventSource
	Queryer
	ID() string
	SetID(id string)
	TagName() string
	Class() Class
	Style() Style
	SetInnerHTML(html string)
	InnerHTML() string
	SetAttribute(attr, value string)
	AppendChild(el HTMLElement)
	RemoveChild(el HTMLElement)
	ChildElements() []HTMLElement
	ParentElement() HTMLElement
	SetData(name, value string)
	Data(name string) js.Value
}

HTMLElement represents an HTML element in a DOM

type Queryer

type Queryer interface {
	QuerySelector(query string) HTMLElement
	QuerySelectorAll(query string) []HTMLElement
}

Queryer implements document querying functions

type Style

type Style interface {
	Underlyer
	SetProperty(prop, value, prio string)
	Property(prop string) string
	RemoveProperty(prop string)
}

Style represents the CSS style declaration of an HTML element

type Underlyer

type Underlyer interface {
	Underlying() js.Value
	IsUndefined() bool
	IsNull() bool
}

Underlying is implemented by all DOM elements. It is used to access the underlying js.Value.

type Window

type Window interface {
	Underlyer
	EventTarget
	EventSource
	Document() Document
}

Window represents the window

func GetWindow

func GetWindow() Window

GetWindow returns the root handle into JS

Jump to

Keyboard shortcuts

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