(Created page with '= Events = Starting in API v2, it is possible register functions as event handlers. To register an event handler, use: * '''addEventListener(String event, Function listener)'''...') |
Neverendingo (Talk | contribs) m (Text replace - "</code>" to "</syntaxhighlight>") |
||
| (One intermediate revision by one user not shown) | |||
| Line 34: | Line 34: | ||
Example: | Example: | ||
| − | < | + | <syntaxhighlight lang="javascript"> |
// anonymous function as a listener on KeyPress | // anonymous function as a listener on KeyPress | ||
plasmoid.addEventListener('KeyPress', function(a) { print(a.key) }) | plasmoid.addEventListener('KeyPress', function(a) { print(a.key) }) | ||
| Line 58: | Line 58: | ||
plasmoid.addEventListener('HoverEnter', output) | plasmoid.addEventListener('HoverEnter', output) | ||
plasmoid.addEventListener('HoverLeave', output) | plasmoid.addEventListener('HoverLeave', output) | ||
| − | </ | + | </syntaxhighlight> |
= HoverEvent (API v2) = | = HoverEvent (API v2) = | ||
Contents |
Starting in API v2, it is possible register functions as event handlers. To register an event handler, use:
The event parameter is the name of the event (see list at end of section for known events) and the handler parameter is the function that will be called whenever the event occurs. Event names are not case sensitive. An event object will be passed into the handler, and the type and behavior of that object is event specific.
Any number of event handlers may be added to a given event, and one handler may be registered to any number of events. The order of execution of event handlers is not guaranteed.
To remove an event handler, use:
The function passed in will no longer be called as a result of the event occurring. Any currently pending calls to the listener are still made, however.
If an event handler is registered using addEventListener, then any callback in the global plasmoid object that may be related to the same event will be suppressed. For instance, if an event handler is registered using addEventListener for the paintInterface event, then plasmoid.paintInterface will not be called.
Following are the input events which are recognized on the Plasmoid along with the type of event object passed in to registered event listeners:
Example:
// anonymous function as a listener on KeyPress plasmoid.addEventListener('KeyPress', function(a) { print(a.key) }) function output() { print('Hover Event!') } function hovered(event) { plasmoid.busy = true plasmoid.removeEventListener('HoverEnter', output) } function unhovered(event) { plasmoid.busy = false } plasmoid.addEventListener('HoverEnter', hovered) plasmoid.addEventListener('HoverLeave', unhovered) plasmoid.addEventListener('HoverEnter', output) plasmoid.addEventListener('HoverLeave', output)
The following two events are used in conjuction with Addons. See the Addons documentation for more information on Addons.