# CMS layout ## Overview The CMS markup is structured into "panels", which are the base units containing interface components (or other panels), as declared by the class `cms-panel`. Panels can be made collapsible, and get the ability to be resized and aligned with a layout manager, in our case [jLayout](http://www.bramstein.com/projects/jlayout/). This layout manager applies CSS declarations (mostly dimensions and positioning) via JavaScript. We've established a convention for a `redraw` method on each panel and UI component that need to update their content as a result of changes to their position, size or visibility. This method would usually be invoked by the parent container. The layout manager does not dynamically track changes to panel sizes - we have to trigger laying out manually each time we need an update to happen (for example from `window::onresize` event, or panel toggling). It then cascades through the children setting sizes and positions, which in turn requires redrawing of some of the elements. The easiest way to update the layout of the CMS is to call `redraw` on the top-level `.cms-container` element. :::js $('.cms-container').redraw(); This causes the framework to: * reset the _threeColumnCompressor_ algorithm with the current layout options (that can be set via `updateLayoutOptions`) * trigger `layout` which cascades into all children resizing and positioning subordinate elements (this is internal to the layout manager) * trigger `redraw` on children which also cascades deeper into the hierarchy (this is framework activity) Caveat #1: `layout` is also triggered when a DOM element is replaced with AJAX in `LeftAndMain::handleAjaxResponse`. In this case it is triggered on the parent of the element being replaced so jLayout has a chance to rebuild its algorithms. Calling the top level `layout` is not enough as it will wrongly descend down the detached element's hierarchy. Caveat #2: invocation order of the `redraws` is crucial here, generally going from innermost to outermost elements. For example, the tab panels have be applied in the CMS form before the form itself is layouted with its sibling panels to avoid incorrect dimensions. ![Layout variations](_images/cms-architecture.png) ## Layout API ### redraw Define `redraw` methods on panels that need to adjust themselves after their sizes, positions or visibility have been changed. Call `redraw` on `.cms-container` to re-layout the CMS. ### data-layout-type attribute Layout manager will automatically apply algorithms to the children of `.cms-container` by inspecting the `data-layout-type` attribute. Let's take the content toolbar as an example of a second-level layout application: :::html