Constructor

new DropDownDiv()

Class for drop-down div.

Properties

animateOutTimer_

static

nullable number

Timer for animation out, to be cleared if we need to immediately hide without disrupting new shows.

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).

DEFAULT_DROPDOWN_BORDER_COLOR

constant   static

string

The default dropdown div border color.

DEFAULT_DROPDOWN_COLOR

constant   static

string

The default dropdown div color.

onHide_

static

nullable function()

Callback for when the drop-down is hidden.

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

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

Element Div to populate with content

getPositionAboveMetrics

static

getPositionAboveMetrics(secondaryX, secondaryY, boundsInfo, divSize) returns Object

Get the metrics for positioning the div above the source.

Parameter

secondaryX

number

Secondary/alternative origin point x, in absolute px.

secondaryY

number

Secondary/alternative origin point y, in absolute px.

boundsInfo

Object

An object containing size information about the bounding element (bounding box and width/height).

Value must not be null.

divSize

Object

An object containing information about the size of the DropDownDiv (width & height).

Value must not be null.

Returns

Object Various final metrics, including rendered positions for drop-down and arrow.

getPositionBelowMetrics

static

getPositionBelowMetrics(primaryX, primaryY, boundsInfo, divSize) returns Object

Get the metrics for positioning the div below the source.

Parameter

primaryX

number

Desired origin point x, in absolute px.

primaryY

number

Desired origin point y, in absolute px.

boundsInfo

Object

An object containing size information about the bounding element (bounding box and width/height).

Value must not be null.

divSize

Object

An object containing information about the size of the DropDownDiv (width & height).

Value must not be null.

Returns

Object Various final metrics, including rendered positions for drop-down and arrow.

getPositionMetrics

static

getPositionMetrics(primaryX, primaryY, secondaryX, secondaryY) returns Object

Helper to position the drop-down and the arrow, maintaining bounds. See explanation of origin points in Blockly.DropDownDiv.show.

Parameter

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.

Returns

Object Various final metrics, including rendered positions for drop-down and arrow.

getPositionTopOfPageMetrics

static

getPositionTopOfPageMetrics(sourceX, boundsInfo, divSize) returns Object

Get the metrics for positioning the div at the top of the page.

Parameter

sourceX

number

Desired origin point x, in absolute px.

boundsInfo

Object

An object containing size information about the bounding element (bounding box and width/height).

Value must not be null.

divSize

Object

An object containing information about the size of the DropDownDiv (width & height).

Value must not be null.

Returns

Object Various final metrics, including rendered positions for drop-down and arrow.

getPositionX

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

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.

setCategory

static

setCategory(category)

Set the category for the drop-down.

Parameter

category

string

The new category for the drop-down.

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.Block

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.