• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Handling keyboard interaction on an Angular app: An Angular Mousetrap wrapper

mgo-mousetrap

This is a library that lets you handle keyboard interaction on an Angular app. It's an Angular Mousetrap wrapper for the awesome MouseTrap library which takes care of binding key strokes to some function.

Usage

Add mgo-mousetrap scripts and module

First of all, you need to include both mousetrap.js and wMousetrap.js in your index.html file. mousetrap.js is copied from its repository, with its corresponding Apache 2 license.

Then, you need to add mgo-mousetrap module as a dependency of your app as follows:

angular.module('myCoolApp', ['mgo-mousetrap']);

Just use it

Now you're prepared to use it. For that, you can add this directive to any field and state which keys and actions will happen. For example, let's look at the following pager:

<div class="pager" w-mousetrap="{left: previousPage, right: nextPage}">
  <li ng-click="previousPage()">Previous</li>
  <li ng-repeat="page in pages" ng-click="goTopage(page)">{{page}}</li>
  <li ng-click="nextPage()">Next</li>
</div>

Check the pager div, we're setting an object where its keys are the keyboard shortcut to press and the value are the functions to execute once those keys have been clicked.

Let's check a more complex example:

<input type="button" value="Make super cool action" ng-click="superCoolAction()" w-mousetrap="{'command+shift+k': superCoolAction}" />

In here, when the user clicks command + shift + k, then the super cool action is going to be run. Please notice the '' that wraps the key. This are needed if the key contains some "not normal" character like +, *, etc.

In every w-mousetrap attribute you can define ANY number of key shortcuts :).

You can also receive the event that's called with mousetrap to call preventDefault or stopPropagation. For example, superCoolAction might look like:

$scope.superCoolAction = function(event) {
    event.preventDefault();
    alert("Super cool");
}

Hope you guys like this!!!

Bitdeli Badge

More Repositories

1

restangular

AngularJS service to handle Rest API Restful Resources properly and easily
JavaScript
7,870
star
2

angularytics

The solution to tracking page views and events in a SPA with AngularJS
JavaScript
632
star
3

factory_pal

A Scala framework for creating objects as test data. Say no to Mocks
Scala
98
star
4

mgo-ui-router-goto

A directive for ui-router that lets you link to states instead of URLs
JavaScript
52
star
5

meaner-seed

A better organised, more complete and updated MEAN seed
JavaScript
50
star
6

gulp-browserify-library-seed

This is a seed (kickstarter) project to create your own library which will use Browserify and Gulp
JavaScript
35
star
7

slick-play2-example

slick-play2-example
Scala
27
star
8

angular-ux

A library that helps you create live, navigable prototypes with the help of AngularJS but without having to learn how to code ;). DESIGNERS, I'm looking at you!
JavaScript
22
star
9

jpa-passive-logging-example

A JPA changes (Create, Modify and Delete) model logger that does this passively.
Java
16
star
10

heroku-static-file-server

Serve static files in Heroku
16
star
11

front-is-the-new-back

The front is the new back talk: Introducing Webtasks
CSS
11
star
12

angular-101-from-n00b-to-ngExpert

AngularJS Training with excercises
JavaScript
9
star
13

angular-security-workshop

Security workshop with Angular
JavaScript
8
star
14

restangular-talk

Restangular talk
HTML
8
star
15

a-token-walks-into-a-SPA

A token enters into a SPA: Angular 2 Authentication talk
CSS
6
star
16

sublime-config

sublime-config
Python
6
star
17

reactive-frontend-oscon

Reactive Frontend Oscon Slides
JavaScript
6
star
18

angello-angularjs-in-action

NodeJS Express app for Angello sample in AngularJS in Action
JavaScript
5
star
19

instagram-user-hash-searcher

Searcher for pictures for a particular user that contain a particular hashtag
JavaScript
4
star
20

specs

Specifications for building stuff
4
star
21

restangular-plugins

Plugins for Restangular to make your life easier.
4
star
22

reactive-all-the-things-talk

Reactive All The Things talk in ngConf
JavaScript
4
star
23

how-to-create-good-documentation-talk

"Stop wasting developers time! How to create good documentation?" TaΓ±l
CSS
4
star
24

angular2-the-new-horizon

Intro talk to Angular 2
CSS
3
star
25

angularjs-good-practices

AngularJS Good Practices
JavaScript
3
star
26

play-framework-2-video-course

Play Framework Video Course for Packt Publishing
CSS
3
star
27

talk-starter

A starter project for any future talks :)
CSS
3
star
28

gon.to-old

The blog & website for gon.to
JavaScript
2
star
29

tournament

Torneo
Ruby
2
star
30

are-your-SPAs-safe-talk

Talk about security on Single Page Apps
HTML
2
star
31

restangular-talk-with-image-right

Restangular talk with rights for images
JavaScript
2
star
32

a-token-walks-into-a-spa-rosario

A token walks into a SPA Rosario
CSS
2
star
33

death-to-cookies-cascadia

Death to cookies: Long live JSON Web Tokens talk at Cascadia
CSS
2
star
34

teammates

iOS App for Soccer playing
Swift
1
star
35

auth0-python-flaskapi-sample

Auth0 + Python + Flas API Seed
Python
1
star
36

reactive-frontend-talk

Learn what Reactive Programming is and how to use it on Frontend apps
JavaScript
1
star
37

a-comerla

A Comerla
1
star
38

tessel-lock

Tessel Lock
JavaScript
1
star
39

mgonto.github.com

Github pages for mgonto
1
star
40

learning-html

Learning HTML with @tyny
JavaScript
1
star
41

prototyping-with-angularjs

Example of Prototyping with AngularJS
HTML
1
star
42

angularjs-todo-frontend-talk

TODO app made with AngularJS for the FrontEnd quick intro (40 min) talk
JavaScript
1
star
43

videolibrary

A library for your videos
Scala
1
star