PageSourceSearch

https://www.bibliotecanichelino.it/bn/modules/mod_bt_contentslider/tmpl/js/slides.js

js bibliotecanichelino.it collected 2026-09-25 07:47:21 UTC 21,635 bytes, 667 lines download raw bytes

1/*
2* Slides, A Slideshow Plugin for jQuery
3* Intructions: http://slidesjs.com
4* By: Nathan Searles, http://nathansearles.com
5* Version: 1.1.9
6* Updated: September 5th, 2011
7*
8* Licensed under the Apache License, Version 2.0 (the "License");
9* you may not use this file except in compliance with the License.
10* You may obtain a copy of the License at
11*
12* http://www.apache.org/licenses/LICENSE-2.0
13*
14* Unless required by applicable law or agreed to in writing, software
15* distributed under the License is distributed on an "AS IS" BASIS,
16* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17* See the License for the specific language governing permissions and
18* limitations under the License.
19*/
20(function($){
21	$.fn.slides = function( option ) {
22		// override defaults with specified option
23		option = $.extend( {}, $.fn.slides.option, option );
24
25		return this.each(function(){
26			// wrap slides in control container, make sure slides are block level
27			$('.' + option.container, $(this)).children().wrapAll('<div class="slides_control"/>');
28			var elem = $(this),
29				control = $('.slides_control',elem),
30				total = control.children().size(),
31				width = getWidth(),
32				height = getHeight(),
33				start = option.start - 1,
34				effect = option.effect.indexOf(',') < 0 ? option.effect : option.effect.replace(' ', '').split(',')[0],
35				paginationEffect = option.effect.indexOf(',') < 0 ? effect : option.effect.replace(' ', '').split(',')[1],
36				next = 0, prev = 0, number = 0, current = 0, loaded, active, clicked, position, direction, imageParent, pauseTimeout, playInterval;
37			equalHeight();
38			if(option.width=="auto"){
39				$(window).resize(function(){
40					var width = getWidth();
41					elem.find('.slide').css({
42					left: width,
43					width: width
44					});
45					equalHeight();
46					control.css({
47					left: -width,
48					width: (width * 3),
49					height:getHeight()
50					});
51					
52				});
53			}
54			
55			// is there only one slide?
56			if (total < 2) {
57				// Fade in .slides_container
58				$('.' + option.container, $(this)).fadeIn(option.fadeSpeed, option.fadeEasing, function(){
59					// let the script know everything is loaded
60					loaded = true;
61					// call the loaded funciton
62					option.slidesLoaded();
63				});
64				// Hide the next/previous buttons
65				$('.' + option.next + ', .' + option.prev,elem).fadeOut(0);
66				return false;
67			}
68			
69			// animate slides
70			function animate(direction, effect, clicked) {
71				if (!active && loaded) {
72					active = true;
73					// start of animation
74					option.animationStart(current + 1);
75					switch(direction) {
76						case 'next':
77							// change current slide to previous
78							prev = current;
79							// get next from current + 1
80							next = current + 1;
81							// if last slide, set next to first slide
82							next = total === next ? 0 : next;
83							// set position of next slide to right of previous
84							position = option.currentWidth*2;
85							// distance to slide based on width of slides
86							direction = -option.currentWidth*2;
87							// store new current slide
88							current = next;
89						break;
90						case 'prev':
91							// change current slide to previous
92							prev = current;
93							// get next from current - 1
94							next = current - 1;
95							// if first slide, set next to last slide
96							next = next === -1 ? total-1 : next;								
97							// set position of next slide to left of previous
98							position = 0;								
99							// distance to slide based on width of slides
100							direction = 0;		
101							// store new current slide
102							current = next;
103						break;
104						case 'pagination':
105							// get next from pagination item clicked, convert to number
106							next = parseInt(clicked,10);
107							// get previous from pagination item with class of current
108							prev = $('.' + option.paginationClass + ' li.'+ option.currentClass +' a', elem).attr('href').match('[^#/]+$');
109							// if next is greater then previous set position of next slide to right of previous
110							if (next > prev) {
111								position = option.currentWidth*2;
112								direction = -option.currentWidth*2;
113							} else {
114							// if next is less then previous set position of next slide to left of previous
115								position = 0;
116								direction = 0;
117							}
118							// store new current slide
119							current = next;
120						break;
121					}
122
123					// fade animation
124					if (effect === 'fade') {
125						// fade animation with crossfade
126						if (option.crossfade) {
127							// put hidden next above current
128							control.children(':eq('+ next +')', elem).css({
129								zIndex: 10
130							// fade in next
131							}).fadeIn(option.fadeSpeed, option.fadeEasing, function(){
132								if (option.autoHeight) {
133									// animate container to height of next
134									equalHeight(next);
135									control.animate({
136										height: control.children(':eq('+ next +')', elem).outerHeight()
137									}, option.autoHeightSpeed, function(){
138										// hide previous
139										control.children(':eq('+ prev +')', elem).css({
140											display: 'none',
141											zIndex: 0
142										});								
143										// reset z index
144										control.children(':eq('+ next +')', elem).css({
145											zIndex: 0
146										});									
147										// end of animation
148										option.animationComplete(next + 1);
149										active = false;
150									});
151								} else {
152									// hide previous
153									control.children(':eq('+ prev +')', elem).css({
154										display: 'none',
155										zIndex: 0
156									});									
157									// reset zindex
158									control.children(':eq('+ next +')', elem).css({
159										zIndex: 0
160									});									
161									// end of animation
162									option.animationComplete(next + 1);
163									active = false;
164								}
165							});
166						} else {
167							// fade animation with no crossfade
168							control.children(':eq('+ prev +')', elem).fadeOut(option.fadeSpeed,  option.fadeEasing, function(){
169								// animate to new height
170								equalHeight(next);
171								if (option.autoHeight) {
172									control.animate({
173										// animate container to height of next
174										height: control.children(':eq('+ next +')', elem).outerHeight()
175									}, option.autoHeightSpeed,
176									// fade in next slide
177									function(){
178										control.children(':eq('+ next +')', elem).fadeIn(option.fadeSpeed, option.fadeEasing);
179									});
180								} else {
181								// if fixed height
182									control.children(':eq('+ next +')', elem).fadeIn(option.fadeSpeed, option.fadeEasing, function(){
183										// fix font rendering in ie, lame
184										if($.browser.msie) {
185											$(this).get(0).style.removeAttribute('filter');
186										}
187									});
188								}									
189								// end of animation
190								option.animationComplete(next + 1);
191								active = false;
192							});
193						}
194					// slide animation
195					} else {
196						// move next slide to right of previous
197						control.children(':eq('+ next +')').css({
198							left: position,
199							display: 'block'
200						});
201						// animate to new height
202						if (option.autoHeight) {
203							equalHeight(next);
204							control.animate({
205								left: direction,
206								height: control.children(':eq('+ next +')').outerHeight()
207							},option.slideSpeed, option.slideEasing, function(){
208								control.css({
209									left: -option.currentWidth
210								});
211								control.children(':eq('+ next +')').css({
212									left: option.currentWidth,
213									zIndex: 5
214								});
215								// reset previous slide
216								control.children(':eq('+ prev +')').css({
217									left: option.currentWidth,
218									display: 'none',
219									zIndex: 0
220								});
221								// end of animation
222								option.animationComplete(next + 1);
223								active = false;
224							});
225							// if fixed height
226							} else {
227								// animate control
228								equalHeight(next);
229								control.animate({
230									left: direction
231								},option.slideSpeed, option.slideEasing, function(){
232									// after animation reset control position
233									control.css({
234										left: -option.currentWidth
235									});
236									// reset and show next
237									control.children(':eq('+ next +')').css({
238										left: option.currentWidth,
239										zIndex: 5
240									});
241									// reset previous slide
242									control.children(':eq('+ prev +')').css({
243										left: option.currentWidth,
244										display: 'none',
245										zIndex: 0
246									});
247									// end of animation
248									option.animationComplete(next + 1);
249									active = false;
250								});
251							}
252						}
253					// set current state for pagination
254					if (option.pagination) {
255						// remove current class from all
256						$('.'+ option.paginationClass +' li.' + option.currentClass, elem).removeClass(option.currentClass);
257						// add current class to next
258						$('.' + option.paginationClass + ' li:eq('+ next +')', elem).addClass(option.currentClass);
259					}
260					
261				}
262				
263			} // end animate function
264			
265			function stop() {
266				// clear interval from stored id
267				clearInterval(elem.data('interval'));
268			}
269			function equalHeight(pointer){
270				// equal height for title/description
271				if(!pointer) pointer = current;
272 				if(option.equalHeight){
273					//setEqualHeight(control.children(':eq('+ pointer +')'));
274					var el = control.children(':eq('+ pointer +')');
275					jQuery('.bt-title,.bt-introtext',el).height('auto');
276					var maxHeight = Math.max.apply(null, jQuery('.bt-title',el).map(function (){return jQuery(this).height();}).get());
277					if(maxHeight) jQuery('.bt-title',el).height(maxHeight);
278					maxHeight = Math.max.apply(null, jQuery('.bt-introtext',el).map(function (){return jQuery(this).height();}).get());
279					if(maxHeight) jQuery('.bt-introtext',el).height(maxHeight);
280				}
281			}
282			function getWidth(){
283				option.currentWidth = option.width!="auto"?option.width:elem.width();
284				return option.currentWidth;
285			}
286			function getHeight(){
287				var mheight = 0;
288				
289				if(option.autoHeight){
290					mheight = control.children(':eq('+ current +')').outerHeight();
291				}else{
292					if(option.height=='auto'){
293						mheight= Math.max.apply(null, control.children().map(function (){return $(this).outerHeight();}).get());
294					}else{
295						mheight = option.height;
296					}
297				}
298				return mheight? mheight:'auto';
299			}
300			function pause() {
301				if (option.pause) {
302					// clear timeout and interval
303					clearTimeout(elem.data('pause'));
304					clearInterval(elem.data('interval'));
305					// pause slide show for option.pause amount
306					pauseTimeout = setTimeout(function() {
307						// clear pause timeout
308						clearTimeout(elem.data('pause'));
309						// start play interval after pause
310						playInterval = setInterval(	function(){
311							animate("next", effect);
312						},option.play);
313						// store play interval
314						elem.data('interval',playInterval);
315					},option.pause);
316					// store pause interval
317					elem.data('pause',pauseTimeout);
318				} else {
319					// if no pause, just stop
320					stop();
321				}
322			}
323				
324			// 2 or more slides required
325			if (total < 2) {
326				return;
327			}
328			
329			// error corection for start slide
330			if (start < 0) {
331				start = 0;
332			}
333			
334			if (start > total) {
335				start = total - 1;
336			}
337					
338			// change current based on start option number
339			if (option.start) {
340				current = start;
341			}
342			
343			// randomizes slide order
344			if (option.randomize) {
345				control.randomize();
346			}
347			
348			// make sure overflow is hidden, width is set
349			$('.' + option.container, elem).css({
350				overflow: 'hidden',
351				// fix for ie
352				position: 'relative'
353			});
354			
355			// set css for slides
356			control.children().css({
357				position: 'absolute',
358				top: 0, 
359				left: control.children().outerWidth(),
360				zIndex: 0,
361				display: 'none'
362			 });
363			
364			// set css for control div
365			control.css({
366				position: 'relative',
367				// size of control 3 x slide width
368				width: (option.currentWidth * 3),
369				// set height to slide height
370				height: height,
371				// center control to slide
372				left: -option.currentWidth
373			});
374			
375			// show slides
376			$('.' + option.container, elem).css({
377				display: 'block'
378			});
379
380			// if autoHeight true, get and set height of first slide
381			if (option.autoHeight) {
382				control.children().css({
383					height: 'auto'
384				});
385				control.animate({
386					height: control.children(':eq('+ start +')').outerHeight()
387				},option.autoHeightSpeed);
388			}
389			
390			// checks if image is loaded
391			if (option.preload && control.find('img:eq(' + start + ')').length) {
392				// adds preload image
393				$('.' + option.container, elem).css({
394					background: 'url(' + option.preloadImage + ') no-repeat 50% 50%'
395				});
396				
397				/*
398				// gets image src, with cache buster
399				var img = control.find('img:eq(' + start + ')').attr('src') + '?' + (new Date()).getTime();
400				
401				// check if the image has a parent
402				if ($('img', elem).parent().attr('class') != 'slides_control') {
403					// If image has parent, get tag name
404					imageParent = control.children(':eq(0)')[0].tagName.toLowerCase();
405				} else {
406					// Image doesn't have parent, use image tag name
407					imageParent = control.find('img:eq(' + start + ')');
408				}
409				*/
410				// checks if image is loaded
411				var $imgs = control.find('img');
412				var imgsl = $imgs.length;
413				var u=0;
414				$imgs.each(function(){
415					var img = new Image();
416					$(img).load(function(){
417						++u;
418						if (u == imgsl) {
419							startSlider();
420						}
421					}).error(function () {
422						++u;
423						if (u == imgsl) {
424							startSlider();
425						}
426					}).attr('src',this.src);
427				});
428			} else {
429				// if no preloader fade in start slide
430				control.children(':eq(' + start + ')').fadeIn(option.fadeSpeed, option.fadeEasing, function(){
431					// let the script know everything is loaded
432					loaded = true;
433					// call the loaded funciton
434					option.slidesLoaded();
435				});
436			}
437			function startSlider(){
438				// once image is fully loaded, fade in
439				control.children(':eq(' + start + ')').fadeIn(option.fadeSpeed, option.fadeEasing, function(){
440					$(this).css({
441						zIndex: 5
442					});
443					// removes preload image
444					$('.' + option.container, elem).css({
445						background: ''
446					});
447					control.css({
448						height:getHeight()
449					});
450					// let the script know everything is loaded
451					loaded = true;
452					// call the loaded funciton
453					option.slidesLoaded();
454				});
455			}
456			
457			// click slide for next
458			if (option.bigTarget) {
459				// set cursor to pointer
460				control.children().css({
461					cursor: 'pointer'
462				});
463				// click handler
464				control.children().click(function(){
465					// animate to next on slide click
466					animate('next', effect);
467					return false;
468				});									
469			}
470			
471			// pause on mouseover
472			if (option.hoverPause && option.play) {
473				control.bind('mouseover',function(){
474					// on mouse over stop
475					stop();
476				});
477				control.bind('mouseleave',function(){
478					// on mouse leave start pause timeout
479					pause();
480				});
481			}
482			
483			// generate next/prev buttons
484			if (option.generateNextPrev) {
485				$('.' + option.container, elem).after('<a href="#" class="'+ option.prev +'">Prev</a>');
486				$('.' + option.prev, elem).after('<a href="#" class="'+ option.next +'">Next</a>');
487			}
488			
489			// next button
490			$('.' + option.next ,elem).click(function(e){
491				e.preventDefault();
492				if (option.play) {
493					pause();
494				}
495				animate('next', effect);
496			});
497			
498			// previous button
499			$('.' + option.prev, elem).click(function(e){
500				e.preventDefault();
501				if (option.play) {
502					 pause();
503				}
504				animate('prev', effect);
505			});
506			
507			// generate pagination
508			if (option.generatePagination) {
509				// create unordered list
510				if($('.' + option.next ,elem).length){
511					$('.' + option.next ,elem).before('<ul class='+ option.paginationClass +'></ul>');
512				}else
513				if (option.prependPagination){
514					elem.prepend('<ul class='+ option.paginationClass +'></ul>');
515				}else{
516					elem.append('<ul class='+ option.paginationClass +'></ul>');
517				}
518				// for each slide create a list item and link
519				control.children().each(function(){
520					$('.' + option.paginationClass, elem).append('<li><a href="#'+ number +'">'+ (number+1) +'</a></li>');
521					number++;
522				});
523			} else {
524				// if pagination exists, add href w/ value of item number to links
525				$('.' + option.paginationClass + ' li a', elem).each(function(){
526					$(this).attr('href', '#' + number);
527					number++;
528				});
529			}
530			
531			// add current class to start slide pagination
532			$('.' + option.paginationClass + ' li:eq('+ start +')', elem).addClass(option.currentClass);
533			
534			// click handling 
535			$('.' + option.paginationClass + ' li a', elem ).click(function(){
536				// pause slideshow
537				if (option.play) {
538					 pause();
539				}
540				// get clicked, pass to animate function					
541				clicked = $(this).attr('href').match('[^#/]+$');
542				// if current slide equals clicked, don't do anything
543				if (current != clicked) {
544					animate('pagination', paginationEffect, clicked);
545				}
546				return false;
547			});
548			
549			// click handling 
550			$('a.link', elem).click(function(){
551				// pause slideshow
552				if (option.play) {
553					 pause();
554				}
555				// get clicked, pass to animate function					
556				clicked = $(this).attr('href').match('[^#/]+$') - 1;
557				// if current slide equals clicked, don't do anything
558				if (current != clicked) {
559					animate('pagination', paginationEffect, clicked);
560				}
561				return false;
562			});
563		
564			if (option.play) {
565				// set interval
566				playInterval = setInterval(function() {
567					animate('next', effect);
568				}, option.play);
569				// store interval id
570				elem.data('interval',playInterval);
571			}
572
573			
574			if(option.touchScreen){
575				var timeStart, xStart, yStart;
576				$(control).on('touchstart', function(e){
577					var touch = e.originalEvent.touches[0];
578					xStart = touch.pageX;
579					yStart = touch.pageY;
580					timeStart = Number(new Date());
581					
582				});
583				$(control).on('touchend', function(e){
584					var touch = e.originalEvent.changedTouches[0];
585					var duration = Number(new Date()) - timeStart;
586					var xDistance = touch.pageX - xStart;
587					var yDistance = touch.pageY - yStart;
588					
589					if(duration <= 300 && Math.abs(yDistance) <= 20 && xDistance != 0){
590						if (option.play) {
591							pause();
592						}
593						if(xDistance < 0){
594							animate('next', effect);
595						}else{
596							animate('prev', effect);
597						}
598					}else{
599						return;
600					}
601					
602				});
603			}
604			
605		});
606	};
607	
608	// default options
609	$.fn.slides.option = {
610		preload: false, // boolean, Set true to preload images in an image based slideshow
611		preloadImage: '/img/loading.gif', // string, Name and location of loading image for preloader. Default is "/img/loading.gif"
612		container: 'slides_container', // string, Class name for slides container. Default is "slides_container"
613		generateNextPrev: false, // boolean, Auto generate next/prev buttons
614		next: 'next', // string, Class name for next button
615		prev: 'prev', // string, Class name for previous button
616		pagination: true, // boolean, If you're not using pagination you can set to false, but don't have to
617		generatePagination: true, // boolean, Auto generate pagination
618		prependPagination: false, // boolean, prepend pagination
619		paginationClass: 'pagination', // string, Class name for pagination
620		currentClass: 'current', // string, Class name for current class
621		fadeSpeed: 350, // number, Set the speed of the fading animation in milliseconds
622		fadeEasing: '', // string, must load jQuery's easing plugin before http://gsgd.co.uk/sandbox/jquery/easing/
623		slideSpeed: 350, // number, Set the speed of the sliding animation in milliseconds
624		slideEasing: '', // string, must load jQuery's easing plugin before http://gsgd.co.uk/sandbox/jquery/easing/
625		start: 1, // number, Set the speed of the sliding animation in milliseconds
626		effect: 'slide', // string, '[next/prev], [pagination]', e.g. 'slide, fade' or simply 'fade' for both
627		crossfade: false, // boolean, Crossfade images in a image based slideshow
628		randomize: false, // boolean, Set to true to randomize slides
629		play: 0, // number, Autoplay slideshow, a positive number will set to true and be the time between slide animation in milliseconds
630		pause: 0, // number, Pause slideshow on click of next/prev or pagination. A positive number will set to true and be the time of pause in milliseconds
631		hoverPause: false, // boolean, Set to true and hovering over slideshow will pause it
632		autoHeight: false, // boolean, Set to true to auto adjust height
633		autoHeightSpeed: 350, // number, Set auto height animation time in milliseconds
634		bigTarget: false, // boolean, Set to true and the whole slide will link to next slide on click
635		animationStart: function(){}, // Function called at the start of animation
636		animationComplete: function(){}, // Function called at the completion of animation
637		slidesLoaded: function() {}, // Function is called when slides is fully loaded
638		width:'auto',
639		equalHeight:true,
640		currentWidth: '',
641	};
642	
643	// Randomize slide order on load
644	$.fn.randomize = function(callback) {
645		function randomizeOrder() { return(Math.round(Math.random())-0.5); }
646			return($(this).each(function() {
647			var $this = $(this);
648			var $children = $this.children();
649			var childCount = $children.length;
650			if (childCount > 1) {
651				$children.hide();
652				var indices = [];
653				for (i=0;i<childCount;i++) { indices[indices.length] = i; }
654				indices = indices.sort(randomizeOrder);
655				$.each(indices,function(j,k) { 
656					var $child = $children.eq(k);
657					var $clone = $child.clone(true);
658					$clone.show().appendTo($this);
659					if (callback !== undefined) {
660						callback($child, $clone);
661					}
662				$child.remove();
663			});
664			}
665		}));
666	};
667})(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.