Module

base/features

Features module.

View Source features.js, line 1

Classes

Feature

Members

Object

static data

All relevant data (added features, relevant shared options, loading-status of bundles).

View Source features.js, line 830

Object

static constant defaultDestroyOptions

Default destroy options.
Properties:
Name Type Default Description
justChildNodes Boolean false Set to true if you don't want to destroy the features of the container node.

View Source features.js, line 62

Object

static constant defaultInitOptions

Default initialization options.
Properties:
Name Type Default Description
justChildNodes Boolean false Set to true if you don't want to initialize the features of the container node.
lazy Boolean true Set to false if you don't want to initialize any features lazy
lazyBundles Object {} Add object with all the bundles
assetPath String null Add path to the feature-init files ("assets/")

View Source features.js, line 48

Class

static Feature

Feature class.
See:
  • module:base/features~Feature

View Source features.js, line 813

Object

static features

Features added to current site.

View Source features.js, line 836

Methods

static add(name, featureClass, options)

Add feature
Parameters:
Name Type Description
name String Name of the feature used by the `data-feature` attribute.
featureClass Feature Feature class to initiate.
options Object Any options to initialize the feature with.

View Source features.js, line 437

Example
// add feature `deathStar`
base.features.add('deathStar', DeathStar, { destroyAlderaan: true })

static destroy(containeropt, nameopt, optionsopt)

Destroy feature instances.
Parameters:
Name Type Attributes Default Description
container Node <optional>
document.body Container element Container element to filter where features should be destroyed.
name String <optional>
null Comma separated string with names of the features (used by the `data-feature` attribute) which should be initialized.
options Object <optional>
{} Further destroy options to overwrite the default ones.

View Source features.js, line 380

Examples
// destroy all feature instances
base.features.destroy()
// destroy `feature1` and `feature2` instances inside #wrapper
base.features.destroy(document.getElementById('wrapper'), 'feature1,feature2')

static getFeatures() → {Array|null}

Return array of all the data-feature identifiers found in the DOM (removes duplicates)

View Source features.js, line 495

Array of feature identifiers.
Array | null
Example
// get features
const featureList = base.features.getFeatures()

static getInstanceByNode(node, name) → {module:base/features~Feature|null}

Return initialized feature instance from given node and name.
Parameters:
Name Type Description
node Node Node to return the instance from.
name String Name used by `data-feature` attribute.

View Source features.js, line 478

Feature instance.
module:base/features~Feature | null
Example
// get feature instance
const deathStar = base.features.getInstancesByNode(document.getElementById('deathstar'), 'deathStar')
// do something with the feature
deathStar.destroy()

static getInstancesByNode(node) → {Object|null}

Return all initialized feature instances from given node.
Parameters:
Name Type Description
node Node Node to return the instances from.

View Source features.js, line 458

Feature instances indexed by name (used by `data-feature` attribute).
Object | null
Example
// get all the feature instances
const features = base.features.getInstancesByNode(document.getElementById('deathstar'))
// do something with one of the features
features.deathStar.destroy()

static getRelevantBundles()

Splits up bundles into thos with and without external dependencies, and only returns those with features on the current page

View Source features.js, line 155

static getSharedOption(nameopt) → {Any}

Return an entry from data.sharedOptions
Parameters:
Name Type Attributes Description
name String <optional>
String with name under which the option was saved

View Source features.js, line 94

Shared option
Any
Example
// get shared option
const deviceOption = base.features.getSharedOption('device')

static init(containeropt, nameopt, optionsopt) → {Array}

Initializes features.
Parameters:
Name Type Attributes Default Description
container Node <optional>
document.body Container element Container element to filter where features should be initialized.
name String <optional>
null Comma separated string with names of the features (used by the `data-feature` attribute) which should be initialized.
options Object <optional>
{} Further initialize options to overwrite the default ones.

View Source features.js, line 288

Initialized feature instances.
Array
Examples
// initialize all features
base.features.init()
// initialize `feature1` and `feature2` instances inside #wrapper
base.features.init(document.getElementById('wrapper'), 'feature1,feature2')

static lazyload(bundlesopt, assetPathopt)

Lazyloads features based on the bundles provided.
Parameters:
Name Type Attributes Default Description
bundles Object <optional>
{} Object containing all the feature-bundles
assetPath String <optional>
null

View Source features.js, line 108

static loadExternals()

Load any external scripts that are needed by the currently loaded features.

View Source features.js, line 199

static reinit(containeropt, nameopt)

Reinitializes features.
Parameters:
Name Type Attributes Default Description
container Node <optional>
document.body Container element to filter where features should be reinitialized.
name String <optional>
null Comma separated string with names of the features (used by the `data-feature` attribute) which should be reinitialized.

View Source features.js, line 262

static setSharedOption(nameopt, valueopt)

Save shared option to data.sharedOptions.
Parameters:
Name Type Attributes Description
name String <optional>
String with name under which the option will be saved
value Any <optional>
Value that the option controls (can be of any type)

View Source features.js, line 75