Skip to content

Commit d87dbce

Browse files
committed
v1.1.0
1 parent 8746d59 commit d87dbce

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tutorials/user_defined_templates/carousel.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Setting your instance in the handleCarouselTemplate method gives access to instance methods like doAutoScroll.
2+
let myInstance;
3+
14
/* eslint-disable header/header */
25
function MySimpleCarousel(event) {
36
this.event = event;
@@ -99,9 +102,10 @@ MySimpleCarousel.prototype.writeHTML = function() {
99102
'<div class="carousel_container_buttons"><button class="carousel_container_prev"><div class="carousel_container_icon"><img src="user_defined_templates/left.svg" alt="previous" /></div></button><button class="carousel_container_next"><div class="carousel_container_icon"><img src="user_defined_templates/right.svg" alt="next" /></div></button></div><ol class="carousel_container_content"></ol>';
100103
const content = element.querySelector('.carousel_container_content');
101104
const message = this.event.data.message;
105+
//Call doAutoScroll on image loads to move the carousel to the bottom of the web chat after they load.
102106
message.user_defined.slides.forEach(function(slide) {
103107
content.innerHTML +=
104-
'<li><div class="ibm-web-chat-card"><img class="carousel_slide_image" src="' +
108+
'<li><div class="ibm-web-chat-card"><img class="carousel_slide_image" onLoad="myInstance.doAutoScroll()" src="' +
105109
slide.image +
106110
'"/><div class="carousel_slide_title">' +
107111
slide.title +
@@ -121,7 +125,8 @@ MySimpleCarousel.prototype.writeHTML = function() {
121125
* @param event.data.element An HTML element that is rendered in Web Chat for you to manipulate. If you have set
122126
* user_defined.silent to true, no HTML element will be created.
123127
*/
124-
function handleCarouselTemplate(event) {
128+
function handleCarouselTemplate(event, instance) {
129+
myInstance = instance;
125130
const carousel = new MySimpleCarousel(event);
126131
carousel.start();
127132
}

0 commit comments

Comments
 (0)