Features module.
Classes
Members
Object
static data
All relevant data (added features, relevant shared options, loading-status of bundles).
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. |
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/") |
Class
static Feature
Feature class.
- See:
-
- module:base/features~Feature
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. |
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. |
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)
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. |
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. |
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
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 |
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. |
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 |
static loadExternals()
Load any external scripts that are needed by the currently loaded features.
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. |
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) |