In your ember-cli project:
ember install ember-keyboard-shortcuts
import KeyboardShortcuts from 'ember-keyboard-shortcuts/mixins/route';
export default Ember.Route.extend(
KeyboardShortcuts,
{
actions: {
cancel: function() {
this.transitionTo('posts');
}
},
keyboardShortcuts: {
// trigger 'cancel' action when esc is pressed
'esc' : 'cancel',
'ctrl+c' : {
action : 'cancel', // action to trigger
global : false, // whether to trigger inside input (default: true)
preventDefault : true // (default: true)
}
// trigger function when tab is pressed
tab : function() {
console.log('Tab pressed');
return false; // preventDefault
}
}
}
);
import Ember from 'ember';
import KeyboardShortcuts from 'ember-keyboard-shortcuts/mixins/component';
export default Ember.Component.extend(
KeyboardShortcuts,
{
keyboardShortcuts: {
'esc' : 'cancel',
'ctrl+s' : 'save'
}
}
);
import Ember from 'ember';
import KeyboardShortcuts from 'ember-keyboard-shortcuts/mixins/view';
export default Ember.View.extend(
KeyboardShortcuts,
{
keyboardShortcuts: {
'esc' : 'cancel',
'ctrl+s' : 'save'
}
}
);
action
: action to trigger. Can be a function or a string containing action name.global
: indicates whether events should be triggered withininput
,textarea
andselect
. Default:true
.scoped
: indicates that the shortcuts should only be registered for the current component/view and its children. Impliesglobal: true
. Default:false
.preventDefault
: prevents the default action and stops the event from bubbling up. Applies only when theaction
is a string. Default:false
.
git clone
this repositorynpm install
bower install
ember server
- Visit your app at http://localhost:4200.
ember test
ember test --server
ember build
For more information on using ember-cli, visit http://www.ember-cli.com/.