Sat 24 May 2008
As you may have read from an earlier post I have been searching for a nice solution to figuring out which element currently has focus. Reason being is that it would be nice to detect if any element within Impromptu has focus, if not focus Impromptu. This way it keeps users from accessing the underlying page. The attempt I made was pretty simple: Apply focus event to ad a class name to the element, and to remove it on blur. Then I just need to search for that class name within the group of elements. My solution was a jquery plugin which looks like:
(function($){
$.fn.focusfinder = function() {
this.each(function(i){
$(this).find('*').focus(function(){
$(this).removeClass('focusfinder').addClass('focusfinder');
}).blur(function(){
$(this).removeClass('focusfinder');
});
});
return this;
};
})(jQuery);
Ok, maybe that isn’t the most efficient solution, but its completely experimental. Anyway, to activate this puppy you would simply call this line to assign the events:
$('#my_el').focusfinder();
What I found was that different browsers fire focus and blur events differently, thus making my solution somewhat inaccurate. Firefox worked as expected, the others were a disappointment. Any ideas?

May 25th, 2008 at 3:51 am
Ever thought about adding focusin/focusout to the document as capturing listeners? Then you can query the focused element using the event’s target. OK, this does not work in all browsers in this combination. To get a really working solution is somewhat more complex. In qooxdoo 0.8 we have gone this way with a combination of multiple ways. One of them is the one I mentioned above. Another often seen option is to add a global listener (at the document) to the mousedown event and then lookup the hierarchy for any focusable elements (e.g. tabIndex != -1). Hope you get an idea.
May 25th, 2008 at 3:54 am
I forgot the demo:
http://demo.qooxdoo.org/devel/demobrowser/demo/event/Focus_1.html
Please press “F7″ when the demo is loaded to the the logging console.
May 25th, 2008 at 12:08 pm
Thanks very much Sebastian, this is just what I was looking for. I think I try to follow what you’re describing, trick will be just to implement it in jQuery(nothing against Qooxdoo.. This might be a chance to learn some qooxdoo!).