Skip to content

Commit 270881d

Browse files
committed
Code refactor + fix oncomplete Callback problem when clicking on Done button
1 parent e2e3502 commit 270881d

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

intro.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,28 @@
5050
* @returns {Boolean} Success or not?
5151
*/
5252
function _introForElement(targetElm) {
53-
var allIntroSteps = targetElm.querySelectorAll('*[data-intro]'),
54-
introItems = [],
53+
var introItems = [],
5554
self = this;
5655

57-
if(this._options.steps) {
58-
// use steps passed programmatically
59-
allIntroSteps = [];
60-
61-
for(var i = 0; i < this._options.steps.length; i++){
62-
this._options.steps[i].step = i+1; //set the step
63-
introItems.push(this._options.steps[i]);
56+
if (this._options.steps) {
57+
//use steps passed programmatically
58+
var allIntroSteps = [];
59+
60+
for (var i = 0, stepsLength = this._options.steps.length; i < stepsLength; i++) {
61+
var currentItem = this._options.steps[i];
62+
//set the step
63+
currentItem.step = i + 1;
64+
//grab the element with given selector from the page
65+
currentItem.element = document.querySelector(currentItem.element);
66+
introItems.push(currentItem);
6467
}
6568

6669
} else {
67-
// use steps from data-* annotations
70+
//use steps from data-* annotations
6871

72+
var allIntroSteps = targetElm.querySelectorAll('*[data-intro]');
6973
//if there's no element to intro
70-
if(allIntroSteps.length < 1) {
74+
if (allIntroSteps.length < 1) {
7175
return false;
7276
}
7377

@@ -424,6 +428,9 @@
424428
skipTooltipButton.innerHTML = this._options.skipLabel;
425429

426430
skipTooltipButton.onclick = function() {
431+
if (self._introItems.length - 1 == self._currentStep && typeof (self._introCompleteCallback) === 'function') {
432+
self._introCompleteCallback.call(self);
433+
}
427434
_exitIntro.call(self, self._targetElement);
428435
};
429436

0 commit comments

Comments
 (0)