forked from olton/Metro-UI-CSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metro-stepper.js
105 lines (81 loc) · 2.76 KB
/
metro-stepper.js
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
(function( $ ) {
$.widget("metro.stepper", {
version: "1.0.0",
options: {
steps: 3,
start: 1,
onStep: function(index, step){}
},
_create: function(){
var element = this.element, o = this.options;
if (element.data('steps') != undefined) o.steps = element.data('steps');
if (element.data('start') != undefined) o.start = element.data('start');
this._createStepper();
this._positioningSteps();
this._stepTo(o.start);
},
_createStepper: function(){
var element = this.element, o= this.options;
var i, ul, li;
ul = $("<ul/>");
for(i=0;i< o.steps;i++) {
li = $("<li/>").appendTo(ul);
}
ul.appendTo(element);
},
_positioningSteps: function(){
var that = this, element = this.element, o = this.options,
steps = element.find("li"),
element_width = element.width(),
steps_length = steps.length-1,
step_width = $(steps[0]).width();
$.each(steps, function(i, step){
var left = i == 0 ? 0 : (element_width - step_width)/steps_length * i;
$(step).animate({
left: left
});
});
},
_stepTo: function(step){
var element = this.element, o = this.options;
var steps = element.find("li");
steps.removeClass('current').removeClass('complete');
$.each(steps, function(i, s){
if (i < step - 1) $(s).addClass('complete');
if (i == step - 1) {
$(s).addClass('current') ;
o.onStep(i+1, s);
}
});
},
first: function(){
var o = this.options;
o.start = 1;
this._stepTo(o.start);
},
last: function(){
var element = this.element, o = this.options;
var steps = element.find("li");
o.start = steps.length;
this._stepTo(o.start);
},
next: function(){
var element = this.element, o = this.options;
var steps = element.find("li");
if (o.start + 1 > steps.length) return;
o.start++;
this._stepTo(o.start);
},
prior: function(){
var o = this.options;
if (o.start - 1 == 0) return;
o.start--;
this._stepTo(o.start);
},
_destroy: function(){
},
_setOption: function(key, value){
this._super('_setOption', key, value);
}
})
})( jQuery );