Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ $scope.superCoolAction = function(event) {
}
````

Let's check an example with custom parameters (require v0.2.0 or higher):
````html
<input type="button" value="Make super cool action" ng-click="superCoolActionWithParams()" w-mousetrap="{'command+shift+p': [superCoolActionWithParams, scopeVariable, 'myCustomString'}" />
````

````js
$scope.scopeVariable = {a: 'A', b: 'B', c: [1,2,3,4]};

$scope.superCoolActionWithParams = function(event, params) {
event.preventDefault();
console.log("Super cool with params", params);
//returns [scopeVariable, 'myCustomString]
}
````


Hope you guys like this!!!


Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mgo-mousetrap",
"version": "0.1.2",
"version": "0.2.0",
"main": "./wMousetrap.js",
"description": "Handling keyboard interaction on an Angular app: An Angular Mousetrap wrapper",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mgo-mousetrap",
"description": "Handling keyboard interaction on an Angular app: An Angular Mousetrap wrapper",
"version": "0.1.2",
"version": "0.2.0",
"filename": "wMousetrap.js",
"main": "./wMousetrap.js",
"homepage": "https://github.com/mgonto/mgo-mousetrap",
Expand Down
14 changes: 10 additions & 4 deletions wMousetrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Mousetrap wrapper for AngularJS
* @version v0.0.1 - 2013-12-30
* @version v0.2.0 - 2015-11-30
* @link https://github.com/mgonto/mgo-mousetrap
* @author Martin Gontovnikas <martin@gon.to>
* @license MIT License, http://www.opensource.org/licenses/MIT
Expand All @@ -23,11 +23,17 @@ angular.module('mgo-mousetrap', []).directive('wMousetrap', function () {
}
}
}, true);

function applyWrapper(func) {

function applyWrapper(fnc) {
var func = fnc[0] || fnc,
params = [];
if (angular.isArray(fnc)) {
fnc.shift();
params = fnc;
}
return function(e) {
$scope.$apply(function() {
func(e);
func(e, params);
});
};
}
Expand Down