Skip to content

Commit dea0ee9

Browse files
committed
Add documentation for a few new features.
1 parent d11b526 commit dea0ee9

File tree

5 files changed

+352
-22
lines changed

5 files changed

+352
-22
lines changed

source/includes/_internal.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,88 @@
1-
# DDC Specific Documentation
1+
# DDC Specific / Internal Documentation
2+
3+
## API.insertMenuContent(target, arrayOfObjects)
4+
5+
> Usage
6+
7+
```javascript
8+
(async APILoader => {
9+
const API = await APILoader.create();
10+
11+
API.insertMenuContent('primary-menu', [{
12+
position: 'top',
13+
primaryText: 'Some User',
14+
secondaryText: '[email protected]',
15+
href: '#',
16+
expanded: true,
17+
menuIcon: true,
18+
subItems: [
19+
{
20+
text: 'Profile',
21+
href: 'https://www.domain.com/profile/',
22+
onclick: (e) => {
23+
e.preventDefault();
24+
alert('Would have gone to the Profile linked in `href`, but preventDefault stopped it.');
25+
}
26+
},
27+
{
28+
text: 'Shopping Cart (1)',
29+
href: 'https://www.domain.com/cart/'
30+
},
31+
{
32+
text: 'Orders (0)',
33+
href: 'https://www.domain.com/orders/'
34+
},
35+
{
36+
text: 'Documents',
37+
href: 'https://www.domain.com/documents/'
38+
},
39+
],
40+
callback: (elem, meta, data) => {
41+
console.log(elem, meta, data);
42+
}
43+
},
44+
{
45+
position: 'bottom',
46+
primaryText: 'Sign Out',
47+
href: 'https://www.domain.com/logout/',
48+
onclick: (e) => {
49+
e.preventDefault();
50+
alert('Hello World!');
51+
},
52+
callback: (elem, meta, data) => {
53+
console.log(elem, meta, data);
54+
}
55+
}]);
56+
})(window.DDC.APILoader);
57+
```
58+
59+
The `insertMenuContent` method allows you to add custom items to the primary navigation menu of Dealer.com sites. You can specify where the items should appear, the primary and secondary text for each item, and any sub-items that should be displayed when the main item is expanded.
60+
61+
The `target` parameter specifies the navigation menu to target. The only currently supported value is 'primary-menu'.
62+
63+
The `arrayOfObjects` parameter is an array of objects describing the menu items to be inserted. Each object can include the following properties:
64+
65+
Property | Description
66+
-------------- | --------------
67+
`position` | The location where the item should be inserted in the menu. The supported values are `top` and `bottom`.
68+
`primaryText` | The main text for the menu item.
69+
`secondaryText` | Additional text that appears beneath the primary text in the menu item.
70+
`href` | The URL where the user should be directed when they click the menu item.
71+
`subItems` | An array of sub-menu items that appear when the main item is expanded. Each sub-item can include the `text` and `href` properties, as well as an `onclick` property specifying a function to be executed when the sub-item is clicked.
72+
`callback` | A function to be called after the menu item has been inserted. This function is passed three parameters: the newly-inserted HTML element (`elem`), the 'page event' object (`meta`), and the original data passed to the `insertMenuContent` function (`data`).
73+
`expanded` | A boolean value indicating whether the menu item should be expanded to show any sub-items when the page loads. The default value is `false`.
74+
`menuIcon` | A boolean value indicating whether an icon should be displayed next to the menu item. The default value is `false`.
75+
76+
The `callback` function you specify is called with three parameters:
77+
78+
Name | Description
79+
-------------- | --------------
80+
`elem` | `{HTMLElement}` The newly-inserted HTML element.
81+
`meta` | `{object}` The 'page event' object. For more information, see the [page event documentation](https://dealerdotcom.github.io/web-integration-api-docs/#page-event).
82+
`data` | `{object}` The original data you passed to the `insertMenuContent` function.
83+
84+
In addition to inserting static content, you can also add interactive functionality to the menu items by providing `onclick` functions. For example, you can prevent the default link behavior and display an alert message when a menu item is clicked, as demonstrated in the example code.
85+
286

387
## API.updateLink(intent, setupFunction(meta))
488
The `updateLink` method is used to override links on the page where the integration is enabled.

source/includes/_locations.md

Lines changed: 135 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ This element is positioned below the vehicle tech specs area on vehicle search a
9595
```javascript
9696
(async APILoader => {
9797
const API = await APILoader.create();
98-
API.insert('vehicle-payments', (elem, meta) => {
99-
// This element is positioned directly below the vehicle pricing area on vehicle search and detail pages.
100-
});
98+
99+
const callback = (elem, meta) => {
100+
// Insert your content here.
101+
}
102+
103+
API.insert('vehicle-payments-primary', callback);
104+
API.insert('vehicle-payments', callback);
101105
})(window.DDC.APILoader);
102106
```
103107

@@ -107,16 +111,31 @@ This element is positioned below the vehicle tech specs area on vehicle search a
107111
(async APILoader => {
108112
const API = await APILoader.create();
109113
API.subscribe('page-load-v1', ev => {
114+
115+
const { searchPage, detailPage } = ev.payload;
116+
117+
const callback = (elem, meta) => {
118+
const button = API.create('button', {
119+
text: 'Vehicle Payments',
120+
href: '#',
121+
classes: 'btn btn-primary'
122+
})
123+
API.append(elem, button);
124+
};
125+
110126
// Only execute the code on search results and vehicle details pages.
111-
if (ev.payload.searchPage || ev.payload.detailPage) {
112-
API.insert('vehicle-payments', (elem, meta) => {
113-
const button = API.create('button', {
114-
text: 'Vehicle Payments',
115-
href: '#',
116-
classes: 'btn btn-primary'
117-
})
118-
API.append(elem, button);
119-
});
127+
if (searchPage || detailPage) {
128+
129+
// This element exists only on the "Grid View" layout of the vehicle search page.
130+
// The content appears below the primary price of the vehicle and above the "Info", "Specials" and "Pricing" tabs.
131+
// Use this in addition to the `vehicle-payments` location if you want your content to be shown before the user clicks on the pricing tab.
132+
if (searchPage) {
133+
API.insert('vehicle-payments-primary', callback);
134+
}
135+
136+
// This element is positioned directly below the vehicle pricing area on vehicle search and detail pages.
137+
// On the "Grid View" layout of the vehicle search page, this content is placed inside the "Pricing" tab, below the vehicle price.
138+
API.insert('vehicle-payments', callback);
120139
}
121140
});
122141
})(window.DDC.APILoader);
@@ -164,6 +183,7 @@ This element is positioned directly below the vehicle pricing area on vehicle se
164183

165184
This element is positioned after the vehicle-payments insert location, and is placed below the pricing/incentives area on vehicle search and detail pages.
166185

186+
167187
## Vehicle Media Container
168188

169189
> Usage:
@@ -198,6 +218,98 @@ This element is positioned after the vehicle-payments insert location, and is pl
198218

199219
This element is the media gallery container on vehicle details pages. Injecting into this location will replace the media gallery with the elements you insert.
200220

221+
222+
## Listings Page Search Facets - Pricing Facet
223+
224+
> Usage:
225+
226+
```javascript
227+
(async APILoader => {
228+
const API = await APILoader.create();
229+
API.insert('search-facet-pricing', async (elem) => {
230+
const markup = document.createElement('div');
231+
markup.setAttribute('style', 'background: #f00;')
232+
markup.innerHTML = 'Your content goes here.';
233+
API.append(elem, markup);
234+
});
235+
})(window.DDC.APILoader);
236+
```
237+
238+
> Example Implementation:
239+
240+
```javascript
241+
(async APILoader => {
242+
const API = await APILoader.create();
243+
API.subscribe('page-load-v1', ev => {
244+
if (!ev.payload.searchPage) {
245+
return;
246+
}
247+
248+
API.insert('search-facet-pricing', async (elem) => {
249+
const markup = document.createElement('div');
250+
markup.setAttribute('style', 'background: #f00;')
251+
markup.innerHTML = 'Your content goes here.';
252+
API.append(elem, markup);
253+
});
254+
});
255+
})(window.DDC.APILoader);
256+
```
257+
258+
This element is positioned on the Search Results Page, within the Search Facets area. It is placed below the first (and typically only) Pricing related facet.
259+
260+
On the Details page, it is positioned at the top of the vehicle information, below the media gallery.
261+
262+
You can target either the listings or details page by first subscribing to the <a href="#page-load-v1">`page-load-v1`</a> event, then using the <a href="#page-event">event</a> values of `payload.searchPage` and `payload.detailPage` to check the page type.
263+
264+
265+
## Vehicle Banners
266+
267+
> Usage:
268+
269+
```javascript
270+
(async APILoader => {
271+
const API = await APILoader.create();
272+
API.insert('listings-placeholder-2', async (elem) => {
273+
const markup = document.createElement('div');
274+
markup.setAttribute('style', 'background: #f00;')
275+
markup.innerHTML = 'Your content goes here.';
276+
API.append(elem, markup);
277+
});
278+
})(window.DDC.APILoader);
279+
```
280+
281+
> Example Implementation:
282+
283+
```javascript
284+
(async APILoader => {
285+
const API = await APILoader.create();
286+
API.subscribe('page-load-v1', ev => {
287+
if (!ev.payload.searchPage) {
288+
return;
289+
}
290+
291+
API.insert('listings-placeholder-2', async (elem, meta) => {
292+
const markup = document.createElement('div');
293+
markup.setAttribute('style', 'background: #f00;')
294+
markup.innerHTML = 'Your device type is ' + meta.layoutType;
295+
API.append(elem, markup);
296+
});
297+
});
298+
})(window.DDC.APILoader);
299+
```
300+
301+
There are four "Listings Banners" locations on the Search Results Page, interspersed evenly between the vehicles displayed. These locations are useful for inserting relevant content that a user would expect to see in a list alongside vehicles.
302+
303+
As an example use case, `listings-placeholder-1` is used to place a widely adopted "My Wallet" integration on many websites. For this reason, it is preferable to use locations 2, 3 or 4 instead when possible.
304+
305+
Available Listings Placeholder location names:
306+
307+
- listings-placeholder-1
308+
- listings-placeholder-2
309+
- listings-placeholder-3
310+
- listings-placeholder-4
311+
312+
201313
## Primary Banner
202314

203315
> Usage:
@@ -262,22 +374,24 @@ You can target either the listings or details page by first subscribing to the <
262374
```javascript
263375
(async APILoader => {
264376
const API = await APILoader.create();
265-
API.subscribe('page-load-v1', ev => {
266-
if (ev.payload.detailPage) {
267-
API.insert('secondary-content', (elem, meta) => {
268-
const containerEl = document.createElement('div');
269-
containerEl.style = 'background-color: #ff0000; font-size: 30px; width: 100%; height: 540px; margin: 0 auto; padding: 100px; text-align: center;';
270-
containerEl.innerHTML = 'Your secondary content container goes here.';
271-
API.append(elem, containerEl);
272-
});
377+
API.subscribe('page-load-v1', (ev) => {
378+
if (!ev.payload.detailPage) {
379+
return;
273380
}
381+
382+
API.insert('secondary-content', (elem, meta) => {
383+
const containerEl = document.createElement('div');
384+
containerEl.style = 'background-color: #ff0000; font-size: 30px; width: 100%; height: 540px; margin: 0 auto; padding: 100px; text-align: center;';
385+
containerEl.innerHTML = 'Your secondary content container goes here.';
386+
API.append(elem, containerEl);
387+
});
274388
});
275389
})(window.DDC.APILoader);
276390
```
277391

278392
By default, this element is roughly 2/3 of the way down on vehicle details pages.
279393

280-
Since this may also be present on one or two standalone pages as custom additions, it is likely you will want to target just details pages by first subscribing to the <a href="#page-load-v1">`page-load-v1`</a> event, then using the <a href="#page-event">event</a> value of `payload.detailPage` to check the page type.
394+
Because this may also be present on one or two standalone pages as custom additions, it is likely you will want to exclusively target Vehicle Details pages by first subscribing to the <a href="#page-load-v1">`page-load-v1`</a> event, then using the <a href="#page-event">event</a> value of `payload.detailPage` to check the page type.
281395

282396
## Content
283397

source/includes/_methods.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,90 @@ Name | Description
295295
`vehicle` | `{object}` The Vehicle Object for the current vehicle, so you can use vehicle data when constructing your markup.
296296

297297

298+
## API.insertMenuContent(target, arrayOfObjects)
299+
300+
> Usage
301+
302+
```javascript
303+
(async APILoader => {
304+
const API = await APILoader.create();
305+
306+
API.insertMenuContent('primary-menu', [{
307+
position: 'top',
308+
primaryText: 'Some User',
309+
expanded: true,
310+
menuIcon: true,
311+
secondaryText: '[email protected]',
312+
href: '#',
313+
subItems: [
314+
{
315+
text: 'Profile',
316+
href: 'https://www.domain.com/profile/',
317+
onclick: (e) => {
318+
e.preventDefault();
319+
alert('Would have gone to the Profile linked in `href`, but preventDefault stopped it.');
320+
}
321+
},
322+
{
323+
text: 'Shopping Cart (1)',
324+
href: 'https://www.domain.com/cart/'
325+
},
326+
{
327+
text: 'Orders (0)',
328+
href: 'https://www.domain.com/orders/'
329+
},
330+
{
331+
text: 'Documents',
332+
href: 'https://www.domain.com/documents/'
333+
},
334+
],
335+
callback: (elem, meta, data) => {
336+
console.log(elem, meta, data);
337+
}
338+
},
339+
{
340+
position: 'bottom',
341+
primaryText: 'Sign Out',
342+
href: 'https://www.domain.com/logout/',
343+
onclick: (e) => {
344+
e.preventDefault();
345+
alert('Hello World!');
346+
},
347+
callback: (elem, meta, data) => {
348+
console.log(elem, meta, data);
349+
}
350+
}]);
351+
})(window.DDC.APILoader);
352+
```
353+
354+
The `insertMenuContent` method allows you to add custom items to the primary navigation menu of Dealer.com sites. You can specify where the items should appear, the primary and secondary text for each item, and any sub-items that should be displayed when the main item is expanded.
355+
356+
The `target` parameter specifies the navigation menu to target. The only currently supported value is 'primary-menu'.
357+
358+
The `arrayOfObjects` parameter is an array of objects describing the menu items to be inserted. Each object can include the following properties:
359+
360+
Property | Description
361+
-------------- | --------------
362+
`position` | The location where the item should be inserted in the menu. The supported values are `top` and `bottom`.
363+
`primaryText` | The main text for the menu item.
364+
`secondaryText` | Additional text that appears beneath the primary text in the menu item.
365+
`href` | The URL where the user should be directed when they click the menu item.
366+
`subItems` | An array of sub-menu items that appear when the main item is expanded. Each sub-item can include the `text` and `href` properties, as well as an `onclick` property specifying a function to be executed when the sub-item is clicked.
367+
`callback` | A function to be called after the menu item has been inserted. This function is passed three parameters: the newly-inserted HTML element (`elem`), the 'page event' object (`meta`), and the original data passed to the `insertMenuContent` function (`data`).
368+
`expanded` | A boolean value indicating whether the menu item should be expanded to show any sub-items when the page loads. The default value is `false`.
369+
`menuIcon` | A boolean value indicating whether an icon should be displayed next to the menu item. The default value is `false`.
370+
371+
The `callback` function you specify is called with three parameters:
372+
373+
Name | Description
374+
-------------- | --------------
375+
`elem` | `{HTMLElement}` The newly-inserted HTML element.
376+
`meta` | `{object}` The 'page event' object. For more information, see the [page event documentation](https://dealerdotcom.github.io/web-integration-api-docs/#page-event).
377+
`data` | `{object}` The original data you passed to the `insertMenuContent` function.
378+
379+
In addition to inserting static content, you can also add interactive functionality to the menu items by providing `onclick` functions. For example, you can prevent the default link behavior and display an alert message when a menu item is clicked, as demonstrated in the example code.
380+
381+
298382
## API.insert(name, callback(elem, meta))
299383

300384
> Usage

0 commit comments

Comments
 (0)