Skip to content

Commit

Permalink
Added setStepIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanoya committed Sep 27, 2020
1 parent 70dd162 commit 4d0cd9f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ git clone http://github.com/oguzhanoya/jquery-steps.git
```
CDN
```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected].0/dist/jquery-steps.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected].0/dist/jquery-steps.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected].1/dist/jquery-steps.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected].1/dist/jquery-steps.min.js"></script>
```

## Setup
Expand Down Expand Up @@ -102,6 +102,7 @@ Init plugin with choosen options.
|finish|Trigger the onFinish event.|
|getStepIndex|Gets the current step index.(start from 0)|
|getMaxStepIndex|Gets the max step index.|
|setStepIndex|Sets the step index.|

## License

Expand Down
14 changes: 12 additions & 2 deletions dist/jquery-steps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jquery-steps.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/jquery-steps.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions examples/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<button id="btnGetStepIndex">Current Step Index</button>
<button id="btnGetMaxStepIndex">Max Step Index</button>
<hr>
<button id="btnGoToFirstStep">First Step</button>
<button id="btnGoToStep2">Go to Step 2</button>
<button id="btnGoToLastStep">Last Step</button>
<hr>
<button id="btnDestroy">Destroy</button>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
Expand All @@ -53,6 +57,7 @@
alert('Wizard Completed');
}
});

steps_api = steps.data('plugin_Steps');

$('#btnPrev').on('click', function () {
Expand All @@ -64,15 +69,28 @@
});

$('#btnGetStepIndex').on('click', function () {
const idx = steps_api.getStepIndex();
var idx = steps_api.getStepIndex();
alert(idx);
});

$('#btnGetMaxStepIndex').on('click', function () {
const idx = steps_api.getMaxStepIndex();
var idx = steps_api.getMaxStepIndex();
alert(idx);
});

$('#btnGoToFirstStep').on('click', function () {
steps_api.setStepIndex(0);
});

$('#btnGoToStep2').on('click', function () {
steps_api.setStepIndex(1);
});

$('#btnGoToLastStep').on('click', function () {
var maxIdx = steps_api.getMaxStepIndex();
steps_api.setStepIndex(maxIdx);
});

$('#btnDestroy').on('click', function () {
steps_api.destroy();
});
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery.steps",
"version": "1.1.0",
"version": "1.1.1",
"description": "A simple, lightweight jQuery step wizard plugin.",
"main": "./dist/jquery-steps.js",
"repository": {
Expand Down
8 changes: 8 additions & 0 deletions src/Steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ class Steps {
}
}

setStepIndex(idx) {
const maxIndex = this.getMaxStepIndex();
if (idx <= maxIndex) {
const stepIndex = this.getStepIndex();
this.setActiveStep(stepIndex, idx);
}
}

next() {
const stepIndex = this.getStepIndex();
const maxIndex = this.getMaxStepIndex();
Expand Down

0 comments on commit 4d0cd9f

Please sign in to comment.