Show:

A widget extension, which can be used to add constrained xy positioning support to the base Widget class, through the <a href="Base.html#method_build">Base.build</a> method. This extension requires that the WidgetPosition extension be added to the Widget (before WidgetPositionConstrain, if part of the same extension list passed to Base.build).

Methods

_afterConstrainChange

(
  • e
)
protected

After change listener for the "constrain" attribute, responsible for updating the UI, in response to attribute changes.

Parameters:

  • e EventFacade

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The event facade</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

_bindUIPosConstrained

() protected

Binds event listeners responsible for updating the UI state in response to Widget constrained positioning related state changes. <p> This method is invoked after bindUI is invoked for the Widget class using YUI's aop infrastructure. </p>

_constrain

(
  • val
  • axis
  • nodeRegion
  • constrainingRegion
)
Number protected

The method which performs the actual constrain calculations for a given axis ("x" or "y") based on the regions provided.

Parameters:

  • val Number

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The value to constrain</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

  • axis String

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The axis to use for constrainment</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

  • nodeRegion Region

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The region of the node to constrain</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

  • constrainingRegion Region

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The region of the node (or viewport) to constrain to</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

Returns:

Number:

<p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The constrained value</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

_constrainOnXYChange

(
  • e
)
protected

The on change listener for the "xy" attribute. Modifies the event facade's newVal property with the constrained XY value.

Parameters:

  • e EventFacade

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The event facade for the attribute change</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

_enableConstraints

(
  • enable
)
private

Updates the UI if enabling constraints, and sets up the xyChange event listeners to constrain whenever the widget is moved. Disabling constraints removes the listeners.

Parameters:

  • enable Boolean

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>Enable or disable constraints</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

_getRegion

(
  • node
)
private

Utility method to normalize region retrieval from a node instance, or the viewport, if no node is provided.

Parameters:

  • node Node

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>Optional.</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

_preventOverlap

(
  • val
  • axis
  • nodeRegion
  • constrainingRegion
)
Number protected

The method which performs the preventOverlap calculations for a given axis ("x" or "y") based on the value and regions provided.

Parameters:

  • val Number

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The value being constrain</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

  • axis String

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The axis to being constrained</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

  • nodeRegion Region

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The region of the node being constrained</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

  • constrainingRegion Region

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The region of the node (or viewport) we need to constrain to</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

Returns:

Number:

<p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The constrained value</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

_setConstrain

(
  • val
)
protected

The setter implementation for the "constrain" attribute.

Parameters:

  • val Node | boolean

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The attribute value</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

constrain

(
  • xy
  • node
)

Constrains the widget's bounding box to a node (or the viewport). If xy or node are not passed in, the current position and the value of "constrain" will be used respectively.

The widget's position will be changed to the constrained position.

Parameters:

  • xy Array

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>Optional. The xy values to constrain</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

  • node Node | boolean

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>Optional. The node to constrain to, or true for the viewport</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

getConstrainedXY

(
  • xy
  • node
)
Array

Calculates the constrained positions for the XY positions provided, using the provided node argument is passed in. If no node value is passed in, the value of the "constrain" attribute is used.

Parameters:

  • xy Array

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The xy values to constrain</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

  • node Node | boolean

    <p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>Optional. The node to constrain to, or true for the viewport</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

Returns:

Array:

<p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p>The constrained xy values</p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p></p>

Properties

_PREVENT_OVERLAP

Object protected static

The set of positions for which to prevent overlap.

ATTRS

Object static

Static property used to define the default attribute configuration introduced by WidgetPositionConstrain.

Attributes

constrain

Boolean | Node

The node to constrain the widget's bounding box to, when setting xy. Can also be set to true, to constrain to the viewport.

Default: null

preventOverlap

Boolean

If set to true, and WidgetPositionAlign is also added to the Widget, constrained positioning will attempt to prevent the widget's bounding box from overlapping the element to which it has been aligned, by flipping the orientation of the alignment for corner based alignments