API Docs for:
Show:

Modules.Accordion Class

Accordion module

Constructor

Modules.Accordion

()

Methods

$data

(
  • key
)
Any | Null

Takes a key and returns either the value of a matching data- attribute or null if no data- attribute is set. Works only on the $root element

Parameters:

  • key String

    Key of the data- attribute to get

Returns:

Any | Null:

The value or null

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        const urlVal = this.$data('url') || '/default/url';
    }
}

$findChilds

(
  • selector
)
JQuery

Takes a CSS style selector and returns all elements under the root node of the widget which match the selector as jQuery collection

Parameters:

  • selector String

    Selector to match elements against

Returns:

JQuery:

A jQuery collection of matched elements

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.$buttons = this.$findChilds('button');
    }
}

$findParent

(
  • [selector]
)
JQuery

Takes a CSS style selector and returns the closes parent element of the root element of the widget that matches the selector. If no selector is specified, returns the immediate parent element of the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

Returns:

JQuery:

A jQuery collection of matched elements

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.$rootContainer = this.$findParent('div');
    }
}

$raw

(
  • index
)
DOMNode

Takes an zero based index and returns the raw DOMNode from the underlying jQuery collection on the given index. If the index is higher than the length of the collection, returns the last element of the collection. If it is omitted, returns the first element of the collection. Works only on the $root element

Parameters:

  • index Integer | Any

    Index of the raw DOMNode you want to get

Returns:

DOMNode:

The node on the given position

Example:

import DOMModule from './modules/__base/dommodule';

let items = new DOMModule('li'); // get all <li> elements as $rootNode

items.$raw(); // -> first <li>, equivalent to items.$raw(0)
items.$raw(4); // -> fourth or last <li>, depending on number of elements

addObserver

(
  • x
  • [m = 'update']
)
This

Adds a observer object to the observable

Parameters:

  • x Object

    The object to register as observer

  • [m = 'update'] Function | String optional

    Function or method to use as handler

Returns:

This:

The observable instance

Example:

import Observable from './mixins/observable';

const logger = {
    update(message) {
        console.log(message);
    }
}

const MyClass = Observable(class {
    constructor() {
        this.addObserver(logger);
    }
});
import Observable from './mixins/observable';

const logger = {
    log(message) {
        console.log(message);
    }
}

const MyClass = Observable(class {
    constructor() {
        this.addObserver(logger, 'log');
    }
});

addState

(
  • state
)
This

Allows to add a new state (see example for more info)

Parameters:

  • state Object

    The new state

Returns:

This:

The instance

Example:

import FSM from './mixins/fsm';

const MyClass = FSM(class {
    constructor() {
        // New states MyClass can be in are added
        this.addState({
                name: 'init',
                events: {next: 'after'}
            }).
            addState({
                name: 'after',
                events: {next: 'last', prev: 'init'}
            }).
            addState({
                name: 'last',
                events: {prev: 'after'}
            });
    }
});

addStates

(
  • states
)
This

Allows to add an array of new states all at once

Parameters:

  • states Array

    The new states

Returns:

This:

The instance

Example:

import FSM from './mixins/fsm';

const MyStates = [
    {name: 'init', events: {next: 'after'}},
    {name: 'after', events: {next: 'last', prev: 'init'}},
    {name: 'last', events: {prev: 'after'}}
];

const MyClass = FSM(class {
    constructor() {
        // New states MyClass can be in are added
        this.addStates(MyStates);
    }
});

consume

(
  • eventName
)
This

Transitions from the current state to the state specified by the given name of event to consume.

Parameters:

  • eventName String

    Name of the event to consume

Returns:

This:

The instance

Example:

import FSM from './mixins/fsm';

const MyStates = [
    {name: 'init', events: {next: 'after'}},
    {name: 'after', events: {next: 'last', prev: 'init'}},
    {name: 'last', events: {prev: 'after'}}
];

const MyClass = FSM(class {
    constructor() {
        // New states MyClass can be in are added
        this.addStates(MyStates);
    }
});

let myInstance = new MyClass();
myInstance.getState(); // -> 'init'

myInstance.consume('next').consume('next').getState(); // -> 'last'

destroy

() Undefined

Destroys the instance, releases all attached eventlisteners and removes all observers and states. Also removes the associated HTMLElement from the DOM

Returns:

Undefined:

Nothing

destroyObservers

() Undefined

Destroys the observable, unregisters all observers

Returns:

Undefined:

Nothing

Example:

import Observable from './mixins/observable';

const logger = {
    update(message) {
        console.log(message);
    }
}

const MyClass = Observable(class {
    constructor() {
        this.addObserver(logger);
    }
});

let myInstance = new MyClass();
myInstance.notifyObservers('Sending a message');
// logs "Sending a message"

myInstance.destroyObservers();

myInstance.notifyObservers('Sending another message');
// nothing happens

destroyStates

() Undefined

Destroys all states associated with the FSM

Returns:

Undefined:

Nothing

Example:

import FSM from './mixins/fsm';

const MyStates = [
    {name: 'init', events: {next: 'after'}},
    {name: 'after', events: {next: 'last', prev: 'init'}},
    {name: 'last', events: {prev: 'after'}}
];

const MyClass = FSM(class {
    constructor() {
        // New states MyClass can be in are added
        this.addStates(MyStates);
    }
});

let myInstance = new MyClass();
myInstance.destroyStates();

findAll

(
  • selector
)
Array static

Finds and initializes all Accordions on a page at once

Parameters:

  • selector String

    CSS selector to match nodes against

Returns:

Array:

A list of instances

Example:

import Accordion from './modules/accordion/js/accordion';

Accordion.findAll('[data-widget=Accordion]');

getState

() String | Null

Returns the name of the current state or null if no state is set

Returns:

String | Null:

Name of the current state or null

Example:

import FSM from './mixins/fsm';

const MyStates = [
    {name: 'init', events: {next: 'after'}},
    {name: 'after', events: {next: 'last', prev: 'init'}},
    {name: 'last', events: {prev: 'after'}}
];

const MyClass = FSM(class {
    constructor() {
        // New states MyClass can be in are added
        this.addStates(MyStates);
    }
});

let myInstance = new MyClass();
myInstance.getState(); // -> 'init'

hasObserver

(
  • x
  • [m = 'update']
)
Boolean

Allows to test if a object is registered as a observer

Parameters:

  • x Object

    The object to check against

  • [m = 'update'] Function | String optional

    The function or method name to check

Returns:

Boolean:

True if registered, false if not

Example:

import Observable from './mixins/observable';

const logger = {
    log(message) {
        console.log(message);
    }
}

const MyClass = Observable(class {
    constructor() {
        this.addObserver(logger, 'log');
    }
});

let myInstance = new MyClass();
myInstance.hasObserver(logger, 'log');
// -> true

hide

() This

Closes the accordion if it is opened

Returns:

This:

The instance

Example:

import Accordion from './modules/accordion/js/accordion';

const myAccordion = Accordion.of('[data-widget=Accordion]');
myAccordion.render().startUp();

myAccordion.hide();

notifyObservers

(
  • x
  • [m = 'update']
)
This

Notifies all registered observers with data

Parameters:

  • x Object

    The object to register as observer

  • [m = 'update'] Function | String optional

    Function or method to use as handler

Returns:

This:

The observable instance

Example:

import Observable from './mixins/observable';

const logger = {
    update(message) {
        console.log(message);
    }
}

const MyClass = Observable(class {
    constructor() {
        this.addObserver(logger);
    }
});

let myInstance = new MyClass();
myInstance.notifyObservers('Sending a message');
// logs "Sending a message"  

of

(
  • node
)
Accordion static

Creates a new Accordion instance without the "new" keyword but does not initialize it

Parameters:

  • node Node | String | Configs

    Node, CSS selector or configuration object

Returns:

Accordion:

A new instance

Example:

import Accordion from './modules/accordion/js/accordion';

const myAccordion = Accordion.of('[data-widget=Accordion]');
myAccordion.render().startUp();

offBlur

(
  • [selector]
  • handler
)
This

Opposite of the onBlur method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offChange

(
  • [selector]
  • handler
)
This

Opposite of the onChange method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offClick

(
  • [selector]
  • handler
)
This

Opposite of the onClick method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offFocus

(
  • [selector]
  • handler
)
This

Opposite of the onFocus method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offInput

(
  • [selector]
  • handler
)
This

Opposite of the onInput method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offMove

(
  • [selector]
  • handler
)
This

Opposite of the onMove method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offPress

(
  • [selector]
  • handler
)
This

Opposite of the onPress method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offRelease

(
  • [selector]
  • handler
)
This

Opposite of the onRelease method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offResize

(
  • [selector]
  • fn
)
This

Opposite of the onResize method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • fn String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offSubmit

(
  • [selector]
  • handler
)
This

Opposite of the onSubmit method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

offTransitionEnd

(
  • [selector]
  • handler
)
This

Opposite of the onTransitionEnd method

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

onBlur

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when the blur event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onBlur('input[name=MyInput]', 'blurHandle');
    }
    blurHandle(event) {
        // ... your code ...
    }
}

onChange

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when the change event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onChange('button', 'changeHandle');
    }
    changeHandle(event) {
        // ... your code ...
    }
}

onClick

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when the click event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onClick('button', 'clickHandle');
    }
    clickHandle(event) {
        // ... your code ...
    }
}

onFocus

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when the focus event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onFocus('input[name=MyInput]', 'focusHandle');
    }
    focusHandle(event) {
        // ... your code ...
    }
}

onInput

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when either the keyup/input event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onInput('input[name=MyInput]', 'inputHandle');
    }
    inputHandle(event) {
        // ... your code ...
    }
}

onMove

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when either the mousemove/touchmove/pointermove event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onMove('.movearea', 'moveHandle');
    }
    moveHandle(event) {
        // ... your code ...
    }
}

onPress

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when either the mousedown/touchstart/pointerdown event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onPress('button', 'pressHandle');
    }
    pressHandle(event) {
        // ... your code ...
    }
}

onRelease

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when either the mouseup/touchend/pointerup event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onRelease('button', 'releaseHandle');
    }
    releaseHandle(event) {
        // ... your code ...
    }
}

onResize

(
  • fn
)
This

Takes function or methodname and registers the function or method as eventhandler on the window object.

Parameters:

  • fn String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onResize('resizeHandle');
    }
    resizeHandle(event) {
        // ... your code ...
    }
}

onSubmit

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when submit event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onSubmit('.my-form', 'submitHandler');
    }
    submitHandler(event) {
        // ... your code ...
    }
}

onTransitionEnd

(
  • [selector]
  • handler
)
This

Takes a CSS style selector and a function or methodname and registers the function or method as eventhandler for all child elements of the root element which match the selector when either the transitionend/webkitTransitionEnd/mozTransitionEnd/msTransitionEnd/ oTransitionEnd event occurs. If the selector is omitted and only a function/methodname is given, registers the handler on the root element.

Parameters:

  • [selector] String optional

    Selector to match elements against

  • handler String | Function

    Eventhandler function or method name

Returns:

This:

The instance

Example:

import DOMModule from './modules/__base/dommodule';

class MyClass extends DOMModule {
    render() {
        this.onTransitionEnd('.effectarea', 'transitionEndHandle');
    }
    transitionEndHandle(event) {
        // ... your code ...
    }
}

publish

(
  • channel
  • data
)
This

Allows to publish information through a channel of the mediator

Parameters:

  • channel String

    The channel to publish information through

  • data

    The data to send through

Returns:

This:

The instance

Example:

import Mediator from './mixins/mediator';

const MyClass = Mediator(class {
    constructor() {}
});

let myInstance = new MyClass();
myInstance.publish('channelName', 'foo');

removeObserver

(
  • x
  • [m = 'update']
)
This

Removes an observer object from the observable

Parameters:

  • x Object

    The object to remove

  • [m = 'update'] Function | String optional

    Function or method used as handler

Returns:

This:

The observable instance

Example:

import Observable from './mixins/observable';

const logger = {
    update(message) {
        console.log(message);
    }
}

const MyClass = Observable(class {
    constructor() {
        this.addObserver(logger);
    }
});

let myInstance = new MyClass();
myInstance.removeObserver(logger);

removeState

(
  • state
)
This

Removes a state from the FSM, if it is not the active one. Please note that you have to take care to preserve a valid path of events to consume, or otherwise the FSM will be trapped in a single state (which may be fine if that is your intention)

Parameters:

  • state Object

    The state to remove

Returns:

This:

The instance

Example:

import FSM from './mixins/fsm';

const MyStates = [
    {name: 'init', events: {next: 'after'}},
    {name: 'after', events: {next: 'last', prev: 'init'}},
    {name: 'last', events: {prev: 'after'}}
];

const MyClass = FSM(class {
    constructor() {
        // New states MyClass can be in are added
        this.addStates(MyStates);
        this.removeState(MyStates[2]); // remove the 'last' state
    }
});

render

() This

Renders missing nodes into the instance and returns it

Returns:

This:

The instance

Example:

import Accordion from './modules/accordion/js/accordion';

const myAccordion = Accordion.of('[data-widget=Accordion]');
myAccordion.render();

show

() This

Opens the accordion if it is closed

Returns:

This:

The instance

Example:

import Accordion from './modules/accordion/js/accordion';

const myAccordion = Accordion.of('[data-widget=Accordion]');
myAccordion.render().startUp();

myAccordion.show();

startUp

() Undefined

Attaches all eventlisteners to the accordion instance and opens it if the initial state is defined as visible

Returns:

Undefined:

Nothing

Example:

import Accordion from './modules/accordion/js/accordion';

const myAccordion = Accordion.of('[data-widget=Accordion]');
myAccordion.render().startUp();

subscribe

(
  • channel
  • handler
)
String

Allows to subscribe to a channel

Parameters:

  • channel String

    The channel to subscribe to

  • handler Function

    A handler function for incoming data

Returns:

String:

A subscription identifier

Example:

import Mediator from './mixins/mediator';

const Foo = Mediator(class {
    constructor() {
        this.subscribe('BarChannel', this.handleBar, this);
    }
    handleBar(data) {
        console.log('Foo received:', data);
    }
})

const Bar = Mediator(class {
    constructor() {
        this.subscribe('FooChannel', this.handleFoo, this);
    }
    handleFoo(data) {
        console.log('Bar received:', data);
    }
});

let foo = new Foo();
let bar = new Bar();

foo.publish('FooChannel', 'Info from Foo');
// logs "Bar received: Info from Foo"

bar.publish('BarChannel', 'Info from Bar');
// logs "Foo received: Info from Bar"

unsubscribe

(
  • identifier
)
Boolean

Allows to subscribe to a channel

Parameters:

  • identifier String

    A subscription ID returned from subscribe()

Returns:

Boolean:

True on success, false on failure

Example:

import Mediator from './mixins/mediator';

const Foo = Mediator(class {
    constructor() {
        this.listens = this.subscribe('self', this.handler, this);
    }
    handler(data) {
        console.log('Foo received:', data);
    }
    unlisten() {
        return this.unsubscribe(this.listens);
    }
})

let foo = new Foo();
foo.publish('self', 1);
// logs "Foo received: 1"

foo.unlisten()

foo.publish('self', 1);
// nothing happens