Static
getIf the element is already configured as a SameHeight widget, the widget instance is returned. Otherwise null.
Static
registerOptional
config: SameHeightConfigReadonly
destroyUndoes all modifications to the element and returns it to its original state.
You will need to recreate it if you want to enable its functionality again.
Readonly
disableDisables the functionality of the widget. What this means is specific to each widget.
Readonly
enableRe-enables the functionality of the widget. What this means is specific to each widget.
Readonly
getReturns the element passed to the widget constructor.
Readonly
getReturns a map of the elements used as the flex children with their type.
Readonly
getReturns the elements used as the flex children.
Readonly
isReturns true if the widget is destroyed.
Readonly
isReturns true if the widget is currently disabled.
Readonly
onThe given handler will be called when the widget is destroyed.
Readonly
onThe given handler will be called when the widget is disabled.
Readonly
onThe given handler will be called when the widget is enabled.
Readonly
toSwitches the flexbox to vertical (column) mode.
You can alternatively do this by setting the
data-lisn-orientation="vertical"
attribute on the element at any time.
You can do this for example as part of a trigger:
Readonly
toggleRe-enables the widget if disabled, otherwise disables it.
Readonly
toSwitches the flexbox back to horizontal (row) mode, which is the default.
You can alternatively do this by deleting the
data-lisn-orientation
attribute on the element, or setting it to
"horizontal"
at any time.
Configures the given element as a SameHeight widget.
The SameHeight widget sets up the given element as a flexbox and sets the flex basis of its components so that their heights are as close as possible to each other. It tracks their size (see SizeWatcher) and continually updates the basis as needed.
When calculating the best flex basis that would result in equal heights, SameHeight determines whether a flex child is mostly text or mostly images since the height of these scales in opposite manner with their width. Therefore, the components of the widget should contain either mostly text or mostly images.
The widget should have more than one item and the items must be immediate children of the container element.
SameHeight tries to automatically determine if an item is mostly text or mostly images based on the total display text content, but you can override this in two ways:
"text"
or"image"
data-lisn-same-height-item
attribute to"text"
or"image"
on the children. NOTE however that when auto-discovering the items (i.e. when you have not explicitly passed a list/map of items), if you set thedata-lisn-same-height-item
attribute on any child you must also add this attribute to all other children that are to be used by the widget. Other children (that don't have this attribute) will be ignored and assumed to be either zero-size or position absolute/fixed.IMPORTANT: You should not instantiate more than one SameHeight widget on a given element. Use SameHeight.get to get an existing instance if any. If there is already a widget instance, it will be destroyed!
IMPORTANT: The element you pass will be set to
display: flex
and its children will getbox-sizing: border-box
and continually updatedflex-basis
style. You can add additional CSS to the element or its children if you wish. For example you may wish to setflex-wrap: wrap
on the element and amin-width
on the children.To use with auto-widgets (HTML API) (see settings.autoWidgets), the following CSS classes or data attributes are recognized:
lisn-same-height
class ordata-lisn-same-height
attribute set on the container element that constitutes the widgetWhen using auto-widgets, the elements that will be used as items are discovered in the following way:
lisn-same-height-item
class ordata-lisn-same-height-item
attribute are taken.script
orstyle
elements are taken as the items.See below examples for what values you can use set for the data attribute in order to modify the configuration of the automatically created widget.
Example
This defines a simple SameHeight widget with one text and one image child.
Example
This defines a SameHeight widget with the flexbox children specified explicitly (and one ignored), as well as having all custom settings.