EDIT 3:. I got this working by ignoring the advice below and listening to it, but only if the input , text or textarea field is not focused. I am not sure if this is the best way to deal with this problem.
http://jsfiddle.net/gXPES/5/
EDIT 2: I tried to solve the keydown problem by applying focus and blur handlers to input s. Then I listen only for events when var focus_on_input == true . But, it seems, not all is well. This prevents some behaviors, but causes other, weirder behaviors. For example, when I tab leaves the input field, pressing J and K will move up or down the list. If I click elsewhere and focus shift, this problem is fixed. Any thoughts?
EDIT:. Thanks to the help of the administrator, I restricted selectors when listening to keydown so that I could still print characters elsewhere, but I am having a new problem. When I press J or K , the nav arrow jumps to the top or bottom of the task list. And when I press C or # , it will notify me that no tasks have been selected. X functions as it should and does not select a task.
Hosting this code in JSFiddle , since there is no possible way to comment it in its entirety. I published all my JS, CSS and HTML used for the interface itself.
I am developing a Gmail-oriented user interface for task management using jQuery on the interface (and PHP on the internal interface, although this is largely unrelated to this).
I'm still relatively new to jQuery development, and so I understand that I'm doing the wrong amount . Until now, I just did not know what exactly I was doing wrong, and how to fix it . I was hoping some more learned souls could help me (and others, hopefully) figure out how to refactor jQuery code for a larger application.
To get started, here are a few things I would like to know how to do better:
Call this code only when the task interface is active.
Improve your listening for the keydown event. I am currently listening to J , K , X , Shift + 3 and C. I will also listen to E for editing the task, but have not yet implemented the changes. The problem with the listeners is related to my first concern, which is that they are always on . This means that pressing J , while in <textarea> , for example, will not result in default behavior.
Use less HTML code in my code.
Make my code drier.
Any thoughts, however important, are more than welcome. Again, I understand that I am not following the best practices here, but that is because I am dumb to them. I want to learn and hope to use this opportunity to do this.
Hooray!