Difference between revisions of "LGUI2:Hooks"

From Lavish Software Wiki
Jump to navigation Jump to search
(Created page with "LavishGUI 2 Hooks provide a way to attach an LGUI2:Event Handler to another related Element. == Defining a Hook == Each Hook must be defined with a JSON object enclosed ...")
 
Line 6: Line 6:
 
Each item in the object is expected to be a string, except "eventHandler".
 
Each item in the object is expected to be a string, except "eventHandler".
  
* "elementType": Optionally provides the element type of an element to locate
+
{| border="1" style="border-collapse:collapse" cellpadding="5"
* "elementName": Optionally provides the name of an element to locate
+
!colspan="2"|Hook properties
* "flags": Optionally provides relationship flags for searching. "ancestor" is used by default for hooks.
+
|-
* "event": The name of the event to attach to, in the target element
+
! elementType
* "eventHandler": An [[LGUI2:Event Handler|Event Handler]] definition
+
| (optional) The element type of an element to attach to
 +
|-
 +
! elementName
 +
| (optional) The name of an element to attach to
 +
|-
 +
! flags
 +
| (optional) Relationship flags for locating the element to attach to. "ancestor" is used by default for hooks.
 +
|-
 +
! event
 +
| The name the event to attach to, in the target element
 +
|-
 +
! eventHandler
 +
| An [[LGUI2:Event Handler|Event Handler]] definition
 +
|}
 +
 
 +
If no optional properties are provided, the parent element (the first ancestor, as per the default flag) will be the target for the hook.
  
If no optional properties are provided, the parent element will be the target for the hook.
 
  
 
== Examples ==
 
== Examples ==
Line 28: Line 42:
  
 
[[Category:LavishGUI 2|LavishGUI 2]]
 
[[Category:LavishGUI 2|LavishGUI 2]]
 +
[[Category:LavishGUI 2 Events]]

Revision as of 04:12, 15 July 2018

LavishGUI 2 Hooks provide a way to attach an Event Handler to another related Element.

Defining a Hook

Each Hook must be defined with a JSON object enclosed by {}, usually as part of a "hooks" property when defining an Element.

Each item in the object is expected to be a string, except "eventHandler".

Hook properties
elementType (optional) The element type of an element to attach to
elementName (optional) The name of an element to attach to
flags (optional) Relationship flags for locating the element to attach to. "ancestor" is used by default for hooks.
event The name the event to attach to, in the target element
eventHandler An Event Handler definition

If no optional properties are provided, the parent element (the first ancestor, as per the default flag) will be the target for the hook.


Examples

From the default skin's checkbox definition

This hook applies the "onUnchecked" Style to the current element, when the nearest checkbox ancestor's (the checkbox containing this element) "onUnchecked" event fires.

"hooks": {
  "onUnchecked": {
    "elementType": "checkbox",
    "event": "onUnchecked",
    "eventHandler": {
    "type": "style",
    "styleName": "onUnchecked"
  }
}