MHoverable

MHoverable ⇐ Trait

Kind: global class
Extends: Trait
Properties

NameTypeDescription
isHoverableboolean

Feature flag

isHoverboolean

is set to true when the view is hovered

hoverEnabledObject

true by default - if it is false, the view is unHoverable: it is no longer concerned by hover events, nor its children

MHoverable()

Mark a view as being Hoverable

mouseMove(mouseEvent)

Mouse move on the screen

  • set state of the views that are hover

  • call onMouseEnter (extension point)

  • remove state of the view that were hover

  • call onMouseLeave (extension point)

Kind: instance method of MHoverable

ParamType
mouseEventMouseEvent

onMouseEnter(mouseEvent)

Extension point

Kind: instance method of MHoverable

ParamType
mouseEventMouseEvent

onMouseLeave(mouseEvent)

Extension point

Kind: instance method of MHoverable

ParamType
mouseEventMouseEvent

isHovered(mouseEvent) ⇒ boolean

Return true if mouse in hover the view The view must have it’s MHoverable#hoverEnabled set to true.

Kind: instance method of MHoverable

ParamType
mouseEventMouseEvent

getHoverableChildren(mouseEvent) ⇒ Array

Find the views that are candidates to handle mouse move.

Kind: instance method of MHoverable

ParamType
mouseEventMouseEvent

_getHoverableChildren(mouseEvent, hoverableChildren) ⇒ Array

Get all hoverable element at position (mouseEvent.pageX ; mouseEvent.pageY)

Try to find all candidates that has been hovered. It iterates over the view hierarchy to find the hovered view’s (ie the views that are within of the mouseEvent coordinates)

Examples

+————————————+ | ViewA | | +—————————–+ | | | | | | | ButtonA ButtonB ButtonC | | | | | | | +—————————–+ | | | +————————————+ ViewA, ButtonA, ButtonB & ButtonC are all hoverable

mouse on ButtonA => hoverableChildren = [buttonA, ViewA] mouse on ButtonB => hoverableChildren = [buttonB, ViewA] mouse on ButtonC => hoverableChildren = [buttonC, ViewA] mouse outside ButtonA & ButtonB & ButtonC => clickedChildren = [ViewA]

Kind: instance method of MHoverable
Access: protected

ParamTypeDescription
mouseEventMouseEvent

the mouse event

hoverableChildrenArray

_getSortedHoverableCandidates() ⇒ Array.<Object.<id, index>>

Get the children that are candidates to be hoverable. Keep children that are hoverable, sort children by layer then declaration order

Remarks: you may override these method to filter additional view(s), for example

Be careful with the format of the returned object

Kind: instance method of MHoverable
Returns: Array.<Object.<id, index>> - An array of object, where id key value is the child id and index key value the order of declaration
Access: protected

_filterHoverableCandidates(id) ⇒ boolean

Called when the view is looking for hoverable candidates The method is called on children that are hoverable (isHoverable === true) It must returns true if the candidate must be kept, false otherwise

You can override these method

Kind: instance method of MHoverable
Returns: boolean - true if the child must be kept
Access: protected

ParamTypeDescription
idstring

the id of the child

Example

_filterHoverableCandidates: function(id) {
   if (id === "modalPopup" && this.modalPopup.isVisible !== true) {
      // exclude modalPopup if not shown
      return false;
   }
   if (id !== "modalPopup" && this.modalPopup.isVisible === true) {
      // keep only modalPopup if shown
      return false;
   }
   return true;
}