harvesthq/ember-shortcuts

Name: ember-shortcuts

Owner: Harvest

Description: Keyboard shortcuts for Ember applications

Forked from: satchmorun/ember-shortcuts

Created: 2018-01-16 11:43:05.0

Updated: 2018-01-16 11:43:07.0

Pushed: 2018-02-19 13:11:18.0

Homepage: null

Size: 18

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Ember Shortcuts

Inspiration

keymaster. This library could not exists without it, and is, in fact, an adaptation of it that integrates cleanly with Ember.

Installation

Get the code:

bower install ember-shortcuts

Include it on your page somewhere after ember.js.

Usage

In any route:

r.Route.extend({
ortcuts: {
'shift+a': 'someAction'


tions: {
someAction: function() {
  console.log('someAction');
}


Like actions, shortcuts get dispatch bottom-up through the currently active routes.

Unlike actions, the shortcut handling does not bubble. In the example above, if a child of that route defined a shift+a: 'otherAction' handler and was active when the shortcut was pressed, the action otherAction would get sent instead of someAction.

KeyDown/KeyUp

Passing in an object rather than a string enables listening for keydown and key up events separately.

In any route:

r.Route.extend({
ortcuts: {
'shift+a': { keyDown: 'triggeredOnKeyDown', keyUp: 'triggeredOnKeyUp' },


tions: {
triggeredOnKeyDown: function() {
  console.log('keyDown!');
},
triggeredOnKeyUp: function() {
  console.log('keyUp!');
},


Injection

Ember.Shortcuts, once includes, is available to you as an injected singleton on your controllers, components and routes as the shortcuts property.

this.shortcuts.disable this.shortcuts.enable

Call this to toggle whether or not the global keyboard shortcut handlers will fire.

Filters

Before any event is triggered this.shortcuts.filters is checked to determine if the event will fire.

By default, ember-shortcuts checks the event target isn't an input, select or text area.

Modify this.shortcuts.filters to add extra filters, for example:

tion modalIsNotOpen() {
turn !Ember.$('.modal').length;


tion targetIsNotInput(event) {
nst tagName = event.target.tagName;
turn (tagName !== 'INPUT') && (tagName !== 'SELECT') && (tagName !== 'TEXTAREA');


r.Shortcuts.reopen({
lters: [modalIsNotOpen, targetIsNotInput]


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.