Skip to content

Commit 1b1e240

Browse files
authored
Add documentation for HTML slides in galleries. (#26)
1 parent b1e9a1d commit 1b1e240

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added / Updated documentation for insertGalleryContent to include instructions on inserting HTML based slides to the gallery.
13+
1014
## [v2022-08-08T22.07.29] - 2022-08-08
1115

1216
## [v2022-08-08T20.41.26] - 2022-08-08

source/includes/_methods.md

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,29 @@ Field Name | Purpose | Field Format
167167
(async APILoader => {
168168
const API = await APILoader.create();
169169

170+
// Callback function to be called when your HTML slide is rendered.
171+
const myCallback = (data) => {
172+
// The `el` property is the top level HTML element where your content will be placed. You may modify this element or insert additional elements into it.
173+
const { el } = data;
174+
175+
// The height and width variables give you size information about the content placement location.
176+
const { width, height } = data;
177+
178+
el.style.height = height;
179+
el.style.width = width;
180+
181+
// The full Vehicle Object is available in the callback data.
182+
const { vehicle } = data;
183+
184+
// This destructures a few variables out of that vehicle object for later use.
185+
// The height and width variables give you size information about the content placement location.
186+
const { year, make, model, vin } = vehicle;
187+
188+
el.innerHTML = `<iframe style="height: ${height}px; width: 100%; border: 0;" frameborder="0" src="https://www.myintegration.com/framed-in-content/index.html?year=${vehicle.year}&make=${vehicle.make}&model=${vehicle.model}&vin=${vehicle.vin}" />`;
189+
}
190+
170191
// This informs your script when the displayed list of vehicles has changed, or when a Vehicle Details Page has loaded.
171192
API.subscribe('vehicle-data-updated-v1', async ev => {
172-
173193
// This obtains a list of VINs for the displayed vehicles.
174194
const vins = await API.utils.getAttributeForVehicles('vin');
175195

@@ -186,10 +206,10 @@ Field Name | Purpose | Field Format
186206
insertMethod: 'insert',
187207
images: [
188208
{
189-
type: 'image',
209+
type: 'html',
190210
position: 'primary',
191-
src: 'https://via.placeholder.com/530x360.png?text=Vehicle 1 Primary Image',
192-
thumbnail: 'https://via.placeholder.com/530x360.png?text=Vehicle 1 Primary Image',
211+
callback: myCallback,
212+
src: 'https://via.placeholder.com/530x360.png?text=Primary HTML Content Placeholder'
193213
},
194214
{
195215
type: 'image',
@@ -216,10 +236,10 @@ Field Name | Purpose | Field Format
216236
thumbnail: 'https://via.placeholder.com/530x360.png?text=Vehicle 2 Primary Image',
217237
},
218238
{
219-
type: 'image',
239+
type: 'html',
220240
position: 'secondary',
221-
src: 'https://via.placeholder.com/530x360.png?text=Vehicle 2 Secondary Image',
222-
thumbnail: 'https://via.placeholder.com/530x360.png?text=Vehicle 2 Secondary Image',
241+
callback: myCallback,
242+
src: 'https://via.placeholder.com/530x360.png?text=Secondary HTML Content Placeholder'
223243
},
224244
{
225245
type: 'image',
@@ -237,9 +257,9 @@ Field Name | Purpose | Field Format
237257
})(window.DDC.APILoader);
238258
```
239259

240-
The `insertGalleryContent` method allows you to add media to media galleries across various pages of Dealer.com sites. The only currently supported target is `vehicle-media`, which will insert media into the media carousels on Search Results Pages and Vehicle Details Pages.
260+
The `insertGalleryContent` method allows you to add media to galleries across various pages of Dealer.com sites. The only currently supported target is `vehicle-media`, which will insert media into the media carousels on Search Results Pages (Images only) and Vehicle Details Pages (Images and HTML slides).
241261

242-
`arrayOfObjects` is an array of objects describing the media to be inserted. Each object requires a `vin` field for the target vehicle, an `images` array with fields describing the images to insert for that vehicle as well as an optional `insertMethod`. The `type` field specifies the type of media to be inserted. The only currently supported media type is `image`. Utilizing `vehicle-data-updated-v1` to know when the list of vehicles changes combined with `API.utils.getAttributeForVehicles`, you can easily obtain a list of the VINs for vehicles shown on the page. With this data, you could query your service to get the dataset of imagery for those vehicles, then construct the array of objects for `API.insertGalleryContent`. See the example code for more details on this approach.
262+
`arrayOfObjects` is an array of objects describing the media to be inserted. Each object requires a `vin` field for the target vehicle, an `images` array with fields describing the images and other HTML content to insert for that vehicle as well as an optional `insertMethod`. The `type` field specifies the type of media to be inserted. The available options are `image` and `html`. Utilizing `vehicle-data-updated-v1` to know when the list of vehicles changes combined with `API.utils.getAttributeForVehicles`, you can easily obtain a list of the VINs for vehicles shown on the page. With this data, you could query your service to get the dataset of imagery and other content for those vehicles, then construct the array of objects for `API.insertGalleryContent`. See the example code for more details on this approach.
243263

244264
The `insertMethod` accepts the following string values:
245265

@@ -252,9 +272,33 @@ The `images` array objects support the following additional attributes:
252272

253273
Name | Description
254274
-------------- | --------------
275+
`type` | Expected values are `image` or `html`. The `html` and `callback` attributes are only used when type is set to `html`.
276+
`src` | HTTPS url to the image to be inserted.
255277
`position` | Where to insert the image. `primary` is used for content that should be displayed to the user as soon as it loads -- as long as the user has not explicitly performed an action to look at pre-existing media. `secondary` is used for content that should be displayed soon, but not replace the pre-existing main image. `last` is used to append content to the end of an existing gallery.
256278
`src` | HTTPS url to the image to be inserted.
257279
`thumbnail` | HTTPS url to a thumbnail of the image to be inserted. For performance, it is ideal to provide a low resolution thumbnail that can be used for a preview of the inserted image, however, `src` will be used if `thumbnail` is not provided.
280+
`html` | HTML markup to render when the user clicks on the placeholder image. This field is optional, as you can also use the `callback` function to create your markup.
281+
`callback` | A callback function to call when the user clicks on the placeholder image. This allows you to construct the HTML to display dynamically, with relevant data in context.
282+
283+
The `callback` function you specify is called with a single parameter, which is an object with the following structure:
284+
285+
/**
286+
* Initial HTML Element where your markup can be inserted. You can modify this element or insert other content inside of it.
287+
* @type {HTMLElement} el
288+
289+
* A unique ID for the location where your content will be inserted (either 'carousel' or 'photoswipe'). There are two insert locations on the Vehicle Details page. If your code requires a unique location on the page by ID (some video players may require this), you can add the `locationId` value to your target ID to make them unique.
290+
* @type {string} locationId
291+
292+
* The available width for your target location. This can be useful when constructing iframes to insert, etc.
293+
* @type {number} width
294+
295+
* The available height for your target location. This can be useful when constructing iframes to insert, etc.
296+
* @type {number} height
297+
298+
* The Vehicle Object for the current vehicle, so you can use vehicle data when constructing your markup.
299+
* @type {object} vehicle
300+
*/
301+
258302

259303
## API.insert(name, callback(elem, meta))
260304

0 commit comments

Comments
 (0)