-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabs.js
153 lines (119 loc) · 4.79 KB
/
tabs.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
SlideTabs = Class.create({
initialize: function(myid, scroller, countItems, wheelScroll) {
var elem = $(myid);
if (!elem) {
return;
}
var allSpans = $(myid).select('.slider-tabs .slider-tabs__header li span');
var allContents = $(myid).select('.slider-tabs__content');
if(allSpans.length >0){
allSpans[0].up('li').addClassName('over');
}
this.countItems = countItems;
this.wheelScroll = wheelScroll;
if(allContents.length>0){
allContents[0].addClassName('active');
new SlideTabsScroller(allContents[0], countItems, this.wheelScroll);
}
allSpans.each(function(el, i){
el.removeClassName('over');
el.tabIdentifier = i;
el.observe('click', this.showTab.bind(this));
}.bind(this));
},
showTab: function (event) {
var el = Event.element(event);
var content_array = el.up('.slider-tabs').select('.slider-tabs__content');
var tabs_array = el.up('li').up('ul').select('li');
content_array.each(function(el){
el.removeClassName('active');
});
tabs_array.each(function(el){
el.removeClassName('over');
});
content_array[el.tabIdentifier].addClassName('active');
el.up('li').addClassName('over');
new SlideTabsScroller(content_array[el.tabIdentifier], this.countItems, this.wheelScroll);
}
});
SlideTabsScroller = Class.create ({
initialize: function(content, countItems, wheelScroll) {
var width_slider = 0;
var width_feature = 0;
// Focus on the slide area
content.select('.slider-tabs__content__i').each(function(el, i){
// To get the array of feature-products
var array = el.select('.feature-products');
if (width_feature == 0) {
width_feature = array[0].getWidth("width");
}
// Calculate the sliders width;
width_slider = width_feature * array.length;
// Set the width of slide area
el.setStyle({
width: width_slider + 'px'
});
var scrollBarBg = el.up('.slider-tabs__content').select('.slider-tabs__scroller');
var scrollHandle = el.up('.slider-tabs__content').select('.slider-tabs__scroller__handle');
//$$('.slider-tabs__scroller').each(function(allSliderBase){allSliderBase.setStyle({display:'none'})});
//$$('.slider-tabs__scroller__handle').each(function(allSliderHandle){allSliderHandle.setStyle({display:'none'})});
if (array.length > countItems) {
scrollHandle.each(function(handle){
handle.setStyle({
display:'block'
});
});
scrollBarBg.each(function(base){
base.setStyle({
display:'block'
});
});
var moveDistance = width_slider-width_feature*countItems;
//alert(moveDistance);
var test = new Control.Slider(scrollHandle[0], scrollBarBg[0], {
sliderValue: 0,
range: $R(0, moveDistance),
onSlide: function(v) {
el.setStyle({
left: (1-v) + 'px'
});
},
onChange: function(v) {
el.setStyle({
left: (1-v) + 'px'
});
}
});
function handle(delta) {
test.setValueBy(-delta*30);
}
function wheel(event){
var delta = 0;
if (!event)
event = window.event;
if (event.wheelDelta) {
delta = event.wheelDelta/120;
if (window.opera)
delta = delta;
} else if (event.detail) {
delta = -event.detail/3;
}
if (delta)
handle(delta);
if (event.preventDefault)
event.preventDefault();
event.returnValue = false;
}
if (wheelScroll == true) {
Event.observe(content, 'DOMMouseScroll', wheel);
Event.observe(content, 'mousewheel', wheel);
}
}
});
}
});
document.observe("dom:loaded", function() {
$$(".cms-slider-tabs").each(function(el){
new SlideTabs(el, false, 0);
});
});