Skip to content

Commit

Permalink
Backwards incomptabile change! Remove global jquery.hotkeys.inputBind…
Browse files Browse the repository at this point in the history
…ing setting in favour of per handler inputBinding. Set handler.inputBinding = true to have events fire on inputs.
  • Loading branch information
John Boxall committed May 3, 2010
1 parent 01ea0e2 commit 65e7a7b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
23 changes: 23 additions & 0 deletions examples/test-inputBinding.html
@@ -0,0 +1,23 @@
<html>
<head>
<script src="jquery-1.4.2.js"></script>
<script src="../jquery.hotkeys.js"></script>
</head>

<body>
<p>Try ctrl+s while focused in the input.</p>
<input type="text" />

<script>
function bindCtrlSInInput(){
alert("Ctrl+S");
return false;
}
bindCtrlSInInput.inputBinding = true;

$(document).ready(function(){
$(document).bind('keydown', 'ctrl+s', bindCtrlSInInput);
});

</script>
</body></html>
14 changes: 9 additions & 5 deletions jquery.hotkeys.js
Expand Up @@ -29,23 +29,27 @@
"`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&",
"8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<",
".": ">", "/": "?", "\\": "|"
},
}

inputBinding: false
};

function keyHandler( handleObj ) {
// Only care when a possible input has been specified
if ( typeof handleObj.data !== "string" ) {
return;
}

var origHandler = handleObj.handler,
keys = handleObj.data.toLowerCase().split(" ");


// Specify inputBinding expando property on the original handler function.
if ( typeof origHandler.inputBinding == "undefined" ) {
origHandler.inputBinding = false;
}

handleObj.handler = function( event ) {
// Don't fire in text-accepting inputs that we didn't directly bind to
if ( !jQuery.hotkeys.inputBinding && this !== event.target &&
if ( !origHandler.inputBinding && this !== event.target &&
(/textarea|select/i.test( event.target.nodeName ) || event.target.type === "text") ) {
return;
}
Expand Down

0 comments on commit 65e7a7b

Please sign in to comment.