@@ -4,6 +4,7 @@ import GleapTours from "./GleapTours";
44export default class GleapProductTours {
55 productTourData = undefined ;
66 productTourId = undefined ;
7+ onCompletion = undefined ;
78
89 // GleapReplayRecorder singleton
910 static instance ;
@@ -18,9 +19,10 @@ export default class GleapProductTours {
1819
1920 constructor ( ) { }
2021
21- startWithConfig ( tourId , config ) {
22+ startWithConfig ( tourId , config , onCompletion ) {
2223 this . productTourId = tourId ;
2324 this . productTourData = config ;
25+ this . onCompletion = onCompletion ;
2426
2527 return this . start ( ) ;
2628 }
@@ -32,6 +34,7 @@ export default class GleapProductTours {
3234 }
3335
3436 const steps = config . steps ;
37+ const self = this ;
3538
3639 var driverSteps = [ ] ;
3740
@@ -71,7 +74,7 @@ export default class GleapProductTours {
7174 driverSteps . push ( driverStep ) ;
7275 }
7376
74- const driverObj = GleapTours ( {
77+ const gleapTourObj = GleapTours ( {
7578 showProgress : true ,
7679 steps : driverSteps ,
7780 allowClose : config . allowClose ,
@@ -81,25 +84,26 @@ export default class GleapProductTours {
8184 'next' ,
8285 'close'
8386 ] ,
87+ onDestroyStarted : ( ) => {
88+ if ( ! gleapTourObj . hasNextStep ( ) ) {
89+ gleapTourObj . destroy ( ) ;
90+
91+ if ( self . onCompletion ) {
92+ self . onCompletion ( {
93+ tourId : self . productTourId
94+ } ) ;
95+ }
96+ }
97+ } ,
8498 onPopoverRender : ( popoverElement ) => {
8599 // Fix for images and videos.
86100 if ( popoverElement ) {
87101 const mediaElements = document . querySelectorAll ( '.gleap-tour-popover-description img, .gleap-tour-popover-description video' ) ;
88102
89103 const performRequentialRefresh = ( ) => {
90- driverObj . refresh ( ) ;
91-
92- setTimeout ( ( ) => {
93- driverObj . refresh ( ) ;
94- } , 250 ) ;
95-
96- setTimeout ( ( ) => {
97- driverObj . refresh ( ) ;
98- } , 500 ) ;
99-
100104 setTimeout ( ( ) => {
101- driverObj . refresh ( ) ;
102- } , 1000 ) ;
105+ gleapTourObj . refresh ( ) ;
106+ } , 750 ) ;
103107 } ;
104108
105109 for ( let i = 0 ; i < mediaElements . length ; i ++ ) {
@@ -154,6 +158,6 @@ export default class GleapProductTours {
154158 }
155159 }
156160 } ) ;
157- driverObj . drive ( ) ;
161+ gleapTourObj . drive ( ) ;
158162 }
159163}
0 commit comments