56
56
self . _introItems = introItems ;
57
57
58
58
//add overlay layer to the page
59
- if ( _addOverlayLayer ( targetElm ) ) {
59
+ if ( _addOverlayLayer . call ( self , targetElm ) ) {
60
60
//then, start the show
61
61
_nextStep . call ( self ) ;
62
62
66
66
targetElm . onkeydown = function ( e ) {
67
67
if ( e . keyCode == 27 ) {
68
68
//escape key pressed, exit the intro
69
- _exitIntro ( targetElm ) ;
69
+ _exitIntro . call ( self , targetElm ) ;
70
70
}
71
71
if ( [ 37 , 39 ] . indexOf ( e . keyCode ) >= 0 ) {
72
72
if ( e . keyCode == 37 ) {
96
96
}
97
97
if ( ( this . _introItems . length ) <= this . _currentStep ) {
98
98
//end of the intro
99
- _exitIntro ( this . _targetElement ) ;
99
+ //check if any callback is defined
100
+ if ( this . _introCompleteCallback != undefined ) {
101
+ this . _introCompleteCallback . call ( this ) ;
102
+ }
103
+ _exitIntro . call ( this , this . _targetElement ) ;
100
104
return ;
101
105
}
102
106
_showElement . call ( this , this . _introItems [ this . _currentStep ] . element ) ;
139
143
showElement . className = showElement . className . replace ( / i n t r o j s - s h o w E l e m e n t / , '' ) . trim ( ) ;
140
144
//clean listeners
141
145
targetElement . onkeydown = null ;
146
+ //check if any callback is defined
147
+ if ( this . _introExitCallback != undefined ) {
148
+ this . _introExitCallback . call ( this ) ;
149
+ }
142
150
}
143
151
144
152
/**
218
226
nextTooltipButton . innerHTML = "Next →" ;
219
227
220
228
skipTooltipButton . onclick = function ( ) {
221
- _exitIntro ( self . _targetElement ) ;
229
+ _exitIntro . call ( self , self . _targetElement ) ;
222
230
} ;
223
231
224
232
var tooltipButtonsLayer = tooltipLayer . querySelector ( '.introjs-tooltipbuttons' ) ;
247
255
*/
248
256
function _addOverlayLayer ( targetElm ) {
249
257
var overlayLayer = document . createElement ( "div" ) ,
250
- styleText = "" ;
258
+ styleText = "" ,
259
+ self = this ;
260
+
251
261
//set css class name
252
262
overlayLayer . className = "introjs-overlay" ;
253
263
261
271
targetElm . appendChild ( overlayLayer ) ;
262
272
263
273
overlayLayer . onclick = function ( ) {
264
- _exitIntro ( targetElm ) ;
274
+ _exitIntro . call ( self , targetElm ) ;
265
275
} ;
266
-
276
+
267
277
setTimeout ( function ( ) {
268
278
styleText += "opacity: .5;" ;
269
279
overlayLayer . setAttribute ( "style" , styleText ) ;
338
348
return IntroJs ( this ) ;
339
349
} ,
340
350
start : function ( ) {
341
- return _introForElement . call ( this , this . _targetElement ) ;
351
+ _introForElement . call ( this , this . _targetElement ) ;
352
+ return this ;
353
+ } ,
354
+ oncomplete : function ( providedCallback ) {
355
+ if ( typeof ( providedCallback ) === "function" ) {
356
+ this . _introCompleteCallback = providedCallback ;
357
+ } else {
358
+ throw new Error ( "Provided callback for oncomplete was not a function." ) ;
359
+ }
360
+ return this ;
361
+ } ,
362
+ onexit : function ( providedCallback ) {
363
+ if ( typeof ( providedCallback ) === "function" ) {
364
+ this . _introExitCallback = providedCallback ;
365
+ } else {
366
+ throw new Error ( "Provided callback for onexit was not a function." ) ;
367
+ }
368
+ return this ;
342
369
}
343
370
} ;
344
371
345
372
this [ 'introJs' ] = introJs ;
346
- } ) ( ) ;
373
+ } ) ( ) ;
0 commit comments