Namespace

Methods

addClass

static

addClass(element, className) returns boolean

Add a CSS class to a element. Similar to Closure's goog.dom.classes.add, except it handles SVG elements.

Parameter

element

Element

DOM element to add class to.

Value must not be null.

className

string

Name of class to add.

Returns

boolean True if class was added, false if already present.

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.

commonWordPrefix

static

commonWordPrefix(array, opt_shortest) returns number

Given an array of strings, return the length of the common prefix. Words may not be split. Any space after a word is included in the length.

Parameter

array

Array of string

Array of strings.

Value must not be null.

opt_shortest

Optional

number

Length of shortest string.

Returns

number Length of common prefix.

commonWordSuffix

static

commonWordSuffix(array, opt_shortest) returns number

Given an array of strings, return the length of the common suffix. Words may not be split. Any space after a word is included in the length.

Parameter

array

Array of string

Array of strings.

Value must not be null.

opt_shortest

Optional

number

Length of shortest string.

Returns

number Length of common suffix.

createSvgElement

static

createSvgElement(name, attrs, parent) returns SVGElement

Helper method for creating SVG elements.

Parameter

name

string

Element's tag name.

attrs

Object

Dictionary of attribute names and values.

Value must not be null.

parent

Element

Optional parent on which to append the element.

Returns

non-null SVGElement Newly created SVG element.

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.

getInjectionDivXY_

static

getInjectionDivXY_(element) returns goog.math.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 goog.math.Coordinate Object with .x and .y properties.

getRelativeXY

static

getRelativeXY(element) returns goog.math.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 goog.math.Coordinate Object with .x and .y properties.

getViewportBBox

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.

hasClass

static

hasClass(element, className) returns boolean

Checks if an element has the specified CSS class. Similar to Closure's goog.dom.classes.has, except it handles SVG elements.

Parameter

element

Element

DOM element to check.

Value must not be null.

className

string

Name of class to check.

Returns

boolean True if class exists, false otherwise.

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.

removeAttribute

static

removeAttribute(element, attributeName)

Remove an attribute from a element even if it's in IE 10. Similar to Element.removeAttribute() but it works on SVG elements in IE 10. Sets the attribute to null in IE 10, which treats removeAttribute as a no-op if it's called on an SVG element.

Parameter

element

Element

DOM element to remove attribute from.

Value must not be null.

attributeName

string

Name of attribute to remove.

removeClass

static

removeClass(element, className) returns boolean

Remove a CSS class from a element. Similar to Closure's goog.dom.classes.remove, except it handles SVG elements.

Parameter

element

Element

DOM element to remove class from.

Value must not be null.

className

string

Name of class to remove.

Returns

boolean True if class was removed, false if never present.

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

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

setCssTransform

static

setCssTransform(node, transform)

Sets the CSS transform property on an element. This function sets the non-vendor-prefixed and vendor-prefixed versions for backwards compatibility with older browsers. See http://caniuse.com/#feat=transforms2d

Parameter

node

Element

The node which the CSS transform should be applied.

Value must not be null.

transform

string

The value of the CSS transform property.

shortestStringLength

static

shortestStringLength(array) returns number

Given an array of strings, return the length of the shortest one.

Parameter

array

Array of string

Array of strings.

Value must not be null.

Returns

number Length of shortest string.

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.

wrap

static

wrap(text, limit) returns string

Wrap text to the specified width.

Parameter

text

string

Text to wrap.

limit

number

Width to wrap each line.

Returns

string Wrapped text.