jScroll

jQuery Plugin for Infinite Scrolling / Auto-Paging

Από την 14/05/2016. Δείτε την τελευταία έκδοση.

Αυτός ο κώδικας δεν πρέπει να εγκατασταθεί άμεσα. Είναι μια βιβλιοθήκη για άλλους κώδικες που περιλαμβάνεται μέσω της οδηγίας meta // @require https://update.greasyfork.org/scripts/19670/125705/jScroll.js

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

/** 
 * infinitescroll - Lightweight Infinite Scrolling
 * Copyright (c) 2012 DIY Co
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 
 * file except in compliance with the License. You may obtain a copy of the License at:
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under 
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 
 * ANY KIND, either express or implied. See the License for the specific language 
 * governing permissions and limitations under the License.
 *
 * @author Brian Reavis <[email protected]>
 */

;(function($) {
	
	$.fn.infiniteScroll = function() {
		var $container = $(this);
		var $window    = $(window);
		var $body      = $('body');
		var action     = 'init';
		var waiting    = false;
		var moreExists = true;
		
		// defaults
		// -----------------------------------------------------------------------------
		var options = {
			threshold : 80,
			loadMore  : function() {},
			onEnd     : null,
			iScroll   : null
		};
		
		// parse arguments
		// -----------------------------------------------------------------------------
		if (arguments.length) {
			if (typeof arguments[0] === 'string') {
				action = arguments[0];
				if (arguments.length > 1 && typeof arguments[1] === 'object') {
					options = $.extend(options, arguments[1]);
				}
			} else if (typeof arguments[0] === 'object') {
				options = $.extend(options, arguments[0]);
			}
		}
		
		// initialize
		// -----------------------------------------------------------------------------
		if (action === 'init') {
			var onScroll = function() {
				if (waiting || !moreExists) return;
					
				var dy = options.iScroll
					? -options.iScroll.maxScrollY + options.iScroll.y
					:  $body.outerHeight() - $window.height() - $window.scrollTop();
				
				if (dy < options.threshold) {
					waiting = true;
					options.loadMore(function(more) {
						if (more === false) {
							moreExists = false;
							if (typeof options.onEnd === 'function') {
								options.onEnd();
							}
						}
						waiting = false;
					});
				}
			}
			
			if (options.iScroll) {
				// ios scrolling
				var onScrollMove = options.iScroll.options.onScrollMove || null;
				options.iScroll.options.onScrollMove = function() {
					if (onScrollMove) onScrollMove();
					onScroll();
				}
				options.iScroll_scrollMove = onScrollMove;
			} else {
				// traditional scrolling
				$window.on('scroll.infinite resize.infinite', onScroll);
			}
			
			$container.data('infinite-scroll', options);
			$(onScroll);
		}
		
		// reinitialize (for when content changes)
		// -----------------------------------------------------------------------------
		if (action === 'reset') {
			var options = $container.data('infinite-scroll');
			if (options.iScroll) {
				if (options.iScroll_scrollMove) {
					options.iScroll.options.onScrollMove = options.iScroll_scrollMove;
				}
				options.iScroll.scrollTo(0, 0, 0, false);
			}
			$window.off('scroll.infinite resize.infinite');
			$container.infiniteScroll(options);
		}
		
		return this;
	};
	
})(jQuery);