OscarGodson / jKey

Key shortcuts made simple
http://oscargodson.github.com/jKey/
185 stars 40 forks source link

Add support to allow event bubbling. #1

Closed techwraith closed 13 years ago

techwraith commented 13 years ago

If you bind the up/down keys to window, you lose page scroll capabilities, I think it would be a good idea to add support for event bubbling so the event still makes it up the chain.

You can do this by passing a "bubble" Boolean into the function.

e.g.

$(window).jkey("up", true, function(key){ //do stuff with the up key}

OscarGodson commented 13 years ago

Great idea. Ill work on this, or feel free to submit a pull request!

tanelpuhu commented 13 years ago

And maybe something similar to keep ability to enter text into form elements.

In sample.html : 'Type the letter "i" inside the box' : If you press 'a', 'w' or try to move to left or right nothing happens, except that what was excepted from demo ;)

OscarGodson commented 13 years ago

I'm going to try to implement this today. Hopefully I can push something today also :)

OscarGodson commented 13 years ago

@Tanelpuhu Could you explain your issue more? If you focus on an input, as per browser defaults, you wont be able to scroll left, right, up, down. You could implement your own scrolling though with a jkey event with up and down to scrollTop() in the callback.

For example: http://www.w3schools.com/TAGS/tag_input.asp Then focus on the search field and try to scroll.

A and W shouldnt do anything in the input field although I noticed a different issue where it does trigger events even tho it shouldnt when window has events binded and your focused on a child DOM element.

techwraith commented 13 years ago

I think @Tanelpuhu was saying that the hotkeys end up hijacking the input. So, if you wanted to type "This" in the input, but the "s" was bound to the window, you would only be able to type "Thi".

tanelpuhu commented 13 years ago

Yeah, just that. And I also tried to select text as i normally do, with Shift(+Ctrl)+Left/Right (Ctrl for per word).

Once-upon time I have also done something like this: .... $(document).bind('keypress',function(e){ target = e.target.type || 'other'; if(target != 'text' && target != 'submit'){ if(e.which==32){ playSong(); ....

OscarGodson commented 13 years ago

Awh, I see yes. I've just implemented the event bubbling boolean param which I've done some quick testing and it works. I'll throw it up in a bit. I haven't yet got the full bind/unbind working though so that you can "undo" a binding though. I'll put an example of the event bubbling param upon pushing as well.

OscarGodson commented 13 years ago

Closing this now. Bubbling now (should) work. Feel free to re-open if something is broken!