Configuration Overloads - AFS

AFS Integration Guide

Product
AFS
AFS_Version
7.9
Category
Reference Guide

Configuration modes can be mixed to offer more flexibility.

The widgets loader builds a widget configuration looking for:

  • a JavaScript definition for the widget type
  • a JavaScript definition for the widget ID
  • a JSON definition embedded in the widget

The configuration object used to initialize a widget is a merge of the three possible definitions.

Objects can be merged, but arrays cannot.

Hereafter is given an example of configuration overloading.

Considering these two widgets:

<div data-type="AFSWidget" data-name="Foobar" class="widget1"></div>
<div data-type="AFSWidget" data-name="Foobar" data-id="Foobar2" class="widget2">
<script type="application/json">
{
key2: 're-overloaded-value2',
key3: {
key8: 13
},
key9: '...'
}
</script>
</div>

In the JavaScript environment are defined the following configurations:

var AFSWidgetFoobar = {
key1: 'value1'
key2: 'value2',
key3: {
key4: 'value4'
key5: [1, 2, 3],
key6: 51
}
};

var AFSWidgetFoobar$$Foobar2 = {
key2: 'overloaded-value2',
key3: {
key4: 'overloaded-value4'
key5: [4, 5, 6],
key7: 42
}
};

The widget1 will be initialized with:

{
key1: 'value1'
key2: 'value2',
key3: {
key4: 'value4'
key5: [1, 2, 3],
key6: 51
}
}

whereas the widget2 will be initialized with:

{
key1: 'value1'
key2: 're-overloaded-value2',
key3: {
key4: 'overloaded-value4'
key5: [4, 5, 6],
key6: 51,
key7: 42,
key8: 13
},
key9: '...'
}