Detecting gaining and losing focus

2,235 views
Skip to first unread message

Glenn Jones

unread,
Feb 1, 2011, 7:57:25 AM2/1/11
to Ajax.org Cloud9 Editor (Ace)
Hi,

We'd like to detect when the ACE editor loses or gains focus. We have
tried to bind to the blur event on the editor element like this:
$('#id_usercode').bind('blur', function() {console.log('blur on
element')});
and we have tried attaching to the blur on the editor object:
editor.addEventListener('blur', function(_)
{console.log('blur');} );

Neither of these gets the event.

Is there something we're missing about the way that events are handled
in the editor?

Thanks
Glenn

Harry P

unread,
Feb 2, 2011, 12:28:00 PM2/2/11
to Ajax.org Cloud9 Editor (Ace)
Oo, looks like that appeared last night - thanks from Glenn, and all
of us at Resolver :0)

--
Harry Percival
Developer
ha...@resolversystems.com
+44 (0) 20 3051 2751

Dirigible: a Python cloud spreadsheet
<http://projectdirigible.com/>

Fabian Jakobs

unread,
Feb 2, 2011, 1:17:47 PM2/2/11
to ace-d...@googlegroups.com
I have added this today after reading your mail but then forgot to get
beck to the mail and reply. Sorry about that.

You can do now

editor.on("focus", function() { ... });
editor.on("blur", function() { ... });

Best,
Fabian

> --
> You received this message because you are subscribed to the Google Groups "Ajax.org Cloud9 Editor (Ace)" group.
> To post to this group, send email to ace-d...@googlegroups.com.
> To unsubscribe from this group, send email to ace-discuss...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ace-discuss?hl=en.
>
>

Daniel Glazman

unread,
Feb 2, 2011, 3:41:18 PM2/2/11
to ace-d...@googlegroups.com
Le 02/02/11 19:17, Fabian Jakobs a �crit :

> You can do now
>
> editor.on("focus", function() { ... });
> editor.on("blur", function() { ... });


Why reinvent the wheel and decrease readability? If editor is
not a DOM node but a private object,

editor.addEventListener( aEventName, aCallback)

is better and more conformant to web authors' habits. It will also
allow custom events.

</Daniel>

Kevin Dangoor

unread,
Feb 2, 2011, 3:44:01 PM2/2/11
to ace-d...@googlegroups.com
On Wed, Feb 2, 2011 at 3:41 PM, Daniel Glazman <daniel....@gmail.com> wrote:
Le 02/02/11 19:17, Fabian Jakobs a écrit :


You can do now

editor.on("focus", function() { ... });
editor.on("blur", function() { ... });


Why reinvent the wheel and decrease readability? If editor is
not a DOM node but a private object,

 editor.addEventListener( aEventName, aCallback)

is better and more conformant to web authors' habits. It will also
allow custom events.


--
Kevin Dangoor

work: http://mozilla.com/
email: kdan...@mozilla.com
blog: http://www.BlueSkyOnMars.com

Fabian Jakobs

unread,
Feb 3, 2011, 2:58:05 AM2/3/11
to ace-d...@googlegroups.com
On Wed, Feb 2, 2011 at 9:41 PM, Daniel Glazman <daniel....@gmail.com> wrote:
> Le 02/02/11 19:17, Fabian Jakobs a écrit :

>
>> You can do now
>>
>> editor.on("focus", function() { ... });
>> editor.on("blur", function() { ... });
>
>
> Why reinvent the wheel and decrease readability? If editor is
> not a DOM node but a private object,
>
>  editor.addEventListener( aEventName, aCallback)

Actually both will work. I code a lot with node.js and there "on" is
used. I personally find this more readable but we can argue days about
personal naming tastes.

Fabian

> is better and more conformant to web authors' habits. It will also
> allow custom events.
>
> </Daniel>
>

Reply all
Reply to author
Forward
0 new messages