-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.waypoints-infinite-woocommerce.js
More file actions
65 lines (64 loc) · 3.07 KB
/
jquery.waypoints-infinite-woocommerce.js
File metadata and controls
65 lines (64 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
Infinite Scroll Shortcut for jQuery Waypoints, adapted for WooCommerce v.1.0.0
Copyright (c) 2011-2014 Caleb Troughton, Dennis Nißle
Licensed under the MIT license.
https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt
*/
(function() {
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
return define(['jquery', 'waypoints'], factory);
} else {
return factory(root.jQuery);
}
})(window, function($) {
var defaults;
defaults = {
container: 'auto',
items: '.infinite-item',
more: '.infinite-more-link',
offset: 'bottom-in-view',
onBeforePageLoad: $.noop,
onAfterPageLoad: $.noop
};
return $.waypoints('extendFn', 'infinite', function(options) {
var $container, opts;
opts = $.extend({}, $.fn.waypoint.defaults, defaults, options);
$container = opts.container === 'auto' ? this : $(opts.container);
opts.handler = function(direction) {
var $this;
if (direction === 'down' || direction === 'right') {
$this = $(this);
opts.onBeforePageLoad();
$this.waypoint('destroy');
if ( ! $( opts.more ).length )
opts.more = $( '.page-numbers' ).find( '.current' ).parent().next().find( 'a' );
if ( ! opts.more.attr( 'href' ) )
return false;
$container.append( '<div class="ajax-loader-wrapper"><div class="ajax-loader"></div></div>' );
return $.get(opts.more.attr('href'), function(data) {
var $data, $newMore, $nr, fn;
$data = $($.parseHTML(data));
var $oldHref = opts.more.attr('href');
opts.more = $data.find( '.page-numbers .current' ).parent().next().find( 'a' );
$nr = parseInt( $data.find( '.page-numbers .current' ).text() );
$data.find(opts.items).last().addClass( 'waypoint-page waypoint-page-' + $nr );
$data.find(opts.items).last().attr( { 'data-page': $nr, 'data-page-url': $oldHref } );
$data.find(opts.items).first().addClass( 'waypoint-page waypoint-page-' + $nr );
$data.find(opts.items).first().attr( { 'data-page': $nr, 'data-page-url': $oldHref } );
$container.append( $data.find(opts.items) );
$container.find( '.ajax-loader-wrapper' ).remove();
if (opts.more.length) {
fn = function() {
return $this.waypoint(opts);
};
setTimeout(fn, 0);
}
return opts.onAfterPageLoad( $nr, $oldHref );
});
}
};
return this.waypoint(opts);
});
});
}).call(this);