Skip to content

khasinski/angular-mousetrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Angular Mousetrap directives

This is a very crude and probably buggy clone of Angular UI Keypress with Mousetrap under the hood.

Usage

JavaScript:

angular.module('myApp', ['mousetrap']);
...
// Note - it should support any kind of binding that mousetrap supports
$scope.test = {
  'a': function() { console.log('"a" key was pressed'); },
  'b': function() { console.log('"b" key was pressed'); }
}

HTML:

<span mousetrap-keypress="test">Press 'a' or 'b'</span>

Global bindings

Global bindings require Global Binding plugin.

Example usage of global bindings:

$scope.myKeybindings = {
  bindGlobal: {
    'ctrl+s': $scope.saveAction,
    'command+s': $scope.saveAction
  }
  'ctrl+b': $scope.backAction
};

Requirements

  • AngularJS v1.0.2+
  • Mousetrap v1.4.4+