1. Home
  2. Developers
  3. Bric Environment Utilities

Bric Environment Utilities

Blocs includes a range of javascript utility functions that all custom Brics can utilize when running within the custom Bric Sandbox.

Alignment Utilities

These alignment utilities can be used within a custom Brics logic in order to manage the alignment of elements within the HTML.

Apply Alignment Class applyAlignmentClass( target, position, sync )

When called, this function will apply the relevant Bootstrap framework alignment class ( text-start | text-center | text-end ) for the provided target element, it supports breakpoints and replaces any current alignment class for the active breakpoint that may already be applied. It also automatically handles the differences in class names for Bootstrap 4 ( text-left | text-center | text-right ).

This function requires three variables. The first variable is the target which should be a javascript reference to an element within your Brics HTML e.g. $(“.my-element”). The second variable is position, this is an integer variable supporting values from 0 to 2. 0 = Left, 1 = center and 2 = Right. Finally, the third variable is the sync boolean. Setting this value to true will trigger the sync API call.

Beginner tip

If you intend to align multiple elements with individual calls, you should set the sync value to true on the final call, to prevent unwanted undo states being generated.

Get Alignment State getAlignmentState( target )

When called, this function will get the current Bootstrap framework alignment class used on a target element ( text-start | text-center | text-end ) based on the active breakpoint and Bootstrap version. This function will return an integer value of either 0 (left), 1 (center) or 2 (right), which can be used to populate your Brics control user interface.

This function requires one variable (target) which should be a javascript reference to an element within your Brics HTML e.g. $(“.my-element”).

Number Utilities

Generate Random Integer getRandomInt( min, max )

When called, this function will generate and return a random integer value between the minimum and maximum integer variables provided.

Updated on 24th January 2023

Was this article helpful?

Related Articles