Element: <oj-masonry-layout>

Oracle® JavaScript Extension Toolkit (JET)
4.2.0

E91398-01

QuickNav

Attributes

PREVIEW: This is a preview API. Preview APIs are production quality, but can be changed on a major version without a deprecation path.

Version:
  • 4.2.0
Since:
  • 1.1.0

JET Custom Elements

JET components are implemented as custom HTML elements. A detailed description of working with these elements can be found in: JET Custom Element Usage.

JET MasonryLayout

Description: A grid of tiles.

A JET MasonryLayout can contain multiple direct child elements that can be sized and positioned.

Each direct child element must be styled using one of the predefined oj-masonrylayout-tile-CxR style classes to specify the size of that tile. A tile can span multiple columns and/or rows. The predefined size style classes are:

Class Description
oj-masonrylayout-tile-1x1 A tile that spans 1 column and 1 row.
oj-masonrylayout-tile-1x2 A tile that spans 1 column and 2 rows.
oj-masonrylayout-tile-1x3 A tile that spans 1 column and 3 rows.
oj-masonrylayout-tile-2x1 A tile that spans 2 columns and 1 row.
oj-masonrylayout-tile-2x2 A tile that spans 2 columns and 2 rows.
oj-masonrylayout-tile-2x3 A tile that spans 2 columns and 3 rows.
oj-masonrylayout-tile-3x1 A tile that spans 3 columns and 1 row.
oj-masonrylayout-tile-3x2 A tile that spans 3 columns and 2 rows.

The number of columns in the layout is determined by the width of the element and the width of a 1x1 tile. The number of rows is determined by the number of columns and the number and sizes of tiles to be laid out. When the element is resized, relayout will occur and the number of columns and rows may change.

When performing layout, tiles are processed in the order in which they originally appeared in the DOM. Cells in the grid are processed in left-to-right, top-to-bottom order (or right-to-left, top-to-bottom order when the reading direction is right-to-left). A tile will be positioned in the first empty cell in which it fits. This can result in empty cells in the layout. Subsequent tiles may fill those earlier gaps if they fit.


<oj-masonry-layout>
  <div class='oj-masonrylayout-tile-2x1'>Alpha</div>
  <div class='oj-masonrylayout-tile-1x2'>Beta</div>
  <div class='oj-masonrylayout-tile-1x1'>Gamma</div>
  <div class='oj-masonrylayout-tile-1x1'>Delta</div>
  <div class='oj-masonrylayout-tile-1x1'>Epsilon</div>
  <div class='oj-masonrylayout-tile-1x1'>Zeta</div>
</oj-masonry-layout>

Touch End User Information

MasonryLayout is for layout only and does not directly support touch interaction. It is up to the application to provide touch support.

Keyboard End User Information

MasonryLayout is for layout only and does not directly support keyboard interaction. It is up to the application to provide keyboard support.

Keyboard Application Developer Information

Providing keyboard support for the tiles in the masonry layout is the responsibility of the application developer, if the tiles do not already support keyboard interaction. This could be done, for example, by specifying tabindex on each tile to enable tab navigation. Alternatively, this could be done by adding a keyboard listener and responding to key events, like pressing the arrow keys.

Accessibility

MasonryLayout is for layout only. It is the responsibility of the application developer to make the tiles in the layout accessible. Sighted keyboard-only users need to be able to access the tiles in the layout just by using the keyboard. It is up to the child tiles of the MasonryLayout to support keyboard navigation. The MasonryLayout reorders the tile DOM elements to match the visual layout order so that tab order and screen reader reading order will match the visual layout order.

Reading direction

As with any JET element, in the unusual case that the directionality (LTR or RTL) changes post-init, the MasonryLayout must be refresh()ed.

Context Menu

Masonry Layout supports context menu for performing cut and paste operations on tiles as an accessible alternative to drag and drop reordering. When defining a context menu, masonry layout will provide built-in behavior for "cut" and "paste" if the following format for menu <oj-option> items is used:

  • <oj-option data-oj-command="oj-masonrylayout-['commandname']" ></oj-option>
The available translated text will be applied to menu items defined this way.

The supported commands:

Default Function data-oj-command value
Cut oj-masonrylayout-cut
Paste Before oj-masonrylayout-paste-before
Paste After oj-masonrylayout-paste-after

Note: Application logic should not interact with the component's properties or invoke its methods until the BusyContext indicates that the component is ready for interaction.

Example

Define a context menu in the masonry layout for performing cut and paste operation:

<oj-masonry-layout>
  <oj-menu slot="contextMenu">
    <oj-option data-oj-command="oj-masonrylayout-cut" ></oj-option>
    <oj-option data-oj-command="oj-masonrylayout-paste-before" ></oj-option>
    <oj-option data-oj-command="oj-masonrylayout-paste-after" ></oj-option>
  </oj-menu>
</oj-masonry-layout>

Slots

JET elements can have up to two types of child content:

  • Any child element with a slot attribute will be moved into that named slot, e.g. <span slot='startIcon'>...</span>. All supported named slots are documented below. Child elements with unsupported named slots will be removed from the DOM.
  • Any child element lacking a slot attribute will be moved to the default slot, also known as a regular child. This is documented under the "Default" heading below.

Default

<oj-masonry-layout> accepts arbitrary direct child elements that can be sized and positioned, which it will lay out as a grid of tiles. Each direct child element must be styled using one of the predefined oj-masonrylayout-tile-CxR style classes to specify the size of that tile. A tile can span multiple columns and/or rows.

Example

Initialize the masonry layout with child content specified:

<oj-masonry-layout>
  <div class='oj-masonrylayout-tile-2x1'>Alpha</div>
  <div class='oj-masonrylayout-tile-1x2'>Beta</div>
  <div class='oj-masonrylayout-tile-1x1'>Gamma</div>
  <div class='oj-masonrylayout-tile-1x1'>Delta</div>
  <div class='oj-masonrylayout-tile-1x1'>Epsilon</div>
  <div class='oj-masonrylayout-tile-1x1'>Zeta</div>
</oj-masonry-layout>

contextMenu

The contextMenu slot is set on the oj-menu within this element. This is used to designate the JET Menu that this component should launch as a context menu on right-click, Shift-F10, Press & Hold, or component-specific gesture. If specified, the browser's native context menu will be replaced by the JET Menu specified in this slot.

The application can register a listener for the Menu's ojBeforeOpen event. The listener can cancel the launch via event.preventDefault(), or it can customize the menu contents by editing the menu DOM directly, and then calling refresh() on the Menu.

To help determine whether it's appropriate to cancel the launch or customize the menu, the ojBeforeOpen listener can use component API's to determine which table cell, chart item, etc., is the target of the context menu. See the JSDoc and demos of the individual components for details.

Keep in mind that any such logic must work whether the context menu was launched via right-click, Shift-F10, Press & Hold, or component-specific touch gesture.

Example

Initialize the component with a context menu:

<oj-some-element>
    <-- use the contextMenu slot to designate this as the context menu for this component -->
    <oj-menu slot="contextMenu" style="display:none" aria-label="Some element's context menu">
...
    </oj-menu>
</oj-some-element>

Attributes

reorder-handle :string

Specify the selector of the descendant DOM element in a oj-masonry-layout child that can be used to reorder the child by drag-and-drop.

This attribute value is null by default, meaning that oj-masonry-layout children cannot be reordered. If each child that can be reordered has an element with style class 'my-reorder-handle', then the reorder-handle attribute would be specified as '.my-reorder-handle'.

When specifying a reorder-handle, the application should also specify a context menu with actions to cut and paste tiles as an accessible alternative to drag-and-drop reordering.

To specify a context menu, see the documentation of oj-menu.

Default Value:
  • null
Names
Item Name
Property reorderHandle
Property change event reorderHandleChanged
Property change listener attribute (must be of type function) on-reorder-handle-changed
Examples

Initialize the masonryLayout with the reorder-handle attribute specified:

<oj-masonry-layout reorder-handle='.my-reorder-handle'>
  <div id='child1'>
    <div class='my-reorder-handle'/>
  </div>
  <div id='child2'>
    <div class='my-reorder-handle'/>
  </div>
  <!-- additional child elements... -->
</oj-masonry-layout>

Get or set the reorderHandle property after initialization:

// getter
var contentParent = myMasonryLayout.reorderHandle;

// setter
myMasonryLayout.reorderHandle = '.my-reorder-handle';

translations :Object

A collection of translated resources from the translation bundle, or null if this component has no resources. Resources may be accessed and overridden individually or collectively, as seen in the examples.

If this component has translations, their documentation immediately follows this doc entry.

Default Value:
  • an object containing all resources relevant to the component, or null if none
Names
Item Name
Property translations
Property change event translationsChanged
Property change listener attribute (must be of type function) on-translations-changed
Examples

Initialize the component, overriding some translated resources and leaving the others intact:

<!-- Using dot notation -->
<oj-some-element translations.some-key='some value' translations.some-other-key='some other value'></oj-some-element>

<!-- Using JSON notation -->
<oj-some-element translations='{"someKey":"some value", "someOtherKey":"some other value"}'></oj-some-element>

Get or set the translations property after initialization:

// Get one
var value = myComponent.translations.someKey;

// Set one, leaving the others intact. Always use the setProperty API for 
// subproperties rather than setting a subproperty directly.
myComponent.setProperty('translations.someKey', 'some value');

// Get all
var values = myComponent.translations;

// Set all.  Must list every resource key, as those not listed are lost.
myComponent.translations = {
    someKey: 'some value',
    someOtherKey: 'some other value'
};

translations.label-cut :string

Context menu text used for cutting a tile.

See the translations attribute for usage examples.

Default Value:
  • "Cut"
Since:
  • 1.1.0
Names
Item Name
Property translations.labelCut

translations.label-paste-after :string

Context menu text used for pasting a tile after another tile.

See the translations attribute for usage examples.

Default Value:
  • "Paste After"
Since:
  • 1.1.0
Names
Item Name
Property translations.labelPasteAfter

translations.label-paste-before :string

Context menu text used for pasting a tile before another tile.

See the translations attribute for usage examples.

Default Value:
  • "Paste Before"
Since:
  • 1.1.0
Names
Item Name
Property translations.labelPasteBefore

Events

ojAnimateEnd

Triggered when a default animation has ended.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
action string The action that triggers the animation. Supported values are:
  • "insert" - when a tile is inserted
  • "move" - when a tile is moved
  • "remove" - when a tile is removed
  • "resize" - when a tile is resized
  • "reorder" - when a tile is reordered
element Element The element being animated.
Examples

Specify an ojAnimateEnd listener via the DOM attribute:

<oj-masonry-layout on-oj-animate-end='[[listener]]'></oj-masonry-layout>

Specify an ojAnimateEnd listener via the JavaScript property:

myMasonryLayout.onOjAnimateEnd = listener;

Add an ojAnimateEnd listener via the addEventListener API:

myMasonryLayout.addEventListener('ojAnimateEnd', listener);

ojAnimateStart

Triggered when a default animation is about to start on the element.

The default animation can be cancelled by calling event.preventDefault(), followed by a call to event.detail.endCallback(). event.detail.endCallback() should be called immediately after event.preventDefault() if the application merely wants to cancel animation, or it should be called when the custom animation ends if the application is invoking another animation function. Failure to call event.detail.endCallback() may prevent the element from working properly.

For more information on customizing animations, see the documentation of oj.AnimationUtils.

The default animations are controlled via the theme (SCSS) :

$masonryLayoutInsertAnimation: ((effect: "zoomIn", duration: $masonryLayoutAnimationDuration, timingFunction: "ease-in-out"), "fadeIn") !default;
$masonryLayoutRemoveAnimation: ((effect: "zoomOut", duration: $masonryLayoutAnimationDuration, timingFunction: "ease-in-out"), "fadeOut") !default;
$masonryLayoutMoveAnimation: (effect: "addTransition", duration: $masonryLayoutAnimationDuration, timingFunction: "ease-in-out", transitionProperties: ('top', 'left', 'right')) !default;
$masonryLayoutResizeAnimation: (effect: "addTransition", duration: $masonryLayoutAnimationDuration, timingFunction: "ease-in-out", transitionProperties: ('width', 'height', 'top', 'left', 'right')) !default;
$masonryLayoutReorderAnimation: (effect: "addTransition", duration: $masonryLayoutAnimationDurationFast, timingFunction: "ease-in-out", transitionProperties: ('width', 'height', 'top', 'left', 'right')) !default;
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
action string The action that triggers the animation. Supported values are:
  • "insert" - when a tile is inserted
  • "move" - when a tile is moved
  • "remove" - when a tile is removed
  • "resize" - when a tile is resized
  • "reorder" - when a tile is reordered

Note that some animation effects may not look appropriate for a given action.
element Element The element being animated.
endCallback function() If the event listener calls event.preventDefault to cancel the default animation, it must call the endCallback function after it finishes its own animation handling and any custom animation has ended.
Examples

Specify an onOjAnimateStart listener to override the default "insert" animation with a custom animation:

  myMasonryLayout.onOjAnimateStart = function( event )
  {
    if (!$(event.target).is("oj-masonry-layout"))
      return;
    var ui = event.detail;
    // Change the insert animation
    if (ui.action == "insert") {
      event.preventDefault();
      // Invoke new animation and call event.detail.endCallback when it ends
      oj.AnimationUtils.fadeIn(ui.element).then(ui.endCallback);
    }
  }

Specify an onOjAnimateStart listener to prevent the default "remove" animation:

  myMasonryLayout.onOjAnimateStart = function( event )
  {
    if (!$(event.target).is("oj-masonry-layout"))
      return;
    var ui = event.detail;
    // Prevent the remove animation
    if (ui.action == "remove") {
      event.preventDefault();
      ui.endCallback();
    }
  }

Specify an ojAnimateStart listener via the DOM attribute:

<oj-masonry-layout on-oj-animate-start='[[listener]]'></oj-masonry-layout>

Specify an ojAnimateStart listener via the JavaScript property:

myMasonryLayout.onOjAnimateStart = listener;

Add an ojAnimateStart listener via the addEventListener API:

myMasonryLayout.addEventListener('ojAnimateStart', listener);

ojBeforeInsert

Triggered immediately before a tile is inserted. This event can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that is about to be inserted.
index number The 0-based index into the set of rendered oj-masonry-layout children where the tile will be inserted.
Examples

Specify an ojBeforeInsert listener via the DOM attribute:

<oj-masonry-layout on-oj-before-insert='[[listener]]'></oj-masonry-layout>

Specify an ojBeforeInsert listener via the JavaScript property:

myMasonryLayout.onOjBeforeInsert = listener;

Add an ojBeforeInsert listener via the addEventListener API:

myMasonryLayout.addEventListener('ojBeforeInsert', listener);

ojBeforeRemove

Triggered immediately before a tile is removed. This event can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that will be removed.
Examples

Specify an ojBeforeRemove listener via the DOM attribute:

<oj-masonry-layout on-oj-before-remove='[[listener]]'></oj-masonry-layout>

Specify an ojBeforeRemove listener via the JavaScript property:

myMasonryLayout.onOjBeforeRemove = listener;

Add an ojBeforeRemove listener via the addEventListener API:

myMasonryLayout.addEventListener('ojBeforeRemove', listener);

ojBeforeReorder

Triggered immediately before a tile is reordered. This event can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that will be reordered.
fromIndex number The 0-based index into the set of rendered oj-masonry-layout children from which the tile will be reordered.
Examples

Specify an ojBeforeReorder listener via the DOM attribute:

<oj-masonry-layout on-oj-before-reorder='[[listener]]'></oj-masonry-layout>

Specify an ojBeforeReorder listener via the JavaScript property:

myMasonryLayout.onOjBeforeReorder = listener;

Add an ojBeforeReorder listener via the addEventListener API:

myMasonryLayout.addEventListener('ojBeforeReorder', listener);

ojBeforeResize

Triggered immediately before a tile is resized. This event can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that will be resized.
previousSizeStyleClass string The previous size style class applied to the tile.
sizeStyleClass string The new size style class that will be applied to the tile.
Examples

Specify an ojBeforeResize listener via the DOM attribute:

<oj-masonry-layout on-oj-before-resize='[[listener]]'></oj-masonry-layout>

Specify an ojBeforeResize listener via the JavaScript property:

myMasonryLayout.onOjBeforeResize = listener;

Add an ojBeforeResize listener via the addEventListener API:

myMasonryLayout.addEventListener('ojBeforeResize', listener);

ojInsert

Triggered immediately after a tile is inserted.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that was inserted.
index number The 0-based index into the set of rendered oj-masonry-layout children where the tile was inserted.
Examples

Specify an ojInsert listener via the DOM attribute:

<oj-masonry-layout on-oj-insert='[[listener]]'></oj-masonry-layout>

Specify an ojInsert listener via the JavaScript property:

myMasonryLayout.onOjInsert = listener;

Add an ojInsert listener via the addEventListener API:

myMasonryLayout.addEventListener('ojInsert', listener);

ojRemove

Triggered immediately after a tile is removed.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that was removed.
Examples

Specify an ojRemove listener via the DOM attribute:

<oj-masonry-layout on-oj-remove='[[listener]]'></oj-masonry-layout>

Specify an ojRemove listener via the JavaScript property:

myMasonryLayout.onOjRemove = listener;

Add an ojRemove listener via the addEventListener API:

myMasonryLayout.addEventListener('ojRemove', listener);

ojReorder

Triggered immediately after a tile is reordered.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that was reordered.
fromIndex number The 0-based index into the set of rendered oj-masonry-layout children from which the tile was reordered.
toIndex number The 0-based index into the set of rendered oj-masonry-layout children to which the tile was reordered.
Examples

Specify an ojReorder listener via the DOM attribute:

<oj-masonry-layout on-oj-reorder='[[listener]]'></oj-masonry-layout>

Specify an ojReorder listener via the JavaScript property:

myMasonryLayout.onOjReorder = listener;

Add an ojReorder listener via the addEventListener API:

myMasonryLayout.addEventListener('ojReorder', listener);

ojResize

Triggered immediately after a tile is resized.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that was resized.
previousSizeStyleClass string The previous size style class applied to the tile.
sizeStyleClass string The new size style class applied to to the tile.
Examples

Specify an ojResize listener via the DOM attribute:

<oj-masonry-layout on-oj-resize='[[listener]]'></oj-masonry-layout>

Specify an ojResize listener via the JavaScript property:

myMasonryLayout.onOjResize = listener;

Add an ojResize listener via the addEventListener API:

myMasonryLayout.addEventListener('ojResize', listener);

Methods

getProperty(property) → {*}

Retrieves a value for a property or a single subproperty for complex properties.
Parameters:
Name Type Description
property string The property name to get. Supports dot notation for subproperty access.
Returns:
Type
*
Example

Get a single subproperty of a complex property:

var subpropValue = myComponent.getProperty('complexProperty.subProperty1.subProperty2');

insertTile(selector, index)

Insert a tile into the masonryLayout.
Parameters:
Name Type Description
selector string Selector identifying the tile to insert. The tile does not need to be a child of the oj-masonry-layout when this method is called. This method will reparent the tile to the oj-masonry-layout.
index number The 0-based index into the set of rendered oj-masonry-layout children where the tile will be inserted.
Example

Invoke the insertTile method:

myMasonryLayout.insertTile('#tileSelector', 2);

refresh()

Refreshes the visual state of the masonryLayout. JET elements require a refresh() after the DOM is programmatically changed underneath the element.

This method does not accept any arguments.

Example

Invoke the refresh method:

myMasonryLayout.refresh();

removeTile(selector)

Remove a tile from the masonryLayout.
Parameters:
Name Type Description
selector string Selector identifying the tile to remove.
Example

Invoke the removeTile method:

myMasonryLayout.removeTile('#tileSelector');

resizeTile(selector, sizeStyleClass)

Resize a tile in the masonryLayout.
Parameters:
Name Type Description
selector string Selector identifying the tile to resize.
sizeStyleClass string New size style class to apply to the tile.
Example

Invoke the resizeTile method:

myMasonryLayout.resizeTile('#tileSelector', 'oj-masonrylayout-tile-2x1');

setProperties(properties)

Performs a batch set of properties.
Parameters:
Name Type Description
properties Object An object containing the property and value pairs to set.
Example

Set a batch of properties:

myComponent.setProperties({"prop1": "value1", "prop2.subprop": "value2", "prop3": "value3"});

setProperty(property, value)

Sets a property or a single subproperty for complex properties and notifies the component of the change, triggering a [property]Changed event.
Parameters:
Name Type Description
property string The property name to set. Supports dot notation for subproperty access.
value * The new value to set the property to.
Example

Set a single subproperty of a complex property:

myComponent.setProperty('complexProperty.subProperty1.subProperty2', "someValue");