Documentation ¶
Index ¶
- Variables
- func Bind(keys string, run func())
- func BindEvent(keys string, run func(), on string)
- func BindMulti(keys []string, run func())
- func BindMultiEvent(keys []string, run func(), on string)
- func Pause()
- func Record(callback func(sequence []string))
- func Reset()
- func StopCallback(event, element, combo interface{})
- func Trigger(keys string)
- func TriggerType(keys, typ string)
- func Unbind(keys string)
- func Unpause()
- type Mousetrap
- func (mt Mousetrap) Bind(keys string, run func())
- func (mt Mousetrap) BindEvent(keys string, run func(), on string)
- func (mt Mousetrap) BindMulti(keys []string, run func())
- func (mt Mousetrap) BindMultiEvent(keys []string, run func(), on string)
- func (mt Mousetrap) Reset()
- func (mt Mousetrap) StopCallback(event, element, combo interface{})
- func (mt Mousetrap) Trigger(keys string)
- func (mt Mousetrap) TriggerType(keys, typ string)
- func (mt Mousetrap) Unbind(keys string)
Constants ¶
This section is empty.
Variables ¶
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 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 ¶
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 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 ¶
Mousetrap is a wrapper for Mousetrap objects
func NewFromQuerySel ¶
NewFromQuerySel calls document.querySelector with the given search string and calls New() with the result.
func (Mousetrap) BindMulti ¶
BindMulti binds all the keys or sequences in the given array to run the given function.
func (Mousetrap) BindMultiEvent ¶
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) TriggerType ¶
TriggerType triggers a keyboard event of the given type within Mousetrap.