forked from keithamus/jwerty
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjwerty.canBridge.js
More file actions
35 lines (28 loc) · 784 Bytes
/
jwerty.canBridge.js
File metadata and controls
35 lines (28 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
steal('can/control/modifier', './jwerty.js' function(Control){
/**
* Add templated-event-binding with keydown specific bindings
* into CanJS(http://www.canjs.us) JavaScript framework.
*
* For example, the following would bind to keydown on "CTRL+P".
*
* can.Control({
* "keydown:(ctrl+p)":function(elm,ev){
* console.log("ctrl+p was pressed");
* }
* });
*
*/
// Hang on to original action
var originalShifter = can.Control._shifter;
// Redefine _isAction to handle new syntax
can.extend( can.Control, {
_shifter: function( context, name ) {
var fn = originalShifter.apply( this, arguments ),
parts = name.split(":");
if ( parts[1] && parts[0] === "keydown" ) {
fn = jwerty.event(parts[1].replace(/\(|\)/gi,''), fn);
}
return fn;
}
});
});