web

package
v0.0.0-...-cc35b79 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

This package provides wrappers to make it easier to work with web APIs. The core is in js.go, which makes it easy to embed javascript in your Go code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alert

func Alert(msg string)

func Body

func Body() js.Value

func CreateElement

func CreateElement(tag string) js.Value

func CreateInputElement

func CreateInputElement(accept []string, ch chan<- []byte) js.Value

Create an input element for single file upload which will push a slice of bytes into the provided channel.

func CreateParamInput

func CreateParamInput(
	ctx context.Context,
	label string,
	backing interface{},
	shortDesc string,
	longDesc string,
	changeCh chan struct{},
	attrs map[string]string,
) js.Value

Create labeled form elements with short and long descriptions

backing must be a pointer to a value that will be set by the form

func CreateSVGElement

func CreateSVGElement(tag string) js.Value

func Document

func Document() js.Value

func Global

func Global(key string) js.Value

func JsExec

func JsExec(code string, args ...interface{}) js.Value

Call an immediate function and don't cache it

func MakeDownloadLink(data []byte, filename string, mime string) js.Value

func MakeFunction

func MakeFunction(code string, nocache ...bool) js.Value

Create a function from a javascript string. The function will be cached unless you pass `true` for nocache. Caching allows the browser to optimize frequently called functions, but every cached function stays in memory forever, so it is not appropriate for iifes.

Types

type Page

type Page struct {
	Html    string
	Element js.Value
}

func NewPage

func NewPage(html string) *Page

func (*Page) Find

func (p *Page) Find(selector string) js.Value

func (*Page) Init

func (p *Page) Init()

Re-init the page's element. If you do this while the element is on the page, its behavior is undefined.

func (*Page) Replace

func (p *Page) Replace(className string, element interface{})

Replace a placeholder element (by class name) with a new element. If element is a string instead of an element, a span element will be created instead.

func (*Page) Show

func (p *Page) Show()

Replace whatever is on the screen with the page's element

Jump to

Keyboard shortcuts

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