mousetrap

package module
v0.0.0-...-221b8a1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2016 License: MIT Imports: 1 Imported by: 2

README

gopher-mousetrap

Mousetrap bindings for GopherJS.

The documentation is partly from the Mousetrap API reference

Use go get -u maunium.net/go/gopher-mousetrap to get this package.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMousetrap = Mousetrap{js.Global.Get("Mousetrap")}

DefaultMousetrap is the default Mousetrap object

Functions

func Bind

func Bind(keys string, run func())

Bind binds a key or a sequence of keys to run the given function.

func BindEvent

func BindEvent(keys string, run func(), on string)

BindEvent binds a key or a sequence of keys to run the given function.

func BindMulti

func BindMulti(keys []string, run func())

BindMulti binds all the keys or sequences in the given array to run the given function.

func BindMultiEvent

func BindMultiEvent(keys []string, run func(), on string)

BindMultiEvent binds all the keys or sequences in the given array to run the given function.

func Pause

func Pause()

Pause stops Mousetrap events from firing.

N.B. Requires the Pause/unpause extension! You can get it from https://github.com/ccampbell/mousetrap/tree/master/plugins/pause

func Record

func Record(callback func(sequence []string))

Record records keyboard shortcuts from your application. For example if you wanted to let users specify their own keyboard shortcuts for performing actions on your page you could ask them to enter a shortcut.

N.B. Requires the Record extension! You can get it from https://github.com/ccampbell/mousetrap/tree/master/plugins/record

func Reset

func Reset()

Reset removes anything you have bound to mousetrap. This can be useful if you want to change contexts in your application without refreshing the page in your browser. You can ajax in a new page, call reset, and then bind the key events needed for that page.

Internally mousetrap keeps an associative array of all the events to listen for so reset does not actually remove or add event listeners on the document. It just sets the array to be empty.

func StopCallback

func StopCallback(event, element, combo interface{})

StopCallback is a method that is called to see if the keyboard event should fire based on if you are inside a form input field.

If true is returned then it stops the callback from firing, if false it fires it.

The default implementation is:

	   stopCallback: function(e, element, combo) {
        // if the element has the class "mousetrap" then no need to stop
        if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
            return false;
        }

        // stop for input, select, and textarea
        return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || (element.contentEditable && element.contentEditable == 'true');
   }

func Trigger

func Trigger(keys string)

Trigger triggers a keyboard event within Mousetrap.

func TriggerType

func TriggerType(keys, typ string)

TriggerType triggers a keyboard event of the given type within Mousetrap.

func Unbind

func Unbind(keys string)

Unbind unbinds a single keyboard event or an array of keyboard events. You should pass in the key combination exactly as it was passed in originally to bind.

func Unpause

func Unpause()

Unpause allows Mousetrap events to fire again.

N.B. Requires the Pause/unpause extension! You can get it from https://github.com/ccampbell/mousetrap/tree/master/plugins/pause

Types

type Mousetrap

type Mousetrap struct {
	*js.Object
}

Mousetrap is a wrapper for Mousetrap objects

func New

func New(obj interface{}) Mousetrap

New creates a new Mousetrap object

func NewFromQuerySel

func NewFromQuerySel(search string) Mousetrap

NewFromQuerySel calls document.querySelector with the given search string and calls New() with the result.

func (Mousetrap) Bind

func (mt Mousetrap) Bind(keys string, run func())

Bind binds a key or a sequence of keys to run the given function.

func (Mousetrap) BindEvent

func (mt Mousetrap) BindEvent(keys string, run func(), on string)

BindEvent binds a key or a sequence of keys to run the given function.

func (Mousetrap) BindMulti

func (mt Mousetrap) BindMulti(keys []string, run func())

BindMulti binds all the keys or sequences in the given array to run the given function.

func (Mousetrap) BindMultiEvent

func (mt Mousetrap) BindMultiEvent(keys []string, run func(), on string)

BindMultiEvent binds all the keys or sequences in the given array to run the given function.

func (Mousetrap) Reset

func (mt Mousetrap) Reset()

Reset removes anything you have bound to mousetrap. This can be useful if you want to change contexts in your application without refreshing the page in your browser. You can ajax in a new page, call reset, and then bind the key events needed for that page.

Internally mousetrap keeps an associative array of all the events to listen for so reset does not actually remove or add event listeners on the document. It just sets the array to be empty.

func (Mousetrap) StopCallback

func (mt Mousetrap) StopCallback(event, element, combo interface{})

StopCallback is a method that is called to see if the keyboard event should fire based on if you are inside a form input field.

If true is returned then it stops the callback from firing, if false it fires it.

The default implementation is:

	   stopCallback: function(e, element, combo) {
        // if the element has the class "mousetrap" then no need to stop
        if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
            return false;
        }

        // stop for input, select, and textarea
        return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || (element.contentEditable && element.contentEditable == 'true');
   }

func (Mousetrap) Trigger

func (mt Mousetrap) Trigger(keys string)

Trigger triggers a keyboard event within Mousetrap.

func (Mousetrap) TriggerType

func (mt Mousetrap) TriggerType(keys, typ string)

TriggerType triggers a keyboard event of the given type within Mousetrap.

func (Mousetrap) Unbind

func (mt Mousetrap) Unbind(keys string)

Unbind unbinds a single keyboard event or an array of keyboard events. You should pass in the key combination exactly as it was passed in originally to bind.

Jump to

Keyboard shortcuts

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