Lately I’ve run into a brick wall. While working on the new version of Impromptu, I’ve had many requests to restrict the tab out of the prompt. Problem is how do you determine which element has focus without some ugly hacks like adding a class name to the element on its focus event, then removing it on blur.
The ideal solution would have jquery selector for :focus which would return the focused element, so then I would do something like so:
if($('.jqi :focus').length == 0){
$('.jqi').focus();
}
The problem is this selector isn’t implemented, or is it(are there any plugins out there)? Is it possible to retrieve such? Well of course everything is possible, but may not be pretty! So, does anyone have any suggestions?
Related posts:


2 Responses
Zev Spitz
16|Jun|20081) IE has a document.activElement property, but that isn’t cross-browser.
Although, perhaps the following is a better solution: trap the blur events for the first (if shift is pressed) and last (if shift is not pressed) inputs in the prompt, and returning the focus to the first and last elements respectively.
2) If we’re talking about the new version, I have modified impromptu to allow a callback when removing the prompt with the escape key:
Add the following member to the ImproptuDefaults object (line 22):
escape:function() {}
Change line 82 as follows:
if (kC == Esc) {removePrompt();o.escape();}
3) As I mentioned in a comment to a previous blog, the focus option doesn’t do anything under IE. Apparently, the focus can only be set after the buttons are visible.
I’ve worked around this by setting the focus in the load function.
trent
16|Jun|2008Thanks for the code Zev. I will definitely look at integrating 3 into the next version.
#2 doesn’t need an option, just simply pass true into that function removePrompt() should work: removePrompt(true,’escape’,jqi); should work. Now you can use the regular callback. I may look at changing it to this as it seems more appropriate.
As for #1 I will look into getting that to work,.. looks like it will be fun :) Thanks for the code and suggestion!