Firstly, do I understand that you mean attachEvent method? Secondly, do I understand correctly that you’d like to attach an event with this method to a button? What is the usage scenario in your case?
To your first, Sorry, I should have linked earlier to the added in 8.2 attachEditorEvent method.
To your second, I was hoping for a more general discussion, but attaching to a button could be instructive for other coders. So sure let’s say a button if you like.
Since the OP, my research, including looking at the source of a few plugins in the marketplace including zotero, and experimentation, leads me to believe attaching events are possible using vanilla modern javascript such as the following untested snippet:
My specific usage scenario, in a spreadsheet, goes something like: a plugin button click, calls a method that returns a cell’s fillcolor to the plugin for display to the plugin’s user.
attachEvent is used to subscribe to the event specified in the config.json of your plugin, whereas attachEditorEvent allows you subscribing to the event directly in the plugin code (without defining event in config.json). Second method was just introduced as you can see.
Your example demonstrates JS events, which are supported as the JS is main language for plugins, but they have nothing to do with attachable with two above mentioned methods plugins events.
As for the button event, you can use button that listens for a specific button to be clicked.
Hi @Constantine,
Thanks for distinguishing subscription ‘how’ differences between attachEvent and attachEditorEvent, but what benefits or limitations arise from using one over the other?
Sorry, but I remain unclear as to the ‘why’ in my original questions.
Because it provides an alternative approach that is much easier to utilize in terms of a JS code of the plugin, i.e. without need to specify events in any other files before or after declaring them in the main code.
These approaches does not affect the events themselves, they will work just as they do now, but it facilitates the plugin development in general.
To make this sample work I am specifying "isSystem": true in the config.json file of a plugin to make plugin start upon editor initialization.
Note: in the same config.json I am not specifying onDocumentContentReady event in the events array (as it is with regular approach with attachEvent method).
As a result, I can see that plugin works as it prompts “Logged” into the browser console once document is ready to be edited: