PageSourceSearch

https://www.realisaprint.es/boutique/nouveau_site/inc/script_ajax/…/jquery.scrollTo-1.4.3.1.js

js realisaprint.es collected 2026-10-08 10:12:06 UTC 7,790 bytes, 218 lines download raw bytes

1/*!
2 * jQuery.ScrollTo
3 * Copyright (c) 2007-2012 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
4 * Dual licensed under MIT and GPL.
5 * Date: 4/09/2012
6 *
7 * @projectDescription Easy element scrolling using jQuery.
8 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
9 * @author Ariel Flesler
10 * @version 1.4.3.1
11 *
12 * @id jQuery.scrollTo
13 * @id jQuery.fn.scrollTo
14 * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements.
15 *	  The different options for target are:
16 *		- A number position (will be applied to all axes).
17 *		- A string position ('44', '100px', '+=90', etc ) will be applied to all axes
18 *		- A jQuery/DOM element ( logically, child of the element to scroll )
19 *		- A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
20 *		- A hash { top:x, left:y }, x and y can be any kind of number/string like above.
21 *		- A percentage of the container's dimension/s, for example: 50% to go to the middle.
22 *		- The string 'max' for go-to-end. 
23 * @param {Number, Function} duration The OVERALL length of the animation, this argument can be the settings object instead.
24 * @param {Object,Function} settings Optional set of settings or the onAfter callback.
25 *	 @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
26 *	 @option {Number, Function} duration The OVERALL length of the animation.
27 *	 @option {String} easing The easing method for the animation.
28 *	 @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
29 *	 @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.
30 *	 @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.
31 *	 @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
32 *	 @option {Function} onAfter Function to be called after the scrolling ends. 
33 *	 @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.
34 * @return {jQuery} Returns the same jQuery object, for chaining.
35 *
36 * @desc Scroll to a fixed position
37 * @example $('div').scrollTo( 340 );
38 *
39 * @desc Scroll relatively to the actual position
40 * @example $('div').scrollTo( '+=340px', { axis:'y' } );
41 *
42 * @desc Scroll using a selector (relative to the scrolled element)
43 * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } );
44 *
45 * @desc Scroll to a DOM element (same for jQuery object)
46 * @example var second_child = document.getElementById('container').firstChild.nextSibling;
47 *			$('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){
48 *				alert('scrolled!!');																   
49 *			}});
50 *
51 * @desc Scroll on both axes, to different values
52 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
53 */
54
55;(function( $ ){
56	
57	var $scrollTo = $.scrollTo = function( target, duration, settings ){
58		$(window).scrollTo( target, duration, settings );
59	};
60
61	$scrollTo.defaults = {
62		axis:'xy',
63		duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1,
64		limit:true
65	};
66
67	// Returns the element that needs to be animated to scroll the window.
68	// Kept for backwards compatibility (specially for localScroll & serialScroll)
69	$scrollTo.window = function( scope ){
70		return $(window)._scrollable();
71	};
72
73	// Hack, hack, hack :)
74	// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
75	$.fn._scrollable = function(){
76		return this.map(function(){
77			var elem = this,
78				isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1;
79
80				if( !isWin )
81					return elem;
82
83			var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
84			
85			return /webkit/i.test(navigator.userAgent) || doc.compatMode == 'BackCompat' ?
86				doc.body : 
87				doc.documentElement;
88		});
89	};
90
91	$.fn.scrollTo = function( target, duration, settings ){
92		if( typeof duration == 'object' ){
93			settings = duration;
94			duration = 0;
95		}
96		if( typeof settings == 'function' )
97			settings = { onAfter:settings };
98			
99		if( target == 'max' )
100			target = 9e9;
101			
102		settings = $.extend( {}, $scrollTo.defaults, settings );
103		// Speed is still recognized for backwards compatibility
104		duration = duration || settings.duration;
105		// Make sure the settings are given right
106		settings.queue = settings.queue && settings.axis.length > 1;
107		
108		if( settings.queue )
109			// Let's keep the overall duration
110			duration /= 2;
111		settings.offset = both( settings.offset );
112		settings.over = both( settings.over );
113
114		return this._scrollable().each(function(){
115			// Null target yields nothing, just like jQuery does
116			if (target == null) return;
117
118			var elem = this,
119				$elem = $(elem),
120				targ = target, toff, attr = {},
121				win = $elem.is('html,body');
122
123			switch( typeof targ ){
124				// A number will pass the regex
125				case 'number':
126				case 'string':
127					if( /^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ) ){
128						targ = both( targ );
129						// We are done
130						break;
131					}
132					// Relative selector, no break!
133					targ = $(targ,this);
134					if (!targ.length) return;
135				case 'object':
136					// DOMElement / jQuery
137					if( targ.is || targ.style )
138						// Get the real position of the target 
139						toff = (targ = $(targ)).offset();
140			}
141			$.each( settings.axis.split(''), function( i, axis ){
142				var Pos	= axis == 'x' ? 'Left' : 'Top',
143					pos = Pos.toLowerCase(),
144					key = 'scroll' + Pos,
145					old = elem[key],
146					max = $scrollTo.max(elem, axis);
147
148				if( toff ){// jQuery / DOMElement
149					attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );
150
151					// If it's a dom element, reduce the margin
152					if( settings.margin ){
153						attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
154						attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
155					}
156					
157					attr[key] += settings.offset[pos] || 0;
158					
159					if( settings.over[pos] )
160						// Scroll to a fraction of its width/height
161						attr[key] += targ[axis=='x'?'width':'height']() * settings.over[pos];
162				}else{ 
163					var val = targ[pos];
164					// Handle percentage values
165					attr[key] = val.slice && val.slice(-1) == '%' ? 
166						parseFloat(val) / 100 * max
167						: val;
168				}
169
170				// Number or 'number'
171				if( settings.limit && /^\d+$/.test(attr[key]) )
172					// Check the limits
173					attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max );
174
175				// Queueing axes
176				if( !i && settings.queue ){
177					// Don't waste time animating, if there's no need.
178					if( old != attr[key] )
179						// Intermediate animation
180						animate( settings.onAfterFirst );
181					// Don't animate this axis again in the next iteration.
182					delete attr[key];
183				}
184			});
185
186			animate( settings.onAfter );			
187
188			function animate( callback ){
189				$elem.animate( attr, duration, settings.easing, callback && function(){
190					callback.call(this, target, settings);
191				});
192			};
193
194		}).end();
195	};
196	
197	// Max scrolling position, works on quirks mode
198	// It only fails (not too badly) on IE, quirks mode.
199	$scrollTo.max = function( elem, axis ){
200		var Dim = axis == 'x' ? 'Width' : 'Height',
201			scroll = 'scroll'+Dim;
202		
203		if( !$(elem).is('html,body') )
204			return elem[scroll] - $(elem)[Dim.toLowerCase()]();
205		
206		var size = 'client' + Dim,
207			html = elem.ownerDocument.documentElement,
208			body = elem.ownerDocument.body;
209
210		return Math.max( html[scroll], body[scroll] ) 
211			 - Math.min( html[size]  , body[size]   );
212	};
213
214	function both( val ){
215		return typeof val == 'object' ? val : { top:val, left:val };
216	};
217
218})( 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.