Skip to content

Commit 39e49d6

Browse files
authored
Merge pull request usablica#665 from Stellenticket/goToDataStep
Add new function `goToStepNumber`
2 parents 25e88b0 + b546c8b commit 39e49d6

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
@@ -301,6 +301,19 @@
301301
}
302302
}
303303

304+
/**
305+
* Go to the specific step of introduction with the explicit [data-step] number
306+
*
307+
* @api private
308+
* @method _goToStepNumber
309+
*/
310+
function _goToStepNumber(step) {
311+
this._currentStepNumber = step;
312+
if (typeof (this._introItems) !== 'undefined') {
313+
_nextStep.call(this);
314+
}
315+
}
316+
304317
/**
305318
* Go to next step on intro
306319
*
@@ -310,6 +323,16 @@
310323
function _nextStep() {
311324
this._direction = 'forward';
312325

326+
if (typeof (this._currentStepNumber) !== 'undefined') {
327+
for( var i = 0, len = this._introItems.length; i < len; i++ ) {
328+
var item = this._introItems[i];
329+
if( item.step === this._currentStepNumber ) {
330+
this._currentStep = i - 1;
331+
this._currentStepNumber = undefined;
332+
}
333+
}
334+
}
335+
313336
if (typeof (this._currentStep) === 'undefined') {
314337
this._currentStep = 0;
315338
} else {
@@ -1784,6 +1807,11 @@
17841807

17851808
return this;
17861809
},
1810+
goToStepNumber: function(step) {
1811+
_goToStepNumber.call(this, step);
1812+
1813+
return this;
1814+
},
17871815
nextStep: function() {
17881816
_nextStep.call(this);
17891817
return this;

0 commit comments

Comments
 (0)