Reputation: 15028
EDIT 3: I've gotten this working by ignoring the advice given below and listening on the window, but only when an input
, text
field, or textarea
is not focused. I'm not sure if this is the best way to be handling this issue, though.
EDIT 2: I've tried addressing the keydown
issue by applying focus
and blur
handlers to input
s. Then I only listen for events when var focus_on_input == true
. But it seems that not all is well. This is preventing some behaviors, but causing other, more bizarre behavior. For example, when I tab out of the input field, pressing J and K will jump to the top or bottom of the list. If I click
elsewhere and shift focus, this issue is fixed. Any thoughts?
EDIT: Thanks to answerer help, I've limited the selectors when listening for keydown
so that I can still type characters elsewhere, but I'm running into a new issue. When I press J or K the arrow nav jumps to the top or bottom of the task list. And when I press C or # it will notify me that no tasks are selected. X functions as it should and does not select a task.
Hosting this code on JSFiddle since there's no possible way to comment on it in its entirety here. I've posted all my JS, CSS, and HTML used for the interface itself.
I'm designing a Gmail-inspired UI for task management using jQuery on the front-end (and PHP on the back-end, though it's largely irrelevant to this).
I'm still relatively new to jQuery development and so I realize I'm doing a number of things wrong. Until now, I simply haven't known what exactly I'm doing wrong nor how to fix it. I was hoping some more learned souls might help me (and others, hopefully) figure out how to refactor jQuery code for a larger-sized application.
To start, here are a number of things I would like to know how to do better:
Call this code only when the task interface is active.
Improve the listening for the keydown
event. Currently I listen for J, K, X, Shift+3, and C. I will also be listening on E for task editing, but haven't yet implemented edits. 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 a <textarea>
, for example, will not result in the default behavior.
Use less HTML in my code.
Make my code generally more DRY.
Any thoughts, no matter how critical, are more than welcome. Again, I realize I am not following best practices here, but that's because I'm dumb to them. I want to learn, and hope to use this opportunity to do so.
Cheers!
Upvotes: 6
Views: 2163
Reputation: 5089
I came across this project last night and I was completely inspired! I decided to work on it through the night and today and refactored the code to be a bit more modular and accept any kind of data.
The notion of a task has been removed, as well as anything that was originally attributed to a task. I did this for plans to make it work for any kind of data and allow for further displaying of data and editing of data through other means. This interface is also closer to the more up to date Gmail interface, as far as I could tell.
Noted feature changes:
http://jsfiddle.net/epic720/BfJYV/7/
http://jsfiddle.net/epic720/BfJYV/7/embedded/result/ (Fullscreen, no code)
Would love any and all feedback on this, I plan to continue my work here and make it a full featured data editing UI.
Upvotes: 0
Reputation: 86443
I like your idea! I made a few changes in your code to make it more streamline (updated demo):
keydown
from $(this)
to $(document)
(ref).container = $('#task-list-container')
).yellowTaskMessage
function to add alerts.yellow-task-message
div to the HTML.display:none
to .yellow-task-message
in the CSS.next_task
as it is already a jQuery object).Upvotes: 2
Reputation: 26380
I'll be the first to admit that I have not learned how to do this yet (and I really should), but drag and drop would be a nice option to rearrange the tasks in the list. The look is very nice by the way. I'm using IE8 and I can't seem to use the keyboard shortcuts, unfortunately - but it seems like JSFiddle won't let me shift the focus to the result pane, so that may not be your code that's not behaving for IE8.
Upvotes: 0
Reputation: 17319
.keydown
doesn't need to be assigned to $(window)
it takes a selector such as $(':not(textarea)')
Upvotes: 1