-
Notifications
You must be signed in to change notification settings - Fork 0
/
ras.js
237 lines (204 loc) · 7.59 KB
/
ras.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// jQuery Plugin ras - Responsive Accessible Slider
// version 2.0, Avril 30 2013
// by Thomas LEBEAU
;(function ( $, window, document, undefined ) {
$.ras = $.ras || {};
$.ras.slideshow = {
options : {
duration: 400,
textPrev:'prev',
textNext:'next'
}
}
// The actual plugin constructor
function PlugRAS(element, options ) {
this.element = element;
var self = this,
$element = $(self.element),
id = element.id,
classRas = element.className.split(' '),
classRas = classRas[0],
identiant;
(id ? identiant = id : identiant = classRas )
$element.wrap('<div class="allRas" id="AllRAS-'+identiant+'"/>')
self.init(options, identiant);
//Public functions
$.fn.ras.slide = function(el, direction, time){
self.slide(el, direction, time);
}
}
PlugRAS.prototype = {
init: function(options, id){
// if more than one items
var self = this,
$element = $(self.element),
childs = $element.children(),
navigation = '<div id="navRAS"><button class="btnSlideRAS prev">'+options.textPrev+'</button><button class="btnSlideRAS next">'+options.textNext+'</button></div>',
childLength = childs.length,
$elementParent = $element.parent();
$element.wrap('<div class="rasContainer" id="RASContainer-'+id+'" style="width:100%; overflow:hidden;"/>'),
$RASContainer = $element.parent();
if(childLength > 1){
// append navigation for Slide
$RASContainer.before(navigation);
var $navRAS = $RASContainer.prev('#navRAS'),
$RASSlideshow = $navRAS.next().children(),
elementRAS = $(self.element),
childs = elementRAS.children(),
RASparent = elementRAS.parent(),
WinWidth = $(window).width();
var docWidth = $elementParent.width(),
childsWidth = docWidth;
childs.css({
'float':'left',
'position':'relative',
'width':docWidth
}).each(function(e){
$(this).attr('data-slide',e);
});
//append Size element RAS
elementRAS.css({
'width':childsWidth*childLength
}).attr('data-width',childsWidth);
$('img').load(function(){
self.heightElement(childs, elementRAS);
elementRAS.css({
'width':docWidth*childLength
}).attr('data-width',docWidth);
childs.css({
'width':docWidth,
'position':'relative'
});
});
//Evenement navigation
$navRAS.find('.prev').bind('click', function(){
var time = options.duration,
anim = options.animation;
self.slide($RASSlideshow, 'prev', time, 'null');
});
$navRAS.find('.next').bind('click', function(){
var time = options.duration,
anim = options.animation;
self.slide($RASSlideshow, 'next', time, 'null');
});
//if User resize window
$(window).resize(function(){
var docWidth = RASparent.width();
self.resizeMe(elementRAS, docWidth, childLength);
});
}
},
// Slide Method
slide: function(el, direction, duration) {
var dataWidth = el.data('width'),
elWidth = el.width(),
firstSlide = el.children(':first'),
lastSlide = el.children(':last'),
navMultiple = $('#navMultiple');
function addClassNav() {
var navSelected = el.find('.activeSlide').data('slide');
navMultiple.find('.active').removeClass('active');
navMultiple.find('button:eq('+navSelected+')').addClass('active');
}
if(el.hasClass('navRas')) {
if(direction == 'prev') {
var prev = el.find('.activeSlide').prev(),
left = prev.data('left');
if(prev.length == 0) {
el.animate({
'margin-left':'-'+lastSlide.data('left')
}, function(){
el.find('.activeSlide').removeClass('activeSlide');
lastSlide.addClass('activeSlide');
addClassNav();
});
}else {
el.animate({
'margin-left':'-'+left
}, function(){
el.find('.activeSlide').removeClass('activeSlide');
prev.addClass('activeSlide');
addClassNav();
});
}
} else if(direction == 'next') {
var next = el.find('.activeSlide').next(),
left = next.data('left');
if(next.length == 0) {
el.animate({
'margin-left':0
}, function(){
el.find('.activeSlide').removeClass('activeSlide');
firstSlide.addClass('activeSlide');
addClassNav();
});
}else {
el.animate({
'margin-left':'-'+left
}, function(){
el.find('.activeSlide').removeClass('activeSlide');
next.addClass('activeSlide');
addClassNav();
});
}
}
}else {
// Prev Direction
if(direction == 'prev') {
el.children().css({'margin-left':0})
lastSlide.prependTo(el).css({
'margin-left': '-'+dataWidth+'px'
}).animate({
'margin-left': 0
}, duration);
// Next Direction
} else if( direction == 'next') {
firstSlide
.animate({
'margin-left': '-'+dataWidth+'px'
}, duration, function(){
$(this).css({'margin-left':0}).appendTo(el);
el.children().each(function(e){
$(this).attr('data-left', dataWidth*e);
});
})
}
}
},
//heightElement Method
heightElement: function(element, parentElement) {
var h = 0;
element.each(function(){
var hTallest = $(this).height();
if(hTallest > h){
h = hTallest;
}
});
//Attribute heigth element and Container
parentElement.height(h);
parentElement.parent().height(h).attr('data-height', h);
},
//Resize Method
resizeMe: function(element, valueScreen, childLength) {
var childs = element.children();
var docWidth = valueScreen,
childsWidth = docWidth;
element.css({
'width':valueScreen*childLength
}).attr('data-width',valueScreen);
/*childs.css({
'width':valueScreen,
'position':'relative'
});*/
this.heightElement(childs, element);
}
}
// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn.ras = function (options) {
options = $.extend({}, $.ras.slideshow.options, options);
return this.each(function () {
new PlugRAS(this, options);
});
};
})( jQuery, window, document );