Documentation ¶
Overview ¶
Package dom contains bits for making dealing with the DOM easier.
Index ¶
- Constants
- type Ace
- type AceEditor
- type AceSession
- type ClassList
- type Document
- type Element
- type FakeClassList
- type FakeDocument
- type FakeElement
- func (e *FakeElement) AddChildren(children ...Element) Element
- func (e *FakeElement) AddEventListener(event string, handler func(Object)) Element
- func (e *FakeElement) ClassList() ClassList
- func (e *FakeElement) Display(style string) Element
- func (e *FakeElement) GetAttribute(attr string) Object
- func (e *FakeElement) Hide() Element
- func (e *FakeElement) ID() string
- func (e *FakeElement) Parent() Element
- func (e *FakeElement) RemoveAttribute(attr string) Element
- func (e *FakeElement) RemoveChildren(children ...Element) Element
- func (e *FakeElement) SetAttribute(attr string, value interface{}) Element
- func (e *FakeElement) Show() Element
- type FakeObject
- func (o *FakeObject) Bool() bool
- func (o *FakeObject) Call(method string, args ...interface{}) Object
- func (o *FakeObject) Delete(key string)
- func (o *FakeObject) Float() float64
- func (o *FakeObject) Get(key string) Object
- func (o *FakeObject) Index(i int) Object
- func (o *FakeObject) Int() int
- func (o *FakeObject) Int64() int64
- func (o *FakeObject) Interface() interface{}
- func (o *FakeObject) Invoke(args ...interface{}) Object
- func (o *FakeObject) Length() int
- func (o *FakeObject) New(args ...interface{}) Object
- func (o *FakeObject) Set(key string, value interface{})
- func (o *FakeObject) SetIndex(i int, value interface{})
- func (o *FakeObject) String() string
- func (o *FakeObject) Uint64() uint64
- func (o *FakeObject) Unsafe() uintptr
- type Hterm
- type IO
- type MethodFunc
- type Object
- type Terminal
Constants ¶
const ( // Ace modes. AceGoMode = "ace/mode/golang" AceJSONMode = "ace/mode/json" // Ace themes. AceChromeTheme = "ace/theme/chrome" AceTomorrowNightBrightTheme = "ace/theme/tomorrow_night_bright" )
Ace editor modes and themes.
const ( SVGNamespaceURI = "http://www.w3.org/2000/svg" XHTMLNamespaceURI = "http://www.w3.org/1999/xhtml" )
Well-known Namespace URIs.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AceEditor ¶
type AceEditor struct {
Object
}
AceEditor is an Ace editor.
func (*AceEditor) Session ¶
func (e *AceEditor) Session() *AceSession
Session returns a session for this editor.
type AceSession ¶
type AceSession struct {
Object
}
AceSession is an Ace editor session.
func (*AceSession) On ¶
func (s *AceSession) On(event string, h func(e Object)) *AceSession
On adds a handler (on change, etc).
func (*AceSession) SetMode ¶
func (s *AceSession) SetMode(mode string) *AceSession
SetMode sets the session mode (language).
func (*AceSession) SetUseSoftTabs ¶
func (s *AceSession) SetUseSoftTabs(b bool) *AceSession
SetUseSoftTabs changes the soft-tabs mode of the session.
func (*AceSession) SetValue ¶
func (s *AceSession) SetValue(contents string)
SetValue puts new contents in the session.
func (*AceSession) Value ¶
func (s *AceSession) Value() string
Value returns the session's current contents.
type ClassList ¶
type ClassList interface { Add(classes ...string) Remove(classes ...string) Toggle(class string) Contains(class string) bool Replace(oldClass, newClass string) }
ClassList abstracts the DOMTokenList returned by element.classList.
type Document ¶
type Document interface { Element ElementByID(string) Element MakeTextNode(string) Element MakeSVGElement(string) Element }
Document describes some things the JS document global can do.
func CurrentDocument ¶
func CurrentDocument() Document
CurrentDocument returns the global document object or nil if it does not exist.
type Element ¶
type Element interface { Object // ID returns the element ID. ID() string // GetAttribute gets the JS getAttribute method, returning the requested attribute. GetAttribute(string) Object // SetAttribute calls the JS setAttribute method, returning the element for chaining. SetAttribute(string, interface{}) Element // RemoveAttribute calls the JS removeAttribute method, returning the element for chaining. RemoveAttribute(string) Element // AddChildren calls the JS method appendChild for each element, returning the element for chaining. AddChildren(...Element) Element // RemoveChildren calls the JS method removeChild for each element, returning the element for chaining. RemoveChildren(...Element) Element // AddEventListener calls the JS method addEventListener, returning the element for chaining. AddEventListener(string, func(Object)) Element // Show sets the display attribute of the style to "", returning the element for chaining. Show() Element // Hide sets the display attribute of the style to "none", returning the element for chaining. Hide() Element // Display sets the display attribute of the style to the given value, returning the element for chaining. Display(string) Element // Parent returns the parent element. Parent() Element // ClassList returns the classList. ClassList() ClassList }
Element represents a DOM element.
func WrapElement ¶
WrapElement turns a Object into an Element, or returns nil if o is nil.
type FakeClassList ¶
type FakeClassList map[string]struct{}
FakeClassList implements a virtual classList (DOMTokenList). Unlike a real DOMTokenList, it doesn't preserve order.
func (FakeClassList) Add ¶
func (c FakeClassList) Add(classes ...string)
Add adds a class to the classlist.
func (FakeClassList) Contains ¶
func (c FakeClassList) Contains(class string) bool
Contains tests if the class is present.
func (FakeClassList) Remove ¶
func (c FakeClassList) Remove(classes ...string)
Remove removes a class from the classlist.
func (FakeClassList) Replace ¶
func (c FakeClassList) Replace(oldClass, newClass string)
Replace swaps an old class for a new one.
func (FakeClassList) String ¶
func (c FakeClassList) String() string
func (FakeClassList) Toggle ¶
func (c FakeClassList) Toggle(class string)
Toggle adds if the class is not present, and removes if it is.
type FakeDocument ¶
type FakeDocument struct {
FakeElement
}
FakeDocument implements a fake Document.
func MakeFakeDocument ¶
func MakeFakeDocument() *FakeDocument
MakeFakeDocument makes a fake document.
func (*FakeDocument) ElementByID ¶
func (d *FakeDocument) ElementByID(id string) Element
ElementByID searches the fake document for a matching element.
func (*FakeDocument) MakeSVGElement ¶
func (d *FakeDocument) MakeSVGElement(class string) Element
MakeSVGElement makes an SVG element.
func (*FakeDocument) MakeTextNode ¶
func (d *FakeDocument) MakeTextNode(text string) Element
MakeTextNode makes something that looks like a text node.
type FakeElement ¶
type FakeElement struct { FakeObject Class string NamespaceURI string Attributes map[string]interface{} Children []*FakeElement EventListeners map[string][]func(Object) Classes FakeClassList // contains filtered or unexported fields }
FakeElement implements a virtual DOM element.
func MakeFakeElement ¶
func MakeFakeElement(class, nsuri string) *FakeElement
MakeFakeElement makes a fake element.
func (*FakeElement) AddChildren ¶
func (e *FakeElement) AddChildren(children ...Element) Element
AddChildren adds child elements (*FakeElement only).
func (*FakeElement) AddEventListener ¶
func (e *FakeElement) AddEventListener(event string, handler func(Object)) Element
AddEventListener adds an event listener.
func (*FakeElement) ClassList ¶
func (e *FakeElement) ClassList() ClassList
ClassList returns the list of classes.
func (*FakeElement) Display ¶
func (e *FakeElement) Display(style string) Element
Display sets the display attribute to whatever.
func (*FakeElement) GetAttribute ¶
func (e *FakeElement) GetAttribute(attr string) Object
GetAttribute gets an attribute value.
func (*FakeElement) Hide ¶
func (e *FakeElement) Hide() Element
Hide sets the display attribute to "none".
func (*FakeElement) ID ¶
func (e *FakeElement) ID() string
ID returns e.Get("id").String() (so, set the embedded FakeObject's id property).
func (*FakeElement) Parent ¶
func (e *FakeElement) Parent() Element
Parent returns the parent element.
func (*FakeElement) RemoveAttribute ¶
func (e *FakeElement) RemoveAttribute(attr string) Element
RemoveAttribute removes an attribute.
func (*FakeElement) RemoveChildren ¶
func (e *FakeElement) RemoveChildren(children ...Element) Element
RemoveChildren removes child elements. It does it with the straightforward, naïve O(len(e.Children) * len(children)) method.
func (*FakeElement) SetAttribute ¶
func (e *FakeElement) SetAttribute(attr string, value interface{}) Element
SetAttribute sets an attribute.
type FakeObject ¶
type FakeObject struct { Value interface{} Properties map[string]interface{} Methods map[string]MethodFunc }
FakeObject implements a fake Object that sort of works like *js.Object.
func MakeFakeObject ¶
func MakeFakeObject(value interface{}) *FakeObject
MakeFakeObject makes a FakeObject.
func (*FakeObject) Call ¶
func (o *FakeObject) Call(method string, args ...interface{}) Object
Call calls a method. In the case of fakes, this returns a pointer that gets used as a key in ObjectsToValues.
func (*FakeObject) Delete ¶
func (o *FakeObject) Delete(key string)
Delete deletes the property with the given key.
func (*FakeObject) Float ¶
func (o *FakeObject) Float() float64
Float returns o.Value asserted as a float64.
func (*FakeObject) Get ¶
func (o *FakeObject) Get(key string) Object
Get gets a "property value". In the case of fakes, this is a pointer that gets used as a key in ObjectsToValues.
func (*FakeObject) Index ¶
func (o *FakeObject) Index(i int) Object
Index returns the element at index i of o.Value.
func (*FakeObject) Int64 ¶
func (o *FakeObject) Int64() int64
Int64 returns o.Value asserted as an int64.
func (*FakeObject) Interface ¶
func (o *FakeObject) Interface() interface{}
Interface returns o.Value.
func (*FakeObject) Invoke ¶
func (o *FakeObject) Invoke(args ...interface{}) Object
Invoke calls the function in o.Value.
func (*FakeObject) New ¶
func (o *FakeObject) New(args ...interface{}) Object
New calls the function in o.Value.
func (*FakeObject) Set ¶
func (o *FakeObject) Set(key string, value interface{})
Set sets a property value.
func (*FakeObject) SetIndex ¶
func (o *FakeObject) SetIndex(i int, value interface{})
SetIndex sets the value at index i of o.Value to value.
func (*FakeObject) String ¶
func (o *FakeObject) String() string
String returns o.Value asserted as a string.
func (*FakeObject) Uint64 ¶
func (o *FakeObject) Uint64() uint64
Uint64 returns o.Value asserted as a uint64.
func (*FakeObject) Unsafe ¶
func (o *FakeObject) Unsafe() uintptr
Unsafe returns o.Value asserted as a uintptr.
type Hterm ¶
Hterm represents a global hterm object.
func (Hterm) NewTerminal ¶
NewTerminal creates a new Terminal with the given profile.
type IO ¶
IO represents a hterm IO object.
func (IO) OnVTKeystroke ¶
OnVTKeystroke registers a keystroke handler.
func (IO) Push ¶
Push pushes an IO, something something nested IO sessions, see hterm documentation.
func (IO) SendString ¶
SendString registers a handler for sendString.
type MethodFunc ¶
type MethodFunc func(...interface{}) interface{}
MethodFunc is what a typical method looks like... sort of.
type Object ¶
type Object interface { Get(string) Object Set(string, interface{}) Delete(string) Length() int Index(int) Object SetIndex(int, interface{}) Call(string, ...interface{}) Object Invoke(...interface{}) Object New(...interface{}) Object Bool() bool String() string Int() int Int64() int64 Uint64() uint64 Float() float64 Interface() interface{} Unsafe() uintptr }
Object is some stuff JS objects can do. This is essentially an extracted interface of *js.Object.
func WrapObject ¶
WrapObject returns a wrapper for *js.Object that conforms to Object.
type Terminal ¶
Terminal represents a Hterm Terminal.
func (Terminal) ClearHome ¶
func (t Terminal) ClearHome()
ClearHome clears the terminal and returns the cursor to 0,0.
func (Terminal) InstallKeyboard ¶
func (t Terminal) InstallKeyboard()
InstallKeyboard installs the hterm keyboard handler.
func (Terminal) OnTerminalReady ¶
func (t Terminal) OnTerminalReady(cb func())
OnTerminalReady registers a callback for when the terminal is ready.