OscarGodson / jKey

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

selector for '*:not(:input)' bug ? #25

Closed twoer closed 10 years ago

twoer commented 10 years ago

$('*:not(:input)').jkey('b', function(key, e) { debugger; })

In the input type 'b', will also perform?

OscarGodson commented 10 years ago

I'm taking a look real quick, but we don't really do anything with the selectors. jQuery is handling that. Also, the code hasn't been touched in a year and I'm amazed it still works at all with jQuery still ;)

OscarGodson commented 10 years ago

After playing with it, I can see it's being called multiple times. You're doing * which means everything. So, when you do b you're triggering it on everything including body, html, etc. Even if you're focused on the input you're still focused on the body and html so you'll trigger the input.

http://jsbin.com/OgAnEGEM/1/edit

What are you trying to do exactly? How about just setting up a key shortcut on the body and then disabling it when you focus on any input?

twoer commented 10 years ago

I want to do is to bind a shortcut key, when the input does not perform, other times, my way is to increase the parameters of an event, then the callback: inside the

$(document).jkey('t', true, function(key, e)
{
    if(e && !$(e.target).is(':input'))
    {
        //exec my code
    }
});
OscarGodson commented 10 years ago

So, does what you have fix it? If so I'll close the ticket.

P.S. when pasting code put ` (x3) above and below so it's formatted nicely :) Click edit on your message to see what I did.

twoer commented 10 years ago

Actually I want to, you add a parameter, or using other methods to identify whether you need this shortcut in input element, what do you think?

OscarGodson commented 10 years ago

Sorry, I'm not sure what you're asking in that last message. If you're asking if the code you have above is a good idea for detecting if you want to execute your shortcuts or not, I think it is. You could remove that e && and just do the !$(e.target)... part since e will always be there now that you added it in the PR (also, did you get my note in the other PR?)

twoer commented 10 years ago

By increasing the event argument, and then judge e. arget can really achieve what I think, but still have some trouble, I want to add new parameters, such as:

https://github.com/vincentdieltiens/jQuery-keyboard-Shortcut

"Except_in (optional) :" the an string with the selectors of the tags for which the shortcut are not active.

I am a Chinese, English is poor, sorry!

OscarGodson commented 10 years ago

I like the idea for sure. I don't really maintain this repo anymore, but if you want to send a PR I'll be happy to test it and everything!

twoer commented 10 years ago

Ok, I'll take time to deal with, thank you for your support!