Skip to content

Instantly share code, notes, and snippets.

@rodolfo42
Created October 22, 2013 11:33
Show Gist options
  • Save rodolfo42/7099070 to your computer and use it in GitHub Desktop.
Save rodolfo42/7099070 to your computer and use it in GitHub Desktop.
suporte a onEnter e onShiftEnter para inputs
$.fn.onEnter = function(callback, selector, data, onlyIfShiftKeyPressed){
if($.isFunction(callback)) {
$(this).on('keydown.onEnter', selector, data, function(e) {
if(e.which != 13) return true;
if(onlyIfShiftKeyPressed && !e.shiftKey) return true;
e.preventDefault();
callback.apply(this, [e]);
});
}
return this;
};
$.fn.onShiftEnter = function(callback, selector, data){
$(this).onEnter(callback, selector, data, true);
return this;
};
@rodolfo42
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment