0

How do I know which element has the focus, or how to determine whether the focus of a particular element?

  • do you need to catch the focus or the hover event will be good too? [http://shoesrb.com/manual/Events.html](http://shoesrb.com/manual/Events.html) – Vasiliy Ermolovich Apr 08 '11 at 13:24

2 Answers2

0

I don't know of anyway to query for this kind of information directly. I suppose you could traverse the DOM and check for it manually. If that's the case you should look at this.

Perhaps what you are trying to do can be achieved by handling an event when specific elements of interest gain focus. Here is how you would do that in jQuery.

$('<selector>').focus(function() {
  // Do something here
});

Just for giggles, here is one way you could use the focus method to track which element recieved it last. I highly recommend against using this code.

var gotDaFocus;
$('*').focus(function() {
  gotDaFocus = this;
}); 
Community
  • 1
  • 1
Blake Taylor
  • 9,217
  • 5
  • 38
  • 41
  • I'm not asking about javascript, but about Ruby and Shoes. – exromany Apr 10 '11 at 06:43
  • Errr... Sorry :). You might want to update the question to state that. I just assumed JS because of the key words "element" and "focus". I didn't look at the tags. Good luck. – Blake Taylor Apr 13 '11 at 14:25
0

not yet implemented yet i'm afraid. You could do something like this

Shoes.app do
  @focused = para ""
  stack do
    @label1 = edit_line :text => 1
    click do
      @focused.replace @label1.text
    end
  end
  stack do
    @label2 = edit_line :text => 2
    click do
      @focused.replace @label2.text
    end
  end
end

But the problem in windows is that the controls steal all the event from Shoes. In Green Shoes it would work. If you'r in windows you can still see the result if you click just to the right of the edit_line. Of course, this is only when you click with the mouse, you should check keypress tot get the keyboard events also. Grtz

peter
  • 41,770
  • 5
  • 64
  • 108