jswrap

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: MIT Imports: 3 Imported by: 0

README

jswrap

Some wrappers for js callers

Compatible with JS and WASM

Wrappers example

Console
c := jswrap.ConsoleGet()

// There is pure js calls of console object

c.Log("Some text")
c.Error("Error log")
c.Info("Info text")
c.Warn("Warn text")
Location
l := jswrap.LocationGet()

path := l.GetPathname() + l.GetSearch() + l.GetHash()
println(path)

println(l.GetFullDomainPath())

l.Reload()     // just reload
l.Reload(true) // force reload without cache
History
// Change URL and adds it to history

h := jswrap.HistoryGet()
h.PushState(nil, "", "/someurl")

// OR

h.PushURL("/someurl")

// ReplaceURL without history
h.ReplaceURL("/someurl-replace")
jswrap.CookieSet("name", "value", "")                               // without path and expires
jswrap.CookieSet("name", "value", "/", time.Now().AddDate(0, 1, 0)) // with path and expires in next month

value, ok := jswrap.CookieGet("name")
jswrap.ConsoleGet().Log(value, ok)

jswrap.CookieDelete("name")
Alert
jswrap.Alert("Just alert")

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alert

func Alert(s string)

Alert calls alert in JS

func CookieDelete

func CookieDelete(name string)

CookieDelete deletes a cookie specified by name

func CookieGet

func CookieGet(name string) (value string, ok bool)

CookieGet returns a given cookie by name. If the cookie is not set then ok will be set to false

func CookieSet

func CookieSet(name, value, path string, expires ...time.Time)

CookieSet adds a cookie to a user's browser with a name, value, expiry and path value, path and expires can be omitted

Examples: Without path and expires: CookieSet("name", "value", "")

or with path and expires to next month: CookieSet("name", "value", "/", time.Now().AddDate(0, 1, 0))

func CookieSetString

func CookieSetString(cookie string)

CookieSetString sets a cookie given a correctly formatted cookie string i.e "username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/"

func IsCookieEnabled

func IsCookieEnabled() bool

IsCookieEnabled returns false if setting a cookie will be ignored and true otherwise.

Types

type Console

type Console struct {
	Value js.Value
}

Console object

func ConsoleGet

func ConsoleGet() *Console

ConsoleGet returns console

func (*Console) Error

func (c *Console) Error(args ...interface{})

Error outputs an error message to the Web Console.

func (*Console) Info

func (c *Console) Info(args ...interface{})

Info outputs an informational message to the Web Console.

func (*Console) Log

func (c *Console) Log(args ...interface{})

Log outputs a message to the Web Console.

func (*Console) Warn

func (c *Console) Warn(args ...interface{})

Warn outputs a warning message to the Web Console.

type History added in v1.0.1

type History struct {
	Value js.Value
}

History object

func HistoryGet added in v1.0.1

func HistoryGet() *History

HistoryGet returns js history object

func (*History) Back added in v1.0.1

func (h *History) Back()

Back moves to backward through history. This acts exactly as if the user clicked on the Back button in their browser toolbar.

func (*History) Forward added in v1.0.1

func (h *History) Forward()

Forward moves forward as if the user clicked the Forward button.

func (*History) Go added in v1.0.1

func (h *History) Go(delta int)

Go method loads a specific page from the session history. You can use it to move forwards and backwards through the history. -1 equivalent of calling Back()

1 just like calling Forward()

-2 or 2 backwards by two pages or forward two pages

0 will reload the current page

func (*History) PushState added in v1.0.1

func (h *History) PushState(state interface{}, title, url string)

PushState adds a state to the browser's session history stack. state - JavaScript object which is associated with the new history entry. title - most browsers currently ignores this parameter, although they may use it in the future. url - The new history entry's URL is given by this parameter. Note that the browser won't attempt to load this URL after a call to pushState(), but it might attempt to load the URL later, for instance after the user restarts the browser.

func (*History) PushURL added in v1.0.1

func (h *History) PushURL(url string)

PushURL is a wrap pushState just to set url and add it to history

func (*History) ReplaceState added in v1.0.1

func (h *History) ReplaceState(state interface{}, title, url string)

ReplaceState method modifies the current history entry, replacing it with the state, title, and URL passed in the method parameters. This method is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.

func (*History) ReplaceURL added in v1.0.1

func (h *History) ReplaceURL(url string)

ReplaceURL is a wrap replaceState just to set new URL without adding it to history

type Location

type Location struct {
	Value js.Value
}

Location object allows you to get any parts of the URL and set href fragments. If you want to set new URL use History object

func LocationGet

func LocationGet() *Location

LocationGet returns location object

func (*Location) GetFullDomainPath added in v1.0.1

func (l *Location) GetFullDomainPath() string

GetHostnameFullPath return full path with hostname and protocol

func (*Location) GetFullPath added in v1.0.1

func (l *Location) GetFullPath() string

GetFullPath is just wrap to get current full path without host like a 'path?query=param#fragment' in the root path will be '/'

func (*Location) GetHash

func (l *Location) GetHash() string

GetHash returns string containing a '#' followed by the fragment identifier of the URL.

func (*Location) GetHost

func (l *Location) GetHost() string

GetHost returns string containing the host, that is the hostname, a ':', and the port of the URL.

func (*Location) GetHostname

func (l *Location) GetHostname() string

GetHostname returns string containing the domain of the URL

func (*Location) GetHref

func (l *Location) GetHref() string

GetHref returns string containing the entire URL

func (*Location) GetOrigin

func (l *Location) GetOrigin() string

GetOrigin returns string containing the canonical form of the origin of the specific location.

func (*Location) GetPathname

func (l *Location) GetPathname() string

GetPathname returns string containing an initial '/' followed by the path of the URL.

func (*Location) GetPort

func (l *Location) GetPort() string

GetPort returns string containing the port number of the URL

func (*Location) GetProtocol

func (l *Location) GetProtocol() string

GetProtocol returns string containing the protocol scheme of the URL including the final ':', example 'http:' or 'https:'

func (*Location) GetSearch

func (l *Location) GetSearch() string

GetSearch returns string containing a '?' followed by the parameters or "querystring" of the URL.

func (*Location) Reload

func (l *Location) Reload(forcedReload ...bool)

Reload reloads the current resource, like the Refresh button. It has an optional Boolean parameter, which is false by default. If true, the page is always reloaded from the server, ignoring the browser cache.

func (*Location) SetHref

func (l *Location) SetHref(href string)

SetHref sets href and associated document navigates to the new page

Jump to

Keyboard shortcuts

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