Ancillary is a layout script to move a set of "element" DOM nodes into a set of "container" DOM nodes based on a series of "setting" class names on the
<body> element that describe positioning. It finds out about which DOM nodes are elements and which are containers through the presence of the data-attributes
data-nc-container. Ancillary can be instantiated many times on one page.
Create an element to wrap all your Ancillary elements. This base element should have the data-attribute
data-nc-base, and the attribute value should reflect the string that comes after 'ancillary' in the body class names.
Create container elements inside your base, and give them the data-attribute
data-nc-container, with the value matching the string that comes after 'position' at the end of the body class names. NOTE: If a body class name refers to a container that is not present on the page as a
data-nc-container, the corresponding element will be removed from the DOM. This can be useful – for example, a body class name of
ancillary-header-logo-position-none will remove
<h1 data-nc-element="logo"> from the DOM entirely, as long as there is no
<div data-nc-container="none"> present in the DOM.
Lastly, create the actual Ancillary elements and assign them the data-attribute
data-nc-element, which should again match the strings that refer to the elements inside the body class names.
You've completed the process of creating your Ancillary layout. Feel free to put whatever you wish inside each
;const header = document;const headerAncillary = header;headerAncillary;
If you prefer to handle transpiling and polyfilling on your own, you can import ES6 from Ancillary:
Alternately, Ancillary specifies a
module property in
package.json that points to the uncompiled
src/index.js, so you may be able to simply import
@squarespace/ancillary if you're using one of the following bundlers: