Constructor

new DropDownDiv()

Class for drop-down div.

Properties

animateOutTimer_

static

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

onHide_

static

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

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.

hide

static

hide()

Hide the menu, triggering animation.

hideIfOwner

static

hideIfOwner(owner) 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.

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 wll 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

static

show(owner, 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

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

number

Optional Y offset for above-block positioning.

Returns

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

showPositionedByField

static

showPositionedByField(owner, 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

owner

Object

The object showing the drop-down.

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.