Classes

Namespaces

Property

global

static

Reference to the global object.

Methods

arrayRemove

package   static

arrayRemove(arr, obj) returns boolean

Removes the first occurrence of a particular value from an array.

Parameter

arr

Array

Array from which to remove value.

Value must not be null.

obj

any type

Object to remove.

Returns

boolean True if an element was removed.

checkMessageReferences

static

checkMessageReferences(message) returns boolean

Validates that any %{MSG_KEY} references in the message refer to keys of the Blockly.Msg string table.

Parameter

message

string

Text which might contain string table references.

Returns

boolean True if all message references have matching values. Otherwise, false.

genUid

static

genUid() returns string

Generate a unique ID. This should be globally unique. 87 characters ^ 20 length > 128 bits (better than a UUID).

Returns

string A globally unique ID string.

getBlockTypeCounts

static

getBlockTypeCounts(block, opt_stripFollowing) returns Object

Get a map of all the block's descendants mapping their type to the number of children with that type.

Parameter

block

Blockly.Block

The block to map.

Value must not be null.

opt_stripFollowing

Optional

boolean

Optionally ignore all following statements (blocks that are not inside a value or statement input of the block).

Returns

non-null Object Map of types to type counts for descendants of the bock.

getDocumentScroll

static

getDocumentScroll() returns Blockly.utils.Coordinate

Gets the document scroll distance as a coordinate object. Copied from Closure's goog.dom.getDocumentScroll.

Returns

non-null Blockly.utils.Coordinate Object with values 'x' and 'y'.

getInjectionDivXY_

static

getInjectionDivXY_(element) returns Blockly.utils.Coordinate

Return the coordinates of the top-left corner of this element relative to the div Blockly was injected into.

Parameter

element

Element

SVG element to find the coordinates of. If this is not a child of the div Blockly was injected into, the behaviour is undefined.

Value must not be null.

Returns

non-null Blockly.utils.Coordinate Object with .x and .y properties.

getRelativeXY

static

getRelativeXY(element) returns Blockly.utils.Coordinate

Return the coordinates of the top-left corner of this element relative to its parent. Only for SVG elements and children (e.g. rect, g, path).

Parameter

element

Element

SVG element to find the coordinates of.

Value must not be null.

Returns

non-null Blockly.utils.Coordinate Object with .x and .y properties.

getScrollDeltaPixels

static

getScrollDeltaPixels(e) returns Object

Get the scroll delta of a mouse event in pixel units.

Parameter

e

Event

Mouse event.

Value must not be null.

Returns

{x: number, y: number} Scroll delta object with .x and .y properties.

getViewportBBox

package   static

getViewportBBox() returns Object

Get the position of the current viewport in window coordinates. This takes scroll into account.

Returns

non-null Object An object containing window width, height, and scroll position in window coordinates.

is3dSupported

static

is3dSupported() returns boolean

Check if 3D transforms are supported by adding an element and attempting to set the property.

Returns

boolean True if 3D transforms are supported.

isRightButton

static

isRightButton(e) returns boolean

Is this event a right-click?

Parameter

e

Event

Mouse event.

Value must not be null.

Returns

boolean True if right-click.

isTargetInput

static

isTargetInput(e) returns boolean

Is this event targeting a text input widget?

Parameter

e

Event

An event.

Value must not be null.

Returns

boolean True if text input.

mouseToSvg

static

mouseToSvg(e, svg, matrix) returns SVGPoint

Return the converted coordinates of the given mouse event. The origin (0,0) is the top-left corner of the Blockly SVG.

Parameter

e

Event

Mouse event.

Value must not be null.

svg

Element

SVG element.

Value must not be null.

matrix

SVGMatrix

Inverted screen CTM to use.

Returns

non-null SVGPoint Object with .x and .y properties.

noEvent

static

noEvent(e)

Don't do anything for this event, just halt propagation.

Parameter

e

Event

An event.

Value must not be null.

replaceMessageReferences

static

replaceMessageReferences(message) returns string

Replaces string table references in a message, if the message is a string. For example, "%{bky_my_msg}" and "%{BKY_MY_MSG}" will both be replaced with the value in Blockly.Msg['MY_MSG'].

Parameter

message

(string or unknown)

Message, which may be a string that contains string table references.

Returns

string String with message references replaced.

runAfterPageLoad

static

runAfterPageLoad(fn)

Calls a function after the page has loaded, possibly immediately.

Parameter

fn

function()

Function to run.

Throws

Error Will throw if no global document can be found (e.g., Node.js).

tokenizeInterpolation

static

tokenizeInterpolation(message) returns Array of (string or number)

Parse a string with any number of interpolation tokens (%1, %2, ...). It will also replace string table references (e.g., %{bky_my_msg} and %{BKY_MY_MSG} will both be replaced with the value in Blockly.Msg['MY_MSG']). Percentage sign characters '%' may be self-escaped (e.g., '%%').

Parameter

message

string

Text which might contain string table references and interpolation tokens.

Returns

non-null Array of (string or number) Array of strings and numbers.