Yes, it is now staying focused on spacebar clicks, but now stays focused on mouse clicks too, which doesn't mimic the native browser behavior. The challenge is that while Firefox, Chrome, and Safari give a clear indication of where the click came from (e.clientX and e.clientY values), IE and Opera do not. That's why I was fooling around with all of the events, and the reason why I started this thread.
While on break, I worked on a plugin for my code. While it's not as clean and awesome as yours, it's working exactly the way I want it to.
Example checkbox HTML:
Code:
<label class="checkbox"><input type="checkbox" name="checkbox1" value="checkbox 1" /> <span>Regular Checkbox</span></label>
New plugin on Gist Github:
https://gist.github.com/3492800
I don't have a working example online for you to checkout, but I've tested in the latest versions of Chrome, Firefox, Safari, IE, and Opera. Also tested on my Android phone, iPad, and old FF3 on Ubuntu. The only problem out of all of these tests has been that Safari on Mac doesn't get focus. It's not that it doesn't display focus, it's just not getting it at all.
I'm not sure that I should care so much about the display of focus, but I just wanted things to be the same as the browser's default functionality. I think your solution would be overall safer, while mine is fully working but has potential to be really buggy because it analyzes the event order, which has proven to be inconsistent. So, in more than one way, you've done a good job, and I'll probably go with your code.
Bookmarks