Skip to content

Commit

Permalink
Add params as to function
Browse files Browse the repository at this point in the history
Fix issue #6 adding params as array.

Needs to pass as array while the function must be the first parameter.

Usage:

```html

<div w-mousetrap="{ a: [someFunc, scopeVariable, 'string variable'] }">
```

```javascript

$scope.someFunc = function(event, params) {
    event.preventDefault();
    console.log("Super cool", params);
};
```
  • Loading branch information
leocaseiro authored and leocaseiro committed Nov 30, 2015
1 parent ab9e0f1 commit 398e1c6
Showing 1 changed file with 10 additions and 4 deletions.
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.1.0 - 2015-11-30
* @link https://github.com/mgonto/mgo-mousetrap
* @author Martin Gontovnikas <[email protected]>
* @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

0 comments on commit 398e1c6

Please sign in to comment.