This repository has been archived by the owner on Nov 8, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
}); | ||
|
||
}); |