Skip to content

Commit b546c8b

Browse files
committed
Add new function goToStepNumber
This allows to go to a specific step with the specific `data-step` attribute. This differs from `goToStep` in the way that `data-step` does not have be continuous to pick the desired element. For example: ``` <div id="first" data-step='5'></div> <div id="second" data-step='9'></div> // to get #second one can do now: introJs().goToStepNumber(9); --> #second // or with goToStep: introJs().goToStep(2); --> #second ```
1 parent c47ea2e commit b546c8b

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Optionally, pass one parameter to `introJs` function to limit the presentation s
4141

4242
<p align="center"><img src="https://raw.githubusercontent.com/usablica/intro.js/gh-pages/img/introjs-demo.png"></p>
4343

44-
4544
## Documentation
4645

4746
Please visit [Documentation](http://introjs.com/docs).

docs/docs/intro/api.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,36 @@ introJs().goToStep(2).start(); //starts introduction from step 2
6767

6868
-----
6969

70+
###introJs.goToStepNumber(step)
71+
72+
Go to specific step of introduction with the concrete step.
73+
This differs from `goToStep` in the way that `data-step`
74+
does not have be continuous to pick the desired element.
75+
76+
**Available since**: v2.x
77+
78+
**Parameters:**
79+
80+
- step : Number
81+
82+
**Returns:**
83+
84+
- introJs object.
85+
86+
**Example:**
87+
88+
```html
89+
<div id="first" data-step='5'></div>
90+
<div id="second" data-step='9'></div>
91+
````
92+
93+
```javascript
94+
//start introduction from step with data-step='9'
95+
introJs().goToStepNumber(9).start();
96+
````
97+
98+
-----
99+
70100
##### introJs.addStep(options)
71101

72102
Add a new step to introJs.

intro.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,19 @@
307307
}
308308
}
309309

310+
/**
311+
* Go to the specific step of introduction with the explicit [data-step] number
312+
*
313+
* @api private
314+
* @method _goToStepNumber
315+
*/
316+
function _goToStepNumber(step) {
317+
this._currentStepNumber = step;
318+
if (typeof (this._introItems) !== 'undefined') {
319+
_nextStep.call(this);
320+
}
321+
}
322+
310323
/**
311324
* Go to next step on intro
312325
*
@@ -316,6 +329,16 @@
316329
function _nextStep() {
317330
this._direction = 'forward';
318331

332+
if (typeof (this._currentStepNumber) !== 'undefined') {
333+
for( var i = 0, len = this._introItems.length; i < len; i++ ) {
334+
var item = this._introItems[i];
335+
if( item.step === this._currentStepNumber ) {
336+
this._currentStep = i - 1;
337+
this._currentStepNumber = undefined;
338+
}
339+
}
340+
}
341+
319342
if (typeof (this._currentStep) === 'undefined') {
320343
this._currentStep = 0;
321344
} else {
@@ -1721,6 +1744,11 @@
17211744

17221745
return this;
17231746
},
1747+
goToStepNumber: function(step) {
1748+
_goToStepNumber.call(this, step);
1749+
1750+
return this;
1751+
},
17241752
nextStep: function() {
17251753
_nextStep.call(this);
17261754
return this;

0 commit comments

Comments
 (0)