Blockly. utils
Utility methods.
Classes
Coordinate
Class for representing coordinates and positions.
Rect
Class for representing rectangular regions.
Sentinel
A type used to create flag values.
Size
Class for representing sizes consisting of a width and height.
Svg
A name with the type of the SVG element stored in the generic.
Interface
Metrics
Namespaces
aria
array
colour
deprecation
dom
global
idGenerator
KeyCodes
math
Metrics
object
parsing
string
style
svgMath
svgPaths
toolbox
userAgent
xml
Enumeration
KeyCodes
number
Key codes for common characters.
Copied from Closure's goog.events.KeyCodes
This list is not localized and therefore some of the key codes are not correct for non US keyboard layouts. See comments below.
Value |
|
---|---|
WIN_KEY_FF_LINUX |
|
MAC_ENTER |
|
BACKSPACE |
|
TAB |
|
NUM_CENTER |
|
ENTER |
|
SHIFT |
|
CTRL |
|
ALT |
|
PAUSE |
|
CAPS_LOCK |
|
ESC |
|
SPACE |
|
PAGE_UP |
|
PAGE_DOWN |
|
END |
|
HOME |
|
LEFT |
|
UP |
|
RIGHT |
|
DOWN |
|
PLUS_SIGN |
|
PRINT_SCREEN |
|
INSERT |
|
DELETE |
|
ZERO |
|
ONE |
|
TWO |
|
THREE |
|
FOUR |
|
FIVE |
|
SIX |
|
SEVEN |
|
EIGHT |
|
NINE |
|
FF_SEMICOLON |
|
FF_EQUALS |
|
FF_DASH |
|
FF_HASH |
|
QUESTION_MARK |
|
AT_SIGN |
|
A |
|
B |
|
C |
|
D |
|
E |
|
F |
|
G |
|
H |
|
I |
|
J |
|
K |
|
L |
|
M |
|
N |
|
O |
|
P |
|
Q |
|
R |
|
S |
|
T |
|
U |
|
V |
|
W |
|
X |
|
Y |
|
Z |
|
META |
|
WIN_KEY_RIGHT |
|
CONTEXT_MENU |
|
NUM_ZERO |
|
NUM_ONE |
|
NUM_TWO |
|
NUM_THREE |
|
NUM_FOUR |
|
NUM_FIVE |
|
NUM_SIX |
|
NUM_SEVEN |
|
NUM_EIGHT |
|
NUM_NINE |
|
NUM_MULTIPLY |
|
NUM_PLUS |
|
NUM_MINUS |
|
NUM_PERIOD |
|
NUM_DIVISION |
|
F1 |
|
F2 |
|
F3 |
|
F4 |
|
F5 |
|
F6 |
|
F7 |
|
F8 |
|
F9 |
|
F10 |
|
F11 |
|
F12 |
|
NUMLOCK |
|
SCROLL_LOCK |
|
FIRST_MEDIA_KEY |
|
LAST_MEDIA_KEY |
|
SEMICOLON |
|
DASH |
|
EQUALS |
|
COMMA |
|
PERIOD |
|
SLASH |
|
APOSTROPHE |
|
TILDE |
|
SINGLE_QUOTE |
|
OPEN_SQUARE_BRACKET |
|
BACKSLASH |
|
CLOSE_SQUARE_BRACKET |
|
WIN_KEY |
|
MAC_FF_META |
|
MAC_WK_CMD_LEFT |
|
MAC_WK_CMD_RIGHT |
|
WIN_IME |
|
VK_NONAME |
|
PHANTOM |
Property
KeyCodes
number
Key codes for common characters.
Copied from Closure's goog.events.KeyCodes
This list is not localized and therefore some of the key codes are not correct for non US keyboard layouts. See comments below.
Value |
|
---|---|
WIN_KEY_FF_LINUX |
|
MAC_ENTER |
|
BACKSPACE |
|
TAB |
|
NUM_CENTER |
|
ENTER |
|
SHIFT |
|
CTRL |
|
ALT |
|
PAUSE |
|
CAPS_LOCK |
|
ESC |
|
SPACE |
|
PAGE_UP |
|
PAGE_DOWN |
|
END |
|
HOME |
|
LEFT |
|
UP |
|
RIGHT |
|
DOWN |
|
PLUS_SIGN |
|
PRINT_SCREEN |
|
INSERT |
|
DELETE |
|
ZERO |
|
ONE |
|
TWO |
|
THREE |
|
FOUR |
|
FIVE |
|
SIX |
|
SEVEN |
|
EIGHT |
|
NINE |
|
FF_SEMICOLON |
|
FF_EQUALS |
|
FF_DASH |
|
FF_HASH |
|
QUESTION_MARK |
|
AT_SIGN |
|
A |
|
B |
|
C |
|
D |
|
E |
|
F |
|
G |
|
H |
|
I |
|
J |
|
K |
|
L |
|
M |
|
N |
|
O |
|
P |
|
Q |
|
R |
|
S |
|
T |
|
U |
|
V |
|
W |
|
X |
|
Y |
|
Z |
|
META |
|
WIN_KEY_RIGHT |
|
CONTEXT_MENU |
|
NUM_ZERO |
|
NUM_ONE |
|
NUM_TWO |
|
NUM_THREE |
|
NUM_FOUR |
|
NUM_FIVE |
|
NUM_SIX |
|
NUM_SEVEN |
|
NUM_EIGHT |
|
NUM_NINE |
|
NUM_MULTIPLY |
|
NUM_PLUS |
|
NUM_MINUS |
|
NUM_PERIOD |
|
NUM_DIVISION |
|
F1 |
|
F2 |
|
F3 |
|
F4 |
|
F5 |
|
F6 |
|
F7 |
|
F8 |
|
F9 |
|
F10 |
|
F11 |
|
F12 |
|
NUMLOCK |
|
SCROLL_LOCK |
|
FIRST_MEDIA_KEY |
|
LAST_MEDIA_KEY |
|
SEMICOLON |
|
DASH |
|
EQUALS |
|
COMMA |
|
PERIOD |
|
SLASH |
|
APOSTROPHE |
|
TILDE |
|
SINGLE_QUOTE |
|
OPEN_SQUARE_BRACKET |
|
BACKSLASH |
|
CLOSE_SQUARE_BRACKET |
|
WIN_KEY |
|
MAC_FF_META |
|
MAC_WK_CMD_LEFT |
|
MAC_WK_CMD_RIGHT |
|
WIN_IME |
|
VK_NONAME |
|
PHANTOM |
Methods
arrayRemove
arrayRemove(arr, value) 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. |
value |
any type Value to remove. |
- Deprecated
- Returns
-
boolean
True if an element was removed.
checkMessageReferences
checkMessageReferences(message) returns boolean
Validates that any %{MSG_KEY} references in the message refer to keys of the Msg string table.
Parameter |
|
---|---|
message |
string Text which might contain string table references. |
- Deprecated
- Returns
-
boolean
True if all message references have matching values. Otherwise, false.
genUid
genUid() returns string
Generate a unique ID.
- Deprecated
- Use Blockly.utils.idGenerator.genUid instead.
- Returns
-
string
A globally unique ID string.
getBlockTypeCounts
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 |
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). |
- Deprecated
- Returns
-
non-null Object
Map of types to type counts for descendants of the bock.
getDocumentScroll
getDocumentScroll() returns Blockly.utils.Coordinate
Gets the document scroll distance as a coordinate object. Copied from Closure's goog.dom.getDocumentScroll.
- Deprecated
- Returns
-
non-null Blockly.utils.Coordinate
Object with values 'x' and 'y'.
getInjectionDivXY_
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. |
- Deprecated
- Returns
-
non-null Blockly.utils.Coordinate
Object with .x and .y properties.
getRelativeXY
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. |
- Deprecated
- Returns
-
non-null Blockly.utils.Coordinate
Object with .x and .y properties.
getScrollDeltaPixels
getScrollDeltaPixels(e) returns Object
Returns the scroll delta of a mouse event in pixel units.
Parameter |
|
---|---|
e |
Event Mouse event. Value must not be null. |
- Deprecated
- Use Blockly.browserEvents.getScrollDeltaPixels instead.
- Returns
-
{x: number, y: number}
Scroll delta object with .x and .y properties.
getViewportBBox
getViewportBBox() returns Blockly.utils.Rect
Get the position of the current viewport in window coordinates. This takes scroll into account.
- Deprecated
- Returns
-
non-null Blockly.utils.Rect
An object containing window width, height, and scroll position in window coordinates.
is3dSupported
is3dSupported() returns boolean
Check if 3D transforms are supported by adding an element and attempting to set the property.
- Deprecated
- Returns
-
boolean
True if 3D transforms are supported.
isRightButton
isRightButton(e) returns boolean
Returns true this event is a right-click.
Parameter |
|
---|---|
e |
Event Mouse event. Value must not be null. |
- Deprecated
- Use Blockly.browserEvents.isRightButton instead.
- Returns
-
boolean
True if right-click.
isTargetInput
isTargetInput(e) returns boolean
Returns true if this event is targeting a text input widget?
Parameter |
|
---|---|
e |
Event An event. Value must not be null. |
- Deprecated
- Use Blockly.browserEvents.isTargetInput instead.
- Returns
-
boolean
True if text input.
mouseToSvg
mouseToSvg(e, svg, matrix) returns SVGPoint
Returns 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. Value may be null. |
- Deprecated
- Use Blockly.browserEvents.mouseToSvg instead;
- Returns
-
non-null SVGPoint
Object with .x and .y properties.
noEvent
noEvent(e)
Halts the propagation of the event without doing anything else.
Parameter |
|
---|---|
e |
Event An event. Value must not be null. |
- Deprecated
parseBlockColour
parseBlockColour(colour) returns Object
Parse a block colour from a number or string, as provided in a block definition.
Parameter |
|
---|---|
colour |
(number or string) HSV hue value (0 to 360), #RRGGBB string, or a message reference string pointing to one of those two values. |
- Deprecated
- Throws
-
Error
If the colour cannot be parsed. - Returns
-
{hue: nullable number, hex: string}
An object containing the colour as a #RRGGBB string, and the hue if the input was an HSV hue value.
replaceMessageReferences
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 Msg['MY_MSG'].
Parameter |
|
---|---|
message |
(string or unknown) Message, which may be a string that contains string table references. |
- Deprecated
- Returns
-
string
String with message references replaced.
runAfterPageLoad
runAfterPageLoad(fn)
Calls a function after the page has loaded, possibly immediately.
Parameter |
|
---|---|
fn |
function() Function to run. |
- Deprecated
- Throws
-
Error Will throw if no global document can be found (e.g., Node.js).
tokenizeInterpolation
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 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. |
- Deprecated
- Returns
-
non-null Array of (string or number)
Array of strings and numbers.