PageSourceSearch

https://www.22.cz/forge/vendors/jquery/carousel/jquery.easyride.plugin.js

js 22.cz collected 2026-10-08 02:37:46 UTC 11,016 bytes, 552 lines download raw bytes

1/*!
2	(c) 2012 Jan Mikes. MIT License. (http://twitter.com/fararr)
3
4	version 0.4.1 - stable
5	requires jQuery 1.7
6*/
7
8(function( $ ){
9
10	// add reverse method
11	$.fn.reverse = [].reverse;
12
13	$.fn.easyRide = function( options ) {
14
15		// default settings extended with passed options
16		var options = $.extend( {
17		slider		: 'ul',
18		slides		: 'ul li',
19		prevButton	: null,// control html element
20		nextButton	: null,// control html element
21		addPaging	: false,
22		pageButtons : null,// control html element
23		leftEasing	: 'easeOutQuart',// easing method (fallback to linear)
24		rightEasing	: 'easeOutQuart',// easing method (fallback to linear)
25		direction	: 'left',
26		axis		: 'x',
27		speed		: 800,
28		autostart	: false,
29		autostartDelay : 6000,
30		enabled		: false
31		}, options);
32
33
34		return this.each(function(){
35
36			// helper functions
37			var $trace = function(msg){
38				console.log(msg);
39			};
40
41
42			var $this = $(this),
43
44			// carousel object
45			jcar = {
46
47				container : $this,
48
49				slider : $this.find(options.slider),
50				slides : $this.find(options.slides),
51				slidesCount : $this.find(options.slides).length,
52
53				pageButtons	: $(options.pageButtons),
54				addPaging	: options.addPaging,
55
56				speed : options.speed,
57				autostart : options.autostart,
58				autostartDelay : options.autostartDelay,
59				automoveStatus : false,
60
61				direction : options.direction,
62				lastDirection : options.direction,
63
64				axis : options.axis,
65
66				position : 0,// default position
67
68				enabled : options.enabled,
69
70				namespace : 'er-carousel-',
71
72				// methods
73				prevButton : $(options.prevButton).on('click', function(e){
74
75					e.preventDefault();
76
77					if(jcar.enabled && !jcar.slider.is(':animated')){
78
79						jcar.direction = 'right';
80						if(jcar.directionCheck()){
81
82							jcar.move();
83
84							// disable automove - if any
85							clearInterval(jcar.automoveInterval);
86
87						}
88					}
89
90				}),
91
92
93				nextButton : $(options.nextButton).on('click', function(e){
94
95					e.preventDefault();
96
97					if(jcar.enabled && !jcar.slider.is(':animated')){
98
99						jcar.direction = 'left';
100						if(jcar.directionCheck()){
101
102							jcar.move();
103
104							// disable automove - if any
105							clearInterval(jcar.automoveInterval);
106						}
107					}
108
109				}),
110
111
112				// init stuff - move all here TODO
113				init : function(){
114
115					// init position
116					jcar.slider.css('top', 0);
117					jcar.slider.css('left', 0);
118
119					// add data key
120					$.each(jcar.slides, function(i, slide){
121						$(this).data(jcar.namespace + 'slide_id', i);
122
123						// used for find
124						$(this).attr('rel', i);
125					});
126
127				},
128
129
130				reloadSlides : function(){
131
132					jcar.slides = jcar.container.find(options.slides);
133
134					// override lastDirection - important!
135					jcar.lastDirection = jcar.direction;
136
137				},
138
139
140				positionCheck : function(){
141
142					var current = jcar.slides.first();
143
144					// use with data()
145					jcar.position = current.data(jcar.namespace + 'slide_id');
146
147					// and mark current page
148					jcar.switchPage(jcar.position);
149
150				},
151
152
153				move : function(){
154
155					var item_size = 0,
156						first_item = jcar.slides.first(),
157						last_item = jcar.slides.last();
158
159					// if vertical move
160					if(jcar.axis == 'y'){
161
162						item_size = first_item.outerHeight() * -1;
163
164						if(jcar.direction == 'left'){
165							jcar.slider.animate({'top': item_size}, {duration: jcar.speed, easing: options.leftEasing , queue: false, complete: function(){
166								jcar.slider.css('top', 0);
167								last_item.after(first_item);
168								jcar.reloadSlides();
169								jcar.positionCheck();
170							}});
171						}
172
173						if(jcar.direction == 'right'){
174							jcar.slider.animate({'top': 0}, {duration: jcar.speed, easing: options.rightEasing, queue: false, complete: function(){
175								jcar.slider.css('top', 0);
176								jcar.reloadSlides();
177								jcar.positionCheck();
178							}});
179						}
180
181
182					// default horizontal - not dry
183					}else{
184
185						item_size = first_item.outerWidth() * -1;
186
187						if(jcar.direction == 'left'){
188							jcar.slider.animate({'left': item_size}, {duration: jcar.speed, easing: options.leftEasing , queue: false, complete: function(){
189								jcar.slider.css('left', 0);
190								last_item.after(first_item);
191								jcar.reloadSlides();
192								jcar.positionCheck();
193							}});
194						}
195
196						if(jcar.direction == 'right'){
197							jcar.slider.animate({'left': 0}, {duration: jcar.speed, easing: options.rightEasing, queue: false, complete: function(){
198								jcar.slider.css('left', 0);
199								jcar.reloadSlides();
200								jcar.positionCheck();
201							}});
202						}
203					}
204
205				},
206//				move : function(){
207//
208//					var item_width = 0,
209//						first_item = jcar.slides.first(),
210//						last_item = jcar.slides.last();
211//
212//					if(jcar.direction == 'left'){
213//
214//						item_width = first_item.outerWidth() * -1;
215//
216//						// do animation
217//						jcar.slider.animate({'left': item_width}, {duration: jcar.speed, easing: options.leftEasing , queue: false, complete: function(){
218//
219//							jcar.slider.css('left', 0);
220//							last_item.after(first_item);
221//
222//							// and reload slides
223//							jcar.reloadSlides();
224//
225//							jcar.positionCheck();
226//						}}
226);
227//
228//					}
229//
230//					if(jcar.direction == 'right'){
231//
232//						// do animation
233//						jcar.slider.animate({'left': 0}, {duration: jcar.speed, easing: options.rightEasing, queue: false, complete: function(){
234//
235//							jcar.slider.css('left', 0);
236//
237//							// and reload slides
238//							jcar.reloadSlides();
239//
240//							jcar.positionCheck();
241//						}});
242//
243//					}
244//
245//				},
246
247
248				moveTo : function(position){
249
250					if(jcar.position !== position){
251
252						// clear interval first
253						clearInterval(jcar.automoveInterval);
254
255						// switch to selected slide
256						jcar.slider.fadeOut('fast', function(){
257
258							jcar.slider.css('top', 0);
259							jcar.slider.css('left', 0);
260
261							jcar.slider.find('[rel='+ position +']').prevUntil().reverse().appendTo(
262								jcar.slider
263							);
264
265							jcar.reloadSlides();
266
267							// show slider again
268							jcar.slider.fadeIn('fast');
269
270							jcar.positionCheck();
271
272							// run automove interval again (if enabled)
273							jcar.automoveRun();
274
275						});
276
277					}
278
279				},
280
281
282				enableCheck : function(){
283
284					var slideSize = 0;
285
286					// vertical
287					if(jcar.axis == 'y'){
288
289						// default slider height TODO more precise
290						slideSize = jcar.slides.outerHeight() * jcar.slidesCount;
291
292						if(slideSize > jcar.container.outerHeight()){
293
294							jcar.enabled = true;
295							jcar.slider.css('height', (slideSize * 2)); // doubled height
296						}
297
298					// default horizontal
299					}else{
300
301						// default slider width TODO more precise
302						slideSize = jcar.slides.outerWidth() * jcar.slidesCount;
303
304						if(slideSize > jcar.container.outerWidth()){
305
306							jcar.enabled = true;
307							jcar.slider.css('width', (slideSize * 2)); // doubled width
308						}
309
310					}
311
312
313					if(!jcar.enabled){
314						jcar.prevButton.hide();
315						jcar.nextButton.hide();
316					}
317
318				},
319
320
321				directionCheck : function(){
322
323					var item_size = 0,
324						item_indent = 0,
325						first_item = jcar.slides.first(),
326						last_item = jcar.slides.last();
327
328
329					if(jcar.direction == 'right'){
330
331						// prefix direction change
332						first_item.before(last_item);
333
334						// reload slides (this is if image width is different)
335						jcar.reloadSlides();
336
337						// get current last item
338						last_item = jcar.slides.last()
339
340
341						// slide direction
342						// vertical
343						if(jcar.axis == 'y'){
344
345							item_size = last_item.outerHeight();
346							item_indent = parseInt(jcar.slider.css('top')) - item_size;
347							jcar.slider.css('top', item_indent);
348
349						// default horizontal
350						}else{
351
352							item_size = last_item.outerWidth();
353							item_indent = parseInt(jcar.slider.css('left')) - item_size;
354							jcar.slider.css('left', item_indent);
355
356						}
357
358					}
359
360					if(jcar.direction == 'left'){
361
362						// reload slides (this is if image width is different)
363						jcar.reloadSlides();
364
365					}
366
367					return true;
368
369				},
370
371
372//				directionCheck : function(){
373//
374//					var item_width = 0,
375//						left_indent = 0,
376//						first_item = jcar.slides.first(),
377//						last_item = jcar.slides.last();
378//
379//
380//					if(jcar.direction == 'right'){
381//
382//						// prefix direction change
383//						first_item.before(last_item);
384//
385//						// reload slides (this is if image width is different)
386//						jcar.reloadSlides();
387//
388//						// get current last item
389//						last_item = jcar.slides.last()
390//
391//						item_width = last_item.outerWidth();
392//						left_indent = parseInt(jcar.slider.css('left')) - item_width;
393//						jcar.slider.css('left', left_indent);
394//
395//					}
396//
397//					if(jcar.direction == 'left'){
398//
399//						// reload slides (this is if image width is different)
400//						jcar.reloadSlides();
401//
402//					}
403//
404//					return true;
405//
406//				},
407
408
409				easingCheck : function(){
410
411					if(typeof($.easing[options.leftEasing]) === 'undefined'){
412						options.leftEasing = 'linear';
413					}
414
415					if(typeof($.easing[options.rightEasing]) === 'undefined'){
416						options.rightEasing = 'linear';
417					}
418
419				},
420
421
422				automoveInterval : function(){},
423
424
425				automoveRun : function(){
426
427					if(jcar.automoveStatus){
428
429						jcar.automoveInterval = jcar.automoveCreateInterval();
430
431					}
432
433				},
434
435
436				automoveCreateInterval : function(){
437
438					return setInterval(function(){
439
440						if(jcar.enabled && !jcar.slider.is(':animated')){
441
442							if(jcar.directionCheck()){
443
444								jcar.move();
445
446							}
447
448						}
449
450					}, jcar.autostartDelay);
451
452				},
453
454
455				createPaging : function(){
456
457					var items = [];
458
459					for(var i = 0; i < jcar.slidesCount; i++){
460
461						var num = i + 1;
462
463						// set data-namespace
464						items.push('<li><a href="#" data-' + jcar.namespace + 'goto_id="' + i + '"><span>' + num + '</span></a></li>');
465
466					}
467
468					jcar.pageButtons.append(items.join(''));
469
470					// wrap with ul tag
471					jcar.pageButtons.wrapInner('<ul />');
472
473
474					// add click event for all page buttons
475					$(jcar.pageButtons.find('a')).on('click', function(e){
476
477						e.preventDefault();
478
479						// get new position
480						var newPosition = parseInt($(this).data(jcar.namespace + 'goto_id'));
481
482						// only if slider is not animated
483						if(!jcar.slider.is(':animated')){
484
485							// and move to position
486							jcar.moveTo(newPosition);
487
488						}
489
490
491						jcar.positionCheck();
492
493
494						return false;
495					});
496
497
498				},
499
500
501				switchPage : function(position){
502
503					// if paging enabled
504					if(jcar.addPaging){
505
506						// rebuild
507						jcar.pageButtons.find('a').removeClass('over');
508						jcar.pageButtons.find('a').eq(position).addClass('over');
509
510					}
511
512				}
513
514
515			};
516
517
518
519			// Init start
520			jcar.init();
521
522
523			// set jcar.enabled status
524			jcar.enableCheck();
525
526			// check if easing method is available
527			jcar.easingCheck();
528
529			// if paging enabled
530			if(jcar.addPaging){
531
532				jcar.createPaging();
533
534				jcar.positionCheck();
535			}
536
537
538			if(jcar.autostart){
539
540				jcar.automoveStatus = true;
541
542				jcar.automoveRun();
543			}
544			// Init end
545
546
547		});// end return.each
548
549	};// easyRide
550
551
552})( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.