new EATAWidget(options)
Parameters:
Name | Type | Description |
---|---|---|
options |
module:types.WidgetParameters
|
Event parameters |
Examples
new EATAWidget({
event: 1,
session: 1,
});
new EATAWidget({
event: 1,
session: 1,
}).appendTo('#widget-container');
new EATAWidget({
event: 1,
session: 1,
}).replace('#widget-placeholder');
Members
(static) version
Returns current version
Example
EATAWidget.version; // "1.0.0"
Methods
(static) init() → {EATAWidget}
Alias to new EATAWidget
that does not require the new
operator.
- See:
Returns:
- Type:
-
EATAWidget
Example
EATAWidget.init({
event: 1,
session: 1,
});
(static) load(container, optionsopt) → {EATAWidget}
Bootstrap EATAWidget and append it to given container. The container can be either a CSS Selector or a DOM Node.
Widget properties can be set using the container's data-
attributes. Attributes should follow kebab-case
naming
convention.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
container |
String
|
Element
|
Container |
|
options |
module:types.WidgetParameters
|
<optional> |
Extra event parameters |
Returns:
- Type:
-
EATAWidget
Examples
<div
id="widget-container"
data-event="1"
data-session="1"
></div>
EATAWidget.load('#widget-container');
EATAWidget.load('#widget-container', {
event: 2,
foo: 'bar',
});
addEventListener(type, handler) → {EATAWidget}
Add event listener. Event data can be accesed through the detail
property of the returned event.
- See:
Parameters:
Name | Type | Description |
---|---|---|
type |
String
|
|
handler |
module:events.eventHandler
|
Returns:
- Type:
-
EATAWidget
Example
widget.addEventListener('order.created', function (e) {
var order = e.detail.order;
// ...
});
appendTo(selector) → {EATAWidget}
Append widget to given container.
- See:
Parameters:
Name | Type | Description |
---|---|---|
selector |
String
|
Element
|
Throws:
-
Widget has already been initialized.
- Type
-
Error
Returns:
- Type:
-
EATAWidget
destroy()
Remove any listener and destroy the instance.
ready(onFulfilled, onRejectedopt) → {Promise}
Returns a Promise
to check the readyness of the instance. If
successful, will return the instance as the first parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
onFulfilled |
function
|
||
onRejected |
function
|
<optional> |
Returns:
- Type:
-
Promise
Example
EATAWidget.load('...').ready(function (widget) {
console.log('Widget loaded:', widget);
});
reload() → {EATAWidget}
Return a new widget instance while keeping all its listeners.
Returns:
- Type:
-
EATAWidget
removeEventListener(type, handler) → {EATAWidget}
Remove event listener.
Parameters:
Name | Type | Description |
---|---|---|
type |
String
|
|
handler |
module:events.eventHandler
|
Returns:
- Type:
-
EATAWidget
Example
function handleOrderCreated(e) { }
widget.addEventListener('order.created', handleOrderCreated);
widget.removeEventListener('order.created', handleOrderCreated);
replace(selector) → {EATAWidget}
Replace target element with the widget.
- See:
Parameters:
Name | Type | Description |
---|---|---|
selector |
String
|
Element
|
Throws:
-
Widget has already been initialized.
- Type
-
Error
Returns:
- Type:
-
EATAWidget