-
Notifications
You must be signed in to change notification settings - Fork 25
/
async.html
executable file
·110 lines (95 loc) · 2.84 KB
/
async.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Async</title>
<link rel="stylesheet" href="../dist/jquery-steps.css">
<!-- Demo stylesheet -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="step-app" id="demo">
<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
</div>
<div class="step-tab-panel" data-step="step2">
... step2
</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>
<div class="loader">Loading...</div>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="../dist/jquery-steps.js"></script>
<script>
var loader = {
isLoading: false,
show: function() {
loader.isLoading = true;
$('.loader').show();
},
hide: function() {
loader.isLoading = false;
$('.loader').hide();
}
};
var xhr = null;
var isAllowChangeToNextStep = false;
var targetStepIndex = 1; // step2
var steps = $('#demo').steps({
onChange: function(currentIndex, newIndex, stepDirection) {
if (isAllowChangeToNextStep && !loader.isLoading) {
isAllowChangeToNextStep = false;
return true;
}
if (currentIndex === targetStepIndex) {
if (stepDirection === 'forward') {
if (!loader.isLoading) {
loader.show();
xhr = $.ajax({
url: 'https://jsonplaceholder.typicode.com/todos/4'
})
.done(function(response) {
loader.hide();
// success
if (response.completed) {
isAllowChangeToNextStep = true;
var stepIndex = steps_api.getStepIndex();
if (stepIndex === targetStepIndex) {
steps_api.next();
}
}
});
}
return false;
}
}
if (xhr) {
xhr.abort();
loader.hide();
}
return true;
},
onFinish: function() {
alert('Wizard Completed');
}
});
var steps_api = steps.data('plugin_Steps');
</script>
</body>
</html>