PageSourceSearch

https://www.vipsektor.com/Script/Js/jquery.serialScroll-1.2.1.js

js vipsektor.com collected 2026-10-05 01:54:09 UTC 7,165 bytes, 190 lines download raw bytes

1/**
2 * jQuery.serialScroll
3 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
4 * Dual licensed under MIT and GPL.
5 * Date: 3/20/2008
6 *
7 * @projectDescription Animated scrolling of series.
8 * @author Ariel Flesler
9 * @version 1.2.1
10 *
11 * @id jQuery.serialScroll
12 * @id jQuery.fn.serialScroll
13 * @param {Object} settings Hash of settings, it is passed in to jQuery.ScrollTo, none is required.
14 * @return {jQuery} Returns the same jQuery object, for chaining.
15 *
16 * http://flesler.blogspot.com/2008/02/jqueryserialscroll.html
17 *
18 * Notes:
19 *	- The plugin requires jQuery.ScrollTo.
20 *	- The hash of settings, is passed to jQuery.ScrollTo, so its settings can be used as well.
21 */
22;(function( $ ){
23
24	var $serialScroll = $.serialScroll = function( settings ){
25		$.scrollTo.window().serialScroll( settings );
26	};
27
28	//Many of these defaults, belong to jQuery.ScrollTo, check it's demo for an example of each option.
29	//@see http://flesler.webs/jQuery.ScrollTo/
30	$serialScroll.defaults = {//the defaults are public and can be overriden.
31		duration:1000, //how long to animate.
32		axis:'x', //which of top and left should be scrolled
33		event:'click', //on which event to react.
34		start:0, //first element (zero-based index)
35		step:1, //how many elements to scroll on each action
36		lock:true,//ignore events if already animating
37		cycle:true, //cycle endlessly ( constant velocity )
38		constant:true //use contant speed ?
39		/*
40		navigation:null,//if specified, it's a selector a collection of items to navigate the container
41		target:null, //if specified, it's a selector to the element to be scrolled.
42		interval:0, //it's the number of milliseconds to automatically go to the next
43		lazy:false,//go find the elements each time (allows AJAX or JS content, or reordering)
44		stop:false, //stop any previous animations to avoid queueing
45		force:false,//force the scroll to the first element on start ?
46		jump: false,//if true, when the event is triggered on an element, the pane scrolls to it
47		items:null, //selector to the items (relative to the matched elements)
48		prev:null, //selector to the 'prev' button
49		next:null, //selector to the 'next' button
50		onBefore: function(){}, //function called before scrolling, if it returns false, the event is ignored
51		exclude:0 //exclude the last x elements, so we cannot scroll past the end
52		*/
53	};
54
55	$.fn.serialScroll = function( settings ){
56		settings = $.extend( {}, $serialScroll.defaults, settings );
57		var event = settings.event, //this one is just to get shorter code when compressed
58			step = settings.step, // idem
59			lazy = settings.lazy;//idem
60
61		return this.each(function(){
62			var 
63				context = settings.target ? this : document, //if a target is specified, then everything's relative to 'this'.
64				$pane = $(settings.target || this, context),//the element to be scrolled (will carry all the events)
65				pane = $pane[0], //will be reused, save it into a variable
66				items = settings.items, //will hold a lazy list of elements
67				active = settings.start, //active index
68				auto = settings.interval, //boolean, do auto or not
69				nav = settings.navigation, //save it now to make the code shorter
70				timer; //holds the interval id
71
72			if( !lazy )//if not lazy, go get the items now
73				items = getItems();
74
75			if( settings.force )
76				jump( {}, active );//generate an initial call
77
78			// Button binding, optionall
79			$(settings.prev||[], context).bind( event, -step, move );
80			$(settings.next||[], context).bind( event, step, move );
81
82			// Custom events bound to the container
83			if( !pane.ssbound )//don't bind more than once
84				$pane
85					.bind('prev.serialScroll', -step, move ) //you can trigger with just 'prev'
86					.bind('next.serialScroll', step, move ) //for example: $(container).trigger('next');
87					.bind('goto.serialScroll', jump ); //for example: $(container).trigger('goto', [4] );
88			if( auto )
89				$pane
90					.bind('start.serialScroll', function(e){
91						if( !auto ){
92							clear();
93							auto = true;
94							next();
95						}
96					 })
97					.bind('stop.serialScroll', function(){//stop a current animation
98						clear();
99						auto = false;
100					});
101			$pane.bind('notify.serialScroll', function(e, elem){//let serialScroll know that the index changed externally
102				var i = index(elem);
103				if( i > -1 )
104					active = i;
105			});
106			pane.ssbound = true;//avoid many bindings
107
108			if( settings.jump )//can't use jump if using lazy items and a non-bubbling event
109				(lazy ? $pane : getItems()).bind( event, function( e ){
110					jump( e, index(e.target) );
111				});
112
113			if( nav )
114				nav = $(nav, context).bind(event, function( e ){
115					e.data = Math.round(getItems().length / nav.length) * nav.index(this);
116					jump( e, this );
117				});
118
119			function move( e ){
120				e.data += active;
121				jump( e, this );
122			};
123			function jump( e, button ){
124				if( !isNaN(button) ){//initial or special call from the outside $(container).trigger('goto',[index]);
125					e.data = button;
126					button = pane;
127				}
128
129				var
130					pos = e.data, n,
131					real = e.type, //is a real event triggering ?
132					$items = settings.exclude ? getItems().slice(0,-settings.exclude) : getItems(),//handle a possible exclude
133					limit = $items.length,
134					elem = $items[pos],
135					duration = settings.duration;
136
137				if( real )//real event object
138					e.preventDefault();
139
140				if( auto ){
141					clear();//clear any possible automatic scrolling.
142					timer = setTimeout( next, settings.interval ); 
143				}
144
145				if( !elem ){ //exceeded the limits
146					n = pos < 0 ? 0 : limit - 1;
147					if( active != n )//we exceeded for the first time
148						pos = n;
149					else if( !settings.cycle )//this is a bad case
150						return;
151					else
152						pos = limit - n - 1;//invert, go to the other side
153					elem = $items[pos];
154				}
155
156				if( !elem || real && active == pos || //could happen, save some CPU cycles in vain
157					settings.lock && $pane.is(':animated') || //no animations while busy
158					real && settings.onBefore && //callback returns false ?
159					settings.onBefore.call(button, e, elem, $pane, getItems(), pos) === false ) return;
160
161				if( settings.stop )
162					$pane.queue('fx',[]).stop();//remove all its animations
163
164				if( settings.constant )
165					duration = Math.abs(duration/step * (active - pos ));//keep constant velocity
166
167				$pane
168					.scrollTo( elem, duration, settings )//do scroll
169					.trigger('notify.serialScroll',[pos]);//in case serialScroll was called on this elem more than once.
170			};
171			function next(){//I'll use the namespace to avoid conflicts
172				$pane.trigger('next.serialScroll');
173			};
174			function clear(){
175				clearTimeout(timer);
176			};
177			function getItems(){
178				return $( items, pane );
179			};
180			function index( elem ){
181				if( !isNaN(elem) ) return elem;//number
182				var $items = getItems(), i;
183				while(( i = $items.index(elem)) == -1 && elem != pane )//see if it matches or one of its ancestors
184					elem = elem.parentNode;
185				return i;
186			};
187		});
188	};
189
190})( 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.