Skip to content

Commit bf28930

Browse files
committed
Add documentation for new API.create features.
1 parent 7551d3a commit bf28930

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

source/includes/_locations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ See the <a href="#ddc-api-insert-key-name-callback-elem-meta">insert documentati
2727
API.insert('vehicle-media', function(elem, meta) {
2828
var button = API.create('button', {
2929
text: 'Watch Video',
30-
src: 'https://www.providerdomain.com/path/video-player.html?vin=' + meta.vin,
30+
href: 'https://www.providerdomain.com/path/video-player.html?vin=' + meta.vin,
3131
classes: 'btn btn-primary dialog',
3232
style: 'margin-top: 12px;',
3333
attributes: {
@@ -114,7 +114,7 @@ This element is positioned below the vehicle tech specs area on vehicle search a
114114
var highPrice = Math.round(meta.finalPrice + 1000);
115115
var button = API.create('button', {
116116
text: 'Search This Price Range',
117-
src: '/' + meta.inventoryType + '-inventory/index.htm?internetPrice=' + lowPrice.toString() + '-' + highPrice.toString(),
117+
href: '/' + meta.inventoryType + '-inventory/index.htm?internetPrice=' + lowPrice.toString() + '-' + highPrice.toString(),
118118
classes: 'btn btn-primary',
119119
style: 'margin-top: 12px;'
120120
})

source/includes/_methods.md

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,30 +286,71 @@ Field Name | Purpose | Field Format
286286
`callback(elem, meta)` | The DOM element where the markup should be inserted, and the payload object for the current insertion point. | Element, Object
287287

288288

289-
## API.create(type, data)
289+
## API.create(type, options)
290290

291291
> Create a Button
292292
293293
```javascript
294294
(function(WIAPI) {
295295
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
296296
var button = API.create('button', {
297-
text: 'Visit Google',
298-
src: 'https://www.google.com/',
297+
href: 'https://www.google.com/',
298+
text: {
299+
'en_US': 'Visit Google', // English
300+
'fr_CA': 'Visitez Google', // French
301+
'es_MX': 'Visite Google' // Spanish
302+
},
299303
classes: 'btn btn-primary',
300304
style: 'border: 2px solid #c00',
301305
attributes: {
306+
'data-custom-attribute': 'attribute-value',
302307
'target': '_blank'
308+
},
309+
imgSrc: 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png',
310+
imgAlt: {
311+
'en_US': 'Visit Google', // English
312+
'fr_CA': 'Visitez Google', // French
313+
'es_MX': 'Visite Google' // Spanish
314+
},
315+
imgClasses: 'custom-image-class another-class',
316+
imgAttributes: {
317+
'data-image-attribute': 'image-attribute-value'
318+
},
319+
onclick: function() {
320+
window.MyIntegration.activateModalOverlay();
303321
}
304322
});
305-
API.log(button);
306-
// The above outputs: <a href="https://www.google.com/" class="btn btn-primary" style="border: 2px solid rgb(204, 0, 0);" target="_blank">Visit Google</a>
323+
return button;
307324
})(window.DDC.API);
308325
```
309326

327+
> The above example generates this markup:
328+
329+
```html
330+
<a href="https://www.google.com/" class="btn btn-primary mb-3" data-custom-attribute="attribute-value" target="_blank" style="border: 2px solid rgb(204, 0, 0);">
331+
<img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" alt="Visit Google" class="custom-image-class another-class" data-image-attribute="image-attribute-value">
332+
</a>
333+
```
334+
310335
The create method can be used to generate markup which adheres to our standard practices. This allows you to simply "create a button", for example, without having to know the inner workings of how buttons should be created on different types of sites.
311336

312-
Currently only the "button" type is supported, however other types will soon be added. Please let us know if there are particular types of elements you want to create so we can work to incorporate your feedback into this API.
337+
Currently only the "button" type is supported, however other types may be added in the future. Please let us know if there are particular types of elements you want to create so we can work to incorporate your feedback into this API.
338+
339+
The available options for the `button` type are as follows:
340+
341+
Field Key | Example Value | Field Format | Purpose
342+
-------------- | -------------- | -------------- | --------------
343+
`href` | `https://www.google.com/` | `String` | The link URL.
344+
`text` | `See functional example.` | `Object` | The localized button text object.
345+
`classes` | `btn btn-primary` | `String` | Classes to place on the link element.
346+
`style` | `border: 2px solid #c00` | `String` | Inline styles to place on the link element.
347+
`attributes` | `See functional example.` | `Object` | An object of key/value pairs to add to the link element as attributes.
348+
`imgSrc` | `https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png` | `String` | The URL to the button image.
349+
`imgAlt` | `See functional example.` | `Object` | The localized image alt text object.
350+
`imgClasses` | `custom-image-class another-class` | `String` | Classes to place on the image.
351+
`imgAttributes` | `See functional example.` | `Object` | An object of key/value pairs to add to the image element as attributes.
352+
`onclick` | `See functional example.` | `Function` | The onclick handler to attach to the button.
353+
313354

314355
## API.append(targetEl, appendEl)
315356

@@ -332,7 +373,7 @@ Currently only the "button" type is supported, however other types will soon be
332373
var highPrice = Math.round(meta.finalPrice + 1000);
333374
var button = API.create('button', {
334375
text: 'Search This Price Range',
335-
src: '/new-inventory/index.htm?internetPrice=' + lowPrice.toString() + '-' + highPrice.toString(),
376+
href: '/new-inventory/index.htm?internetPrice=' + lowPrice.toString() + '-' + highPrice.toString(),
336377
classes: 'btn btn-primary',
337378
style: 'margin-top: 12px;',
338379
attributes: {

0 commit comments

Comments
 (0)