Skip to content
This repository has been archived by the owner on Nov 8, 2017. It is now read-only.

Commit

Permalink
canjs bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed Aug 7, 2012
1 parent bb0b313 commit 57efae3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions jwerty.canBridge.js
@@ -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;
}
});

});

0 comments on commit 57efae3

Please sign in to comment.