Origami Frontend Components & Services

JSDoc: o-layout

CharacterHighlight

Properties

  • 0 - (type: string) the character in the suggestion
  • 1 - (type: boolean) should it be highlighted?

Type

Array

Links

PopulateOptions(options)

parameter type default description
options Array.<*> The options which match the rext which was typed into the autocomplete by the user

Returns

  • void

Type

function

Links

Source(query, populateOptions)

parameter type default description
query string Text which was typed into the autocomplete by the user
populateOptions PopulateOptions Function to call when ready to update the suggestions dropdown

Returns

  • void

Type

function

Links

MapOptionToSuggestedValue(option)

parameter type default description
option * The option to transform into a suggestion string

Returns

  • string - The string to display as the suggestions for this option

Type

function

Links

onConfirm(option)

parameter type default description
option * The option the user selected

Returns

  • void

Type

function

Links

AutocompleteOptions

Properties

  • defaultValue - (type: string) Specify a string to prefill the autocomplete with
  • source - (type: Source) The function which retrieves the suggestions to display
  • mapOptionToSuggestedValue - (type: MapOptionToSuggestedValue) Function which transforms a suggestion before rendering
  • onConfirm - (type: onConfirm) Function which is called when the user selects an option

Type

object

Links

highlightSuggestion(suggestion, query)

Global Function

parameter type default description
suggestion string Text which is going to be suggested to the user
query string Text which was typed into the autocomplete by the user

Returns

  • Array.<CharacterHighlight> - An array of arrays which contain two items, the first is the character in the suggestion, the second is a boolean which indicates whether the character should be highlighted.

Links

createLoadingContainer

Global Function

Create DOM for the loading container.

Returns

  • HTMLDivElement - The loading container.

Links

showLoadingPane(instance)

Global Function

Show the loading panel

parameter type default description
instance Autocomplete The autocomplete instance whose loading panel should be shown

Returns

  • void

Links

hideLoadingPane(instance)

Global Function

Hide the loading panel

parameter type default description
instance Autocomplete The autocomplete instance whose loading panel should be hidden

Returns

  • void

Links

createClearButton(id)

Global Function

Create the DOM tree which corresponds to <button class="o-autocompleteclear" type="button" aria-controls=${autocompleteEl.id} title="Clear input"> <span class="o-autocompletevisually-hidden">Clear input</span> </button>

parameter type default description
id string The id of the autocomplete input to associate the clear button with

Returns

  • HTMLButtonElement - The clear button DOM tree

Links

initClearButton(instance)

Global Function

Attach the clear button and corresponding event listeners to the o-autocomplete instance

parameter type default description
instance Autocomplete The autocomplete instance to setup the clear button for

Returns

  • void

Links

new Autocomplete(autocompleteEl, options)

Class constructor.

parameter type default description
autocompleteEl (optional) HTMLElement The component element in the DOM
options (optional) AutocompleteOptions {} An options object for configuring the component

Methods

Properties

Links

new Drawer(headerEl)

Class constructor.

parameter type default description
headerEl (optional) HTMLElement The component element in the DOM

Methods

Properties

  • enabled - Check if the drawer is currently enabled. If the burger element is visible, the drawer is enabled.

Links

new HeaderServices(headerEl)

Class constructor

parameter type default description
headerEl (optional) HTMLElement The component element in the DOM

Methods

Links

new Layout(layoutEl, options)

Class constructor.

parameter type default description
layoutEl (optional) HTMLElement The layout element in the DOM
options (optional) object {} An options object for configuring aspects of the layout

Methods

  • constructNavFromDOM - (instance) Construct the sidebar navigation from headings within the DOM.
  • destroy - (instance) Unmount the sideBarNavigation.
  • highlightNavItems - (instance) Enables navigation item highlighting based on scroll position. Relies on heading ids and anchor href being the same.
  • getDataAttributes(layoutElement) - (static) Get the data attributes from the layoutEl. If the layout is being set up declaratively, this method is used to extract the data attributes from the DOM.
  • init(rootEl, opts) - (static) Initialise layout component.

Properties

Links

new LinkedHeading(...)

Represents a linked heading.

Class constructor.

parameter type default description
headingElement HTMLElement The heading element in the DOM
options (optional) object {} An options object for configuring the linked heading
options.content (optional) string "ΒΆ" The content to add to the created link
options.title (optional) string "Link directly to this section of the page" The title attribute to add to the created link

Links

new Scroll(headerEl)

Class constructor

parameter type default description
headerEl (optional) HTMLElement The component element in the DOM

Methods

Links

<anonymous>~customSource

Inner Property

Type

  • Source

Links

Autocomplete#mapOptionToSuggestedValue

Instance Property

Type

  • MapOptionToSuggestedValue

Links

Autocomplete#options.source(query, populateOptions)

Static Method

parameter type default description
query string Text which was typed into the autocomplete by the user
populateOptions PopulateOptions Function to call when ready to update the suggestions dropdown

Returns

  • void

Links

Autocomplete#options.source~callback(options)

Inner Function

parameter type default description
options Array.<string> The options which match the rext which was typed into the autocomplete by the user

Returns

  • void

Links

templates.suggestion(option)

Static Method

Used when rendering suggestions, the return value of this will be used as the innerHTML for a single suggestion.

parameter type default description
option * The suggestion to apply the template with.

Returns

  • string | undefined - HTML string to represent a single suggestion.

Links

templates.inputValue(option)

Static Method

Used when a suggestion is selected, the return value of this will be used as the value for the input element.

parameter type default description
option * The suggestion which was selected.

Returns

  • string | undefined - String to represent the suggestion.

Links

Autocomplete#suggestionTemplate(suggestedValue)

Instance Method

Used when rendering suggestions, the return value of this will be used as the innerHTML for a single suggestion.

parameter type default description
suggestedValue string The suggestion to apply the template with.

Returns

  • string - HTML string to be represent a single suggestion.

Links

<anonymous>~characters

Inner Property

Type

  • Array.<CharacterHighlight>

An array of arrays which contain two items, the first is the character in the suggestion, the second is a boolean which indicates whether the character should be highlighted.

Links

Autocomplete.getDataAttributes(autocompleteEl)

Static Method

Get the data attributes from the AutocompleteElement. If the element is being set up declaratively, this method is used to extract the data attributes from the DOM.

parameter type default description
autocompleteEl HTMLElement The component element in the DOM

Returns

  • object - An options object which can be used for configuring the component

Links

Autocomplete.init(rootElement, options)

Static Method

Initialise o-autocomplete component/s.

parameter type default description
rootElement HTMLElement | string The root element to intialise the component in, or a CSS selector for the root element
options (optional) object {} An options object for configuring the component

Returns

  • Autocomplete | Array.<Autocomplete> - The newly constructed Autocomplete components

Links

Banner#render

Instance Method

Render the banner.

Returns

  • void

Links

Banner#open

Instance Method

Open the banner.

Returns

  • void

Links

Banner#close

Instance Method

Close the banner.

Returns

  • void

Links

Banner#buildBannerElement(bannerElement)

Instance Method

Build a full banner element. This is used when no banner or a partial banner exists in the DOM.

parameter type default description
bannerElement (optional) HTMLElement The banner element to build around

Returns

  • HTMLElement - Returns the new banner element

Links

Banner#buildCloseButtonElement

Instance Method

Build a close button element.

Returns

  • HTMLElement - Returns the new close button element

Links

Banner.getOptionsFromDom(bannerElement)

Static Method

Get the data attributes from the bannerElement. If the banner is being set up declaratively, this method is used to extract the data attributes from the DOM.

parameter type default description
bannerElement HTMLElement The banner element in the DOM

Returns

  • Object.<string, any> - - The options

Links

Banner#destroy

Instance Method

Undo the init method

Links

Banner.init(rootElement, options)

Static Method

Initialise banner components.

parameter type default description
rootElement (optional) HTMLElement | string The root element to intialise banners in, or a CSS selector for the root element
options (optional) object {} An options object for configuring the banners

Returns

  • Banner | Array.<Banner> - - The newly instantiated Banner (or Banners, if rootElement was not a banner)

Links

Drawer#handleEvent(event)

Instance Method

Event Handler

parameter type default description
event object The event emitted by element/window interactions

Returns

  • void

Links

Drawer#enabled

Instance Property

Check if the drawer is currently enabled. If the burger element is visible, the drawer is enabled.

Links

Drawer#render

Instance Method

Drawer rendering

Returns

  • void

Links

Drawer#toggleDrawer

Instance Method

Drawer hide/show functionality

Returns

  • void

Links

HeaderServices.init(rootElement, options)

Static Method

Initialise header component

parameter type default description
rootElement HTMLElement | string The root element to intialise the component in, or a CSS selector for the root element
options (optional) object {} An options object for configuring the component

Returns

  • Array.<HTMLElement> | HTMLElement - - The header(s) initalised.

Links

Layout#navAnchors

Instance Property

Type

  • Array.<HTMLAnchorElement>

Links

Layout#constructNavFromDOM

Instance Method

Construct the sidebar navigation from headings within the DOM.

Links

Layout#navAnchors

Instance Property

Type

  • Array.<HTMLAnchorElement>

Links

Layout#destroy

Instance Method

Unmount the sideBarNavigation.

Links

Layout#highlightNavItems

Instance Method

Enables navigation item highlighting based on scroll position. Relies on heading ids and anchor href being the same.

Returns

  • void

Links

Layout.getDataAttributes(layoutElement)

Static Method

Get the data attributes from the layoutEl. If the layout is being set up declaratively, this method is used to extract the data attributes from the DOM.

parameter type default description
layoutElement HTMLElement The layout element in the DOM

Returns

  • Object.<string, any> - - Options for configuring the layout

Links

Layout.init(rootEl, opts)

Static Method

Initialise layout component.

parameter type default description
rootEl HTMLElement | string The root element to intialise the layout in, or a CSS selector for the root element
opts (optional) object {} An options object for configuring layout behaviour.

Returns

  • Layout | Array.<Layout> - Returns either a single Layout instance or an array of Layout instances

Links

Scroll#render

Instance Method

Scroll functionality rendering

Returns

  • void

Links

Scroll#toggleScrollButtons

Instance Method

Hide/show scroll buttons

Returns

  • void

Links

Scroll#scroll(event)

Instance Method

Scrolling functionality

parameter type default description
event object A scroll event

Returns

  • void

Links

Scroll#showCurrentSelection

Instance Method

Scroll secondary nav to 'current selection'

Returns

  • void

Links

new Layout(layoutEl, options)

Class constructor.

parameter type default description
layoutEl (optional) HTMLElement The layout element in the DOM
options (optional) object {} An options object for configuring aspects of the layout

Methods

  • constructNavFromDOM - (instance) Construct the sidebar navigation from headings within the DOM.
  • destroy - (instance) Unmount the sideBarNavigation.
  • highlightNavItems - (instance) Enables navigation item highlighting based on scroll position. Relies on heading ids and anchor href being the same.
  • getDataAttributes(layoutElement) - (static) Get the data attributes from the layoutEl. If the layout is being set up declaratively, this method is used to extract the data attributes from the DOM.
  • init(rootEl, opts) - (static) Initialise layout component.

Properties

Links

Status
active
Switch component view

GitHub: o-layout@5.3.2

Install o-layout

If using the Build Service, add o-layout@^5.3.2 to your script and link tags.

If using the npm package manager for a Manual Build, run npm install --save-peer "@financial-times/o-layout@^5.3.2".

Help & Support

o-layout is maintained directly by the Origami team. If you have any questions about o-layout or Origami in general, we are happy to help. 😊

Slack: #origami-support
Email: origami.support@ft.com

Feedback / Issues

To report a bug or request features please create an issue on Github. For support or general feedback please get in touch 😊

Slack: #origami-support
Email: origami.support@ft.com