Skip to content

Commit

Permalink
Fix get step index
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanoya committed Jun 20, 2021
1 parent 178613f commit 3705a4e
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 43 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[![npm](https://img.shields.io/npm/v/jquery.steps)](https://www.npmjs.com/package/jquery.steps)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![npm](https://img.shields.io/npm/dw/jquery.steps)](https://www.npmjs.com/package/jquery.steps)
[![npm](https://img.shields.io/npm/dm/jquery.steps)](https://www.npmjs.com/package/jquery.steps)
[![npm](https://img.shields.io/jsdelivr/npm/hm/jquery.steps)](https://www.npmjs.com/package/jquery.steps)

> A simple, lightweight jQuery step wizard plugin.
Expand All @@ -25,8 +26,8 @@ git clone http://github.com/oguzhanoya/jquery-steps.git
```
CDN
```html
<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>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected].2/dist/jquery-steps.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/jquery-steps.min.js"></script>
```

## Setup
Expand Down Expand Up @@ -63,7 +64,7 @@ Make necessary markup for wizard. That's all, you don't need to do anything else
```
Include plugin and dependeces. jQuery is the only dependency, make sure to include it.
```html
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="js/jquery-steps.js"></script>
```
Init plugin with choosen options.
Expand Down
6 changes: 3 additions & 3 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.

2 changes: 1 addition & 1 deletion examples/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<hr>
<button id="btnDestroy">Destroy</button>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="../dist/jquery-steps.js"></script>
<script>
var steps = $('#demo').steps({
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</div>
</div>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="../dist/jquery-steps.js"></script>
<script>
$('#demo').steps({
Expand Down
4 changes: 2 additions & 2 deletions examples/callbacks.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ <h3>Tab5</h3>
</div>
</div>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-[email protected]/dist/jquery.validate.min.js"></script>
<script src="../dist/jquery-steps.js"></script>
<script>
var frmInfo = $('#frmInfo');
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</div>
</div>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="../dist/jquery-steps.js"></script>
<script>
$('#demo1').steps({
Expand Down
2 changes: 1 addition & 1 deletion src/Steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Steps {
getStepIndex() {
const all = this.el.find(this.stepSelector);
const stepIndex = all.index(all.filter(`.${this.options.activeClass.split(' ').join('.')}`));
return stepIndex || 0;
return stepIndex;
}

getMaxStepIndex() {
Expand Down
49 changes: 24 additions & 25 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,37 @@
<meta charset="utf-8">
<title>Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="http://jasmine.github.io/images/jasmine.ico">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.99.2/jasmine.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.99.2/jasmine.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.99.2/jasmine-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.99.2/boot.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.7.1/jasmine.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.7.1/jasmine.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.7.1/jasmine-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.7.1/boot.min.js"></script>
</head>
<body>

<div class="step-app" id="demo" style="display: none;">
<ul class="step-steps">
<li data-step-target="step1">Step 1</li>
<li data-step-target="step2">Step 2</li>
<li data-step-target="step3">Step 3</li>
</ul>
<div class="step-content">
<div class="step-tab-panel" data-step="step1">
... step1
<script id="tpl-demo" type="text/html">
<div class="step-app" id="demo" style="display: none;">
<ul class="step-steps">
<% for(var i = 0; i < stepsCount; i++){ %>
<li data-step-target="step{{i}}">Step {{i}}</li>
<% } %>
</ul>
<div class="step-content">
<% for(var i = 0; i < stepsCount; i++){ %>
<div class="step-tab-panel" data-step="step{{i}}">
... step{{i}}
</div>
<% } %>
</div>
<div class="step-tab-panel" data-step="step2">
... step2
<div class="step-footer">
<button data-step-action="prev" class="step-btn">Previous</button>
<button data-step-action="next" class="step-btn">Next</button>
<button data-step-action="finish" class="step-btn">Finish</button>
</div>
<div class="step-tab-panel" data-step="step3">
... step3
</div>
</div>
<div class="step-footer">
<button data-step-action="prev" class="step-btn">Previous</button>
<button data-step-action="next" class="step-btn">Next</button>
<button data-step-action="finish" class="step-btn">Finish</button>
</div>
</div>
</script>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/template-web.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="../dist/jquery-steps.js"></script>
<script src="spec.js"></script>
</body>
Expand Down
34 changes: 32 additions & 2 deletions test/spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
describe('My Plugin', function () {
describe('jquery steps', function () {

var steps_api;
beforeEach(function () {
var data = {
stepsCount: 3,
};
var html = template('tpl-demo', data);
document.body.insertAdjacentHTML('afterbegin', html);
var steps = $('#demo').steps();
steps_api = steps.data('plugin_Steps');
});

afterEach(function () {
steps_api.destroy();
});

it('version', function () {
var ver = $.fn.steps.version;
expect(ver).toEqual('1.1.0');
expect(ver).toEqual('1.1.2');
});

it('next', function () {
steps_api.next();
steps_api.next();
var idx = steps_api.getStepIndex();
expect(idx).toEqual(2);
});

it('prev', function () {
steps_api.next();
steps_api.next();
steps_api.prev();
var idx = steps_api.getStepIndex();
expect(idx).toEqual(1);
});

});

0 comments on commit 3705a4e

Please sign in to comment.