Atto - functions on 'onClick', 'onFocus', etc. events on text

Atto - functions on 'onClick', 'onFocus', etc. events on text

by Ju L -
Number of replies: 1

Hi all,

I've searched for this for quite a long time, but I've not found how to do this.

I'm developing a plugin which inserts text into the textbox. But this text would be "metacharacters" for a filter, so I want them to behave differently.

Let's say we have the following on the textbox:

<span class="mytext">text inserted by the plugin</span> other text

For example, if I click anywhere inside that span, I would like to select the whole span.

In "plain" JavaScript, we would probably do:

<span class="mytext" onClick="myFunction()">text inserted by the plugin</span> other text

And then myFunction() would do whatever it is supposed to do to select that span.

But I don't know how to approach this for an Atto plugin.


Any help would be greatly appreciated.

Best regards,

Julen

Average of ratings: -
In reply to Ju L

Re: Atto - functions on 'onClick', 'onFocus', etc. events on text

by Ju L -

Okay, I've found the way (or at least one, if there are more), doing a massive search on Atto examples,  to listen to selection change event.

It's enough to add this snippet to the plugin (e.g. into initializer, which would be the most common place):

this.get('host').on('atto:selectionchanged', function() {
    // This will be fired every time the selection changes
}

I hope this is helpful if someone gets stuck in similar task smile


Best regards,

Julen


EDIT: I've realized that the event is also fired when clicking on toolbar buttons. So, it is not limited to textbox selection.