-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjQuery.ElementStepper.js
123 lines (97 loc) · 3.79 KB
/
jQuery.ElementStepper.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
(function (jQuery) {
var sliding = false;
function eventbinder(options) {
var self = this;
jQuery(options.next).bind("click", function (e) {
if(!sliding) {
var prevnextreturn = options.onPrevNextEvent.call(self, true);
if(prevnextreturn == false) {
return false;
}
sliding = true;
var $curSlider = jQuery(self).find(".showedstep");
setTimeout(function () {
sliding = false;
}, options.duration);
$curSlider.hide({
duration : options.duration,
easing : options.easing || 'swing'
}).removeClass("showedstep");
var $nextslider;
var $childs = jQuery(jQuery(self).children(options.childElement));
if($curSlider.index() == $childs.length-1) $nextslider = $childs.first();
else $nextslider = $curSlider.next();
$nextslider.show({
duration : options.duration,
easing : options.easing || 'swing'
}).addClass("showedstep");
options.after.call($curSlider, jQuery(self).find(".showedstep"), options, true);
}
});
jQuery(options.prev).bind("click", function () {
if(!sliding) {
var prevnextreturn = options.onPrevNextEvent.call(self, false);
if(prevnextreturn == false) {
return false;
}
var $curSlider = jQuery(self).find(".showedstep");
setTimeout(function () {
sliding = false;
}, options.duration);
$curSlider.hide({
duration: options.duration,
easing: options.easing || 'swing'
}).removeClass("showedstep");
var $nextslider;
if($curSlider.index() == 0) {
$nextslider = jQuery(jQuery(self).children(options.childElement)).last();
}
else {
$nextslider = $curSlider.prev();
}
$nextslider.show({
duration: options.duration,
easing: options.easing || 'swing'
}).addClass("showedstep");
options.after.call($curSlider, jQuery(self).find(".showedstep"), options, false);
}
});
}
function stepper(options) {
jQuery(this).addClass("mentionStepper").css({
position : 'relative'
});
var $childs = jQuery(jQuery(this).children(options.childElement));
$childs.addClass("steps").css({
position : 'absolute'
});
if(typeof($childs.hide()[0]) !== "undefined") {
jQuery($childs.hide()[0]).show().addClass("showedstep");
}
}
jQuery.fn.elementStepper = function (opt, parameter) {
if (typeof(opt) === "string") return Query.fn.elementStepper.methods[opt](this, parameter);
return this.each(function () {
var options;
options = jQuery.extend(true, {}, jQuery.fn.elementStepper.options, jQuery.fn.elementStepper.methods, opt);
jQuery.data(this, 'options', {
options: options
});
stepper.call(this, options);
eventbinder.call(this, options);
});
};
jQuery.fn.elementStepper.methods = {
onPrevNextEvent : function (next) {
},
after : function () {
}
};
jQuery.fn.elementStepper.options = {
childElement : 'div',
prev: null,
next : null,
easing: 'swing',
duration : 500
};
})(jQuery);