Class: DropDownDiv

Constructor

new DropDownDiv()

Class for drop-down div.

Properties

ANIMATION_TIME

constant   static

number

Length of animations in seconds.

ARROW_HORIZONTAL_PADDING

constant   static

number

Amount the arrow must be kept away from the edges of the main drop-down div, in px.

ARROW_SIZE

constant   static

number

Arrow size in px. Should match the value in CSS (need to position pre-render).

BORDER_SIZE

constant   static

number

Drop-down border size in px. Should match the value in CSS (need to position the arrow).

owner_

static

non-null Blockly.Field

PADDING_Y

constant   static

number

Amount drop-downs should be padded away from the source, in px.

Methods

clearContent

static

clearContent()

Clear the content of the drop-down.

createDom

package   static

createDom()

Create and insert the DOM element for this div.

getContentDiv

static

getContentDiv() returns Element

Provide the div for inserting content into the drop-down.

Returns

non-null Element Div to populate with content.

getPositionX

package   static

getPositionX(sourceX, boundsLeft, boundsRight, divWidth) returns Object

Get the x positions for the left side of the DropDownDiv and the arrow, accounting for the bounds of the workspace.

Parameter

sourceX

number

Desired origin point x, in absolute px.

boundsLeft

number

The left edge of the bounding element, in absolute px.

boundsRight

number

The right edge of the bounding element, in absolute px.

divWidth

number

The width of the div in px.

Returns

{divX: number, arrowX: number} An object containing metrics for the x positions of the left side of the DropDownDiv and the arrow.

hide

static

hide()

Hide the menu, triggering animation.

hideIfOwner

static

hideIfOwner(owner, opt_withoutAnimation) returns boolean

Hide the menu only if it is owned by the provided object.

Parameter

owner

Object

Object which must be owning the drop-down to hide.

opt_withoutAnimation

Optional

boolean

True if we should hide the dropdown without animating.

Returns

boolean True if hidden.

hideWithoutAnimation

static

hideWithoutAnimation()

Hide the menu, without animation.

isVisible

static

isVisible() returns boolean

Is the container visible?

Returns

boolean True if visible.

repositionForWindowResize

package   static

repositionForWindowResize()

Repositions the dropdownDiv on window resize. If it doesn't know how to calculate the new position, it will just hide it instead.

setBoundsElement

static

setBoundsElement(boundsElement)

Set an element to maintain bounds within. Drop-downs will appear within the box of this element if possible.

Parameter

boundsElement

Element

Element to bind drop-down to.

setColour

static

setColour(backgroundColour, borderColour)

Set the colour for the drop-down.

Parameter

backgroundColour

string

Any CSS colour for the background.

borderColour

string

Any CSS colour for the border.

show

package   static

show(owner, rtl, primaryX, primaryY, secondaryX, secondaryY, opt_onHide) returns boolean

Show and place the drop-down. The drop-down is placed with an absolute "origin point" (x, y) - i.e., the arrow will point at this origin and box will positioned below or above it. If we can maintain the container bounds at the primary point, the arrow will point there, and the container will be positioned below it. If we can't maintain the container bounds at the primary point, fall-back to the secondary point and position above.

Parameter

owner

Object

The object showing the drop-down

rtl

boolean

Right-to-left (true) or left-to-right (false).

primaryX

number

Desired origin point x, in absolute px.

primaryY

number

Desired origin point y, in absolute px.

secondaryX

number

Secondary/alternative origin point x, in absolute px.

secondaryY

number

Secondary/alternative origin point y, in absolute px.

opt_onHide

Optional

function()

Optional callback for when the drop-down is hidden.

Returns

boolean True if the menu rendered at the primary origin point.

showPositionedByBlock

static

showPositionedByBlock(field, block, opt_onHide, opt_secondaryYOffset) returns boolean

Shortcut to show and place the drop-down with positioning determined by a particular block. The primary position will be below the block, and the secondary position above the block. Drop-down will be constrained to the block's workspace.

Parameter

field

Blockly.Field

The field showing the drop-down.

Value must not be null.

block

Blockly.BlockSvg

Block to position the drop-down around.

Value must not be null.

opt_onHide

Optional

function()

Optional callback for when the drop-down is hidden.

opt_secondaryYOffset

Optional

number

Optional Y offset for above-block positioning.

Returns

boolean True if the menu rendered below block; false if above.

showPositionedByField

static

showPositionedByField(field, opt_onHide, opt_secondaryYOffset) returns boolean

Shortcut to show and place the drop-down with positioning determined by a particular field. The primary position will be below the field, and the secondary position above the field. Drop-down will be constrained to the block's workspace.

Parameter

field

Blockly.Field

The field to position the dropdown against.

Value must not be null.

opt_onHide

Optional

function()

Optional callback for when the drop-down is hidden.

opt_secondaryYOffset

Optional

number

Optional Y offset for above-block positioning.

Returns

boolean True if the menu rendered below block; false if above.

Abstract types

BoundsInfo

static

{top:number, left:number, bottom:number, right:number, width:number, height:number}

Dropdown bounds info object used to encapsulate sizing information about a bounding element (bounding box and width/height).

PositionMetrics

static

{initialX:number, initialY:number, finalX:number, finalY:number, arrowX: nullable number, arrowY: nullable number, arrowAtTop: nullable boolean, arrowVisible:boolean}

Dropdown position metrics.