Code Monkey home page Code Monkey logo

ember-keyboard-shortcuts's Introduction

ember-keyboard-shortcuts

Installation

In your ember-cli project:

ember install ember-keyboard-shortcuts

Usage

In a route

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
      }
    }
  }
);

In a component

import Ember from 'ember';
import KeyboardShortcuts from 'ember-keyboard-shortcuts/mixins/component';

export default Ember.Component.extend(
  KeyboardShortcuts,

  {
    keyboardShortcuts: {
      'esc'    : 'cancel',
      'ctrl+s' : 'save'
    }
  }
);

In a view

import Ember from 'ember';
import KeyboardShortcuts from 'ember-keyboard-shortcuts/mixins/view';

export default Ember.View.extend(
  KeyboardShortcuts,

  {
    keyboardShortcuts: {
      'esc'    : 'cancel',
      'ctrl+s' : 'save'
    }
  }
);

Available shortcut options

  • action: action to trigger. Can be a function or a string containing action name.
  • global: indicates whether events should be triggered within input, textarea and select. Default: true.
  • scoped: indicates that the shortcuts should only be registered for the current component/view and its children. Implies global: true. Default: false.
  • preventDefault: prevents the default action and stops the event from bubbling up. Applies only when the action is a string. Default: false.

Development

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

ember-keyboard-shortcuts's People

Contributors

andremalan avatar dremora avatar ember-tomster avatar karanjthakkar avatar pgengler avatar solirvine avatar sukima avatar trym avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.