Version Description
- Adding callback function that is dispatched once a successful ajax call is made. $.fn.almComplete(alm).
- Adding WPML support for ICL_LANGUAGE_CODE - A 'lang' atributed is added dynamically if WPML is installed.
- Making JS variables and functions publically accessible.
Download this release
Release Info
Developer | dcooney |
Plugin | WordPress Infinite Scroll – Ajax Load More |
Version | 2.2.2 |
Comparing to | |
See all releases |
Code changes from version 2.2.1 to 2.2.2
- README.txt +31 -7
- admin/admin.php +2 -2
- admin/includes/cta/writeable.php +1 -1
- admin/includes/test-writable.txt +0 -1
- admin/shortcode-builder/shortcode-builder.php +1 -1
- ajax-load-more.php +10 -7
- core/js/ajax-load-more.js +134 -126
- core/js/ajax-load-more.min.js +1 -1
README.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== Ajax Load More ===
|
2 |
Contributors: dcooney
|
3 |
Donate link: http://connekthq.com/donate/
|
4 |
-
Tags: ajax, query, loop, paging, filter, jquery, shortcode builder, shortcode, search, tags, category
|
5 |
Requires at least: 3.6
|
6 |
Tested up to: 4.0
|
7 |
-
Stable tag: 2.2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -27,11 +27,11 @@ Build complex WordPress queries using our shortcode builder then add the shortco
|
|
27 |
|
28 |
Check out the **[demo site](http://connekthq.com/plugins/ajax-load-more/)** for more information!
|
29 |
|
30 |
-
|
31 |
|
32 |
= Shortcode Parameters =
|
33 |
|
34 |
-
Ajax Load More accepts a number of
|
35 |
|
36 |
* **repeater** - Choose a repeater template (Add-on available). Default = ‘default‘
|
37 |
* **post_type** - Comma separated list of post types. Default = ‘post’
|
@@ -54,7 +54,7 @@ Ajax Load More accepts a number of paramaters to pass to the WordPress query. Th
|
|
54 |
* **transition** - Choose a posts reveal transition (slide/fade). Default = 'slide'
|
55 |
* **button_label** - The label text for Load More button. Default = 'Older Posts'
|
56 |
|
57 |
-
|
58 |
|
59 |
= Example Shortcode =
|
60 |
|
@@ -63,11 +63,29 @@ Ajax Load More accepts a number of paramaters to pass to the WordPress query. Th
|
|
63 |
= Demos =
|
64 |
* **[Default](http://connekthq.com/plugins/ajax-load-more/)** - Out of the box functionality and styling
|
65 |
* **[Fade Transition](http://connekthq.com/plugins/ajax-load-more/examples/fade-transition/)** - Elements fade in as posts are loaded
|
|
|
|
|
66 |
* **[Pause Loading](http://connekthq.com/plugins/ajax-load-more/examples/pause-loading/)** - Posts will not load until initiated by the user
|
|
|
67 |
|
68 |
*The [Custom Repeater Add-On](http://connekthq.com/plugins/ajax-load-more/custom-repeaters/) has been installed for use on each of our product demos*
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
= Add-ons =
|
73 |
|
@@ -78,6 +96,7 @@ The following Add-ons are available to increase the functionality of Ajax Load M
|
|
78 |
The **[Custom Repeaters](http://connekthq.com/plugins/ajax-load-more/custom-repeaters)** add-on will add an additional five repeater templates allowing you to create unique templates for different content types throughout your theme.
|
79 |
[Get More Information](http://connekthq.com/plugins/ajax-load-more/custom-repeaters)
|
80 |
|
|
|
81 |
|
82 |
= Tested Browsers =
|
83 |
|
@@ -89,12 +108,12 @@ The **[Custom Repeaters](http://connekthq.com/plugins/ajax-load-more/custom-repe
|
|
89 |
* Android (Native + Chrome)
|
90 |
* BB10
|
91 |
|
92 |
-
|
93 |
|
94 |
= Website =
|
95 |
http://connekthq.com/ajax-load-more/
|
96 |
|
97 |
-
|
98 |
|
99 |
= Please Rate Ajax Load More! =
|
100 |
|
@@ -170,6 +189,11 @@ How to install Ajax Load More.
|
|
170 |
|
171 |
== Changelog ==
|
172 |
|
|
|
|
|
|
|
|
|
|
|
173 |
= 2.2.1 =
|
174 |
* Fixed php notice/warning that would trigger if WP_DEBUG was enabled.
|
175 |
* Adding minified core JS.
|
1 |
=== Ajax Load More ===
|
2 |
Contributors: dcooney
|
3 |
Donate link: http://connekthq.com/donate/
|
4 |
+
Tags: ajax, query, loop, paging, filter, jquery, shortcode builder, shortcode, search, tags, category, post types, taxonomy, post format, wmpl
|
5 |
Requires at least: 3.6
|
6 |
Tested up to: 4.0
|
7 |
+
Stable tag: 2.2.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
27 |
|
28 |
Check out the **[demo site](http://connekthq.com/plugins/ajax-load-more/)** for more information!
|
29 |
|
30 |
+
***
|
31 |
|
32 |
= Shortcode Parameters =
|
33 |
|
34 |
+
Ajax Load More accepts a number of parameters that are passed to the WordPress query. These parameters are transferred via shortcode - don't worry, creating your shortcode is simple with our intuitive Shortcode Builder.
|
35 |
|
36 |
* **repeater** - Choose a repeater template (Add-on available). Default = ‘default‘
|
37 |
* **post_type** - Comma separated list of post types. Default = ‘post’
|
54 |
* **transition** - Choose a posts reveal transition (slide/fade). Default = 'slide'
|
55 |
* **button_label** - The label text for Load More button. Default = 'Older Posts'
|
56 |
|
57 |
+
***
|
58 |
|
59 |
= Example Shortcode =
|
60 |
|
63 |
= Demos =
|
64 |
* **[Default](http://connekthq.com/plugins/ajax-load-more/)** - Out of the box functionality and styling
|
65 |
* **[Fade Transition](http://connekthq.com/plugins/ajax-load-more/examples/fade-transition/)** - Elements fade in as posts are loaded
|
66 |
+
* **[Mansory](http://connekthq.com/plugins/ajax-load-more/examples/masonry/)** - Creating a flexible grid layout with Masonry JS
|
67 |
+
* **[Multiple Instances](http://connekthq.com/plugins/ajax-load-more/examples/multiple-instances/)** - Include multiple Ajax Load More' on a single page
|
68 |
* **[Pause Loading](http://connekthq.com/plugins/ajax-load-more/examples/pause-loading/)** - Posts will not load until initiated by the user
|
69 |
+
* **[Search Results](http://connekthq.com/plugins/ajax-load-more/examples/search-results/)** - Returning results based on search terms
|
70 |
|
71 |
*The [Custom Repeater Add-On](http://connekthq.com/plugins/ajax-load-more/custom-repeaters/) has been installed for use on each of our product demos*
|
72 |
|
73 |
+
***
|
74 |
+
|
75 |
+
= Callback Functions =
|
76 |
+
The following functions are avaialble to be dispatched by Ajax Load More.
|
77 |
+
|
78 |
+
|
79 |
+
**Ajax Complete**
|
80 |
|
81 |
+
The almComplete() function is triggered after every *successful* ajax call made by Ajax Load More.
|
82 |
+
To utilize the almComplete() function simply place the following code inside your sites javascript file.
|
83 |
+
|
84 |
+
$.fn.almComplete = function(alm){
|
85 |
+
// Your on complete code goes here
|
86 |
+
}
|
87 |
+
|
88 |
+
***
|
89 |
|
90 |
= Add-ons =
|
91 |
|
96 |
The **[Custom Repeaters](http://connekthq.com/plugins/ajax-load-more/custom-repeaters)** add-on will add an additional five repeater templates allowing you to create unique templates for different content types throughout your theme.
|
97 |
[Get More Information](http://connekthq.com/plugins/ajax-load-more/custom-repeaters)
|
98 |
|
99 |
+
***
|
100 |
|
101 |
= Tested Browsers =
|
102 |
|
108 |
* Android (Native + Chrome)
|
109 |
* BB10
|
110 |
|
111 |
+
***
|
112 |
|
113 |
= Website =
|
114 |
http://connekthq.com/ajax-load-more/
|
115 |
|
116 |
+
***
|
117 |
|
118 |
= Please Rate Ajax Load More! =
|
119 |
|
189 |
|
190 |
== Changelog ==
|
191 |
|
192 |
+
= 2.2.2 =
|
193 |
+
* Adding callback function that is dispatched once a successful ajax call is made. $.fn.almComplete(alm).
|
194 |
+
* Adding WPML support for ICL_LANGUAGE_CODE - A 'lang' atributed is added dynamically if WPML is installed.
|
195 |
+
* Making JS variables and functions publically accessible.
|
196 |
+
|
197 |
= 2.2.1 =
|
198 |
* Fixed php notice/warning that would trigger if WP_DEBUG was enabled.
|
199 |
* Adding minified core JS.
|
admin/admin.php
CHANGED
@@ -281,7 +281,7 @@ function alm_repeater_page(){ ?>
|
|
281 |
<?php
|
282 |
if (!has_action('alm_get_custom_repeaters')) {
|
283 |
echo '<div class="row no-brd">';
|
284 |
-
include( ALM_PATH. 'admin/includes/cta/extend.php');
|
285 |
echo '</div>';
|
286 |
}
|
287 |
?>
|
@@ -793,7 +793,7 @@ function alm_hide_btn_callback(){
|
|
793 |
$options['_alm_hide_btn'] = '0';
|
794 |
|
795 |
echo '<input type="hidden" name="alm_settings[_alm_hide_btn]" value="0" />
|
796 |
-
<label><input type="checkbox" name="alm_settings[_alm_hide_btn]" value="1"'. (($options['_alm_hide_btn']) ? ' checked="checked"' : '') .' /> '.__('Hide shortcode button in WYSIWYG editor', ALM_NAME).'
|
797 |
}
|
798 |
|
799 |
|
281 |
<?php
|
282 |
if (!has_action('alm_get_custom_repeaters')) {
|
283 |
echo '<div class="row no-brd">';
|
284 |
+
include( ALM_PATH . 'admin/includes/cta/extend.php');
|
285 |
echo '</div>';
|
286 |
}
|
287 |
?>
|
793 |
$options['_alm_hide_btn'] = '0';
|
794 |
|
795 |
echo '<input type="hidden" name="alm_settings[_alm_hide_btn]" value="0" />
|
796 |
+
<label><input type="checkbox" name="alm_settings[_alm_hide_btn]" value="1"'. (($options['_alm_hide_btn']) ? ' checked="checked"' : '') .' /> '.__('Hide shortcode button in WYSIWYG editor', ALM_NAME).'</label>';
|
797 |
}
|
798 |
|
799 |
|
admin/includes/cta/writeable.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<div class="item">
|
4 |
<?php
|
5 |
//Test server for write capabilities
|
6 |
-
$filename = ALM_PATH .'
|
7 |
if (is_writable($filename))
|
8 |
echo '<p><i class="fa fa-check"></i><strong>'.__('Write Access Enabled!').'</strong></p><p class="desc">Good news! Your server is configured to read and write files within the plugin directory.';
|
9 |
else
|
3 |
<div class="item">
|
4 |
<?php
|
5 |
//Test server for write capabilities
|
6 |
+
$filename = ALM_PATH .'core/repeater/default.php';
|
7 |
if (is_writable($filename))
|
8 |
echo '<p><i class="fa fa-check"></i><strong>'.__('Write Access Enabled!').'</strong></p><p class="desc">Good news! Your server is configured to read and write files within the plugin directory.';
|
9 |
else
|
admin/includes/test-writable.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
test.txt
|
|
admin/shortcode-builder/shortcode-builder.php
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
|
21 |
echo '</div></div>';
|
22 |
if (!has_action('alm_get_custom_repeaters')) {
|
23 |
-
include( 'cta/extend.php');
|
24 |
}
|
25 |
echo '</div>';
|
26 |
echo '</div>';
|
20 |
|
21 |
echo '</div></div>';
|
22 |
if (!has_action('alm_get_custom_repeaters')) {
|
23 |
+
include( ALM_PATH . 'admin/includes/cta/extend.php');
|
24 |
}
|
25 |
echo '</div>';
|
26 |
echo '</div>';
|
ajax-load-more.php
CHANGED
@@ -6,14 +6,14 @@ Description: A simple solution for lazy loading WordPress posts and pages with A
|
|
6 |
Author: Darren Cooney
|
7 |
Twitter: @KaptonKaos
|
8 |
Author URI: http://connekthq.com
|
9 |
-
Version: 2.2.
|
10 |
License: GPL
|
11 |
Copyright: Darren Cooney & Connekt Media
|
12 |
*/
|
13 |
|
14 |
|
15 |
-
define('ALM_VERSION', '2.2.
|
16 |
-
define('ALM_RELEASE', 'September
|
17 |
|
18 |
/*
|
19 |
* alm_install
|
@@ -174,8 +174,10 @@ if( !class_exists('AjaxLoadMore') ):
|
|
174 |
$btn_color = ' '.$options['_alm_btn_color'];
|
175 |
}
|
176 |
|
|
|
|
|
177 |
$ajaxloadmore = '<div id="ajax-load-more" class="ajax-load-more-wrap '. $btn_color .'">';
|
178 |
-
$ajaxloadmore .= '<'.$container_element.' class="alm-listing'. $classname . '" data-repeater="'.$repeater.'" data-post-type="'.$post_type.'" data-post-format="'.$post_format.'" data-category="'.$category.'" data-taxonomy="'.$taxonomy.'" data-taxonomy-terms="'.$taxonomy_terms.'" data-taxonomy-operator="'.$taxonomy_operator.'" data-tag="'.$tag.'" data-author="'.$author.'" data-search="'.$search.'" data-order="'.$order.'" data-orderby="'.$orderby.'" data-exclude="'.$exclude.'" data-offset="'.$offset.'" data-posts-per-page="'.$posts_per_page.'" data-scroll="'.$scroll.'" data-max-pages="'.$max_pages.'" data-pause="'. $pause .'" data-button-label="'.$button_label.'" data-transition="'.$transition.'"></'.$container_element.'>';
|
179 |
$ajaxloadmore .= '</div>';
|
180 |
|
181 |
return $ajaxloadmore;
|
@@ -219,8 +221,8 @@ if( !class_exists('AjaxLoadMore') ):
|
|
219 |
$exclude = (isset($_GET['exclude'])) ? $_GET['exclude'] : '';
|
220 |
$numPosts = (isset($_GET['numPosts'])) ? $_GET['numPosts'] : 6;
|
221 |
$page = (isset($_GET['pageNumber'])) ? $_GET['pageNumber'] : 0;
|
222 |
-
$offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
|
223 |
-
|
224 |
|
225 |
// Set up initial args
|
226 |
|
@@ -233,7 +235,8 @@ if( !class_exists('AjaxLoadMore') ):
|
|
233 |
'offset' => $offset + ($numPosts*$page),
|
234 |
's' => $s,
|
235 |
'order' => $order,
|
236 |
-
'orderby' => $orderby,
|
|
|
237 |
'post_status' => 'publish',
|
238 |
'ignore_sticky_posts' => false,
|
239 |
);
|
6 |
Author: Darren Cooney
|
7 |
Twitter: @KaptonKaos
|
8 |
Author URI: http://connekthq.com
|
9 |
+
Version: 2.2.2
|
10 |
License: GPL
|
11 |
Copyright: Darren Cooney & Connekt Media
|
12 |
*/
|
13 |
|
14 |
|
15 |
+
define('ALM_VERSION', '2.2.2');
|
16 |
+
define('ALM_RELEASE', 'September 23, 2014');
|
17 |
|
18 |
/*
|
19 |
* alm_install
|
174 |
$btn_color = ' '.$options['_alm_btn_color'];
|
175 |
}
|
176 |
|
177 |
+
$lang = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : '';
|
178 |
+
|
179 |
$ajaxloadmore = '<div id="ajax-load-more" class="ajax-load-more-wrap '. $btn_color .'">';
|
180 |
+
$ajaxloadmore .= '<'.$container_element.' class="alm-listing'. $classname . '" data-repeater="'.$repeater.'" data-post-type="'.$post_type.'" data-post-format="'.$post_format.'" data-category="'.$category.'" data-taxonomy="'.$taxonomy.'" data-taxonomy-terms="'.$taxonomy_terms.'" data-taxonomy-operator="'.$taxonomy_operator.'" data-tag="'.$tag.'" data-author="'.$author.'" data-search="'.$search.'" data-order="'.$order.'" data-orderby="'.$orderby.'" data-exclude="'.$exclude.'" data-offset="'.$offset.'" data-posts-per-page="'.$posts_per_page.'" data-lang="'.$lang.'" data-scroll="'.$scroll.'" data-max-pages="'.$max_pages.'" data-pause="'. $pause .'" data-button-label="'.$button_label.'" data-transition="'.$transition.'"></'.$container_element.'>';
|
181 |
$ajaxloadmore .= '</div>';
|
182 |
|
183 |
return $ajaxloadmore;
|
221 |
$exclude = (isset($_GET['exclude'])) ? $_GET['exclude'] : '';
|
222 |
$numPosts = (isset($_GET['numPosts'])) ? $_GET['numPosts'] : 6;
|
223 |
$page = (isset($_GET['pageNumber'])) ? $_GET['pageNumber'] : 0;
|
224 |
+
$offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
|
225 |
+
$lang = (isset($_GET['lang'])) ? $_GET['lang'] : '';
|
226 |
|
227 |
// Set up initial args
|
228 |
|
235 |
'offset' => $offset + ($numPosts*$page),
|
236 |
's' => $s,
|
237 |
'order' => $order,
|
238 |
+
'orderby' => $orderby,
|
239 |
+
'lang' => $lang,
|
240 |
'post_status' => 'publish',
|
241 |
'ignore_sticky_posts' => false,
|
242 |
);
|
core/js/ajax-load-more.js
CHANGED
@@ -15,167 +15,175 @@
|
|
15 |
"use strict";
|
16 |
$.ajaxloadmore = function(el) {
|
17 |
//Set variables
|
18 |
-
var
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
38 |
|
39 |
$(window).scrollTop(0); //Prevent loading of unnessasry posts - move user to top of page
|
40 |
|
41 |
// Check for pause on init
|
42 |
// Pause could be used to hold the loading of posts for a button click.
|
43 |
-
if (
|
44 |
-
|
45 |
}
|
46 |
|
47 |
// Select the repeater template
|
48 |
-
if (
|
49 |
-
|
50 |
}
|
51 |
|
52 |
// Max number of pages to load while scrolling
|
53 |
-
if (
|
54 |
-
|
55 |
}
|
56 |
-
if (
|
57 |
-
|
58 |
}
|
59 |
|
60 |
// select the transition
|
61 |
-
if (
|
62 |
-
|
63 |
-
} else if (
|
64 |
-
|
65 |
} else {
|
66 |
-
|
67 |
}
|
68 |
|
69 |
// Define offset
|
70 |
-
if (
|
71 |
-
|
72 |
} else {
|
73 |
-
|
74 |
}
|
75 |
|
76 |
// Define button text
|
77 |
-
if (
|
78 |
-
|
79 |
} else {
|
80 |
-
|
81 |
}
|
82 |
|
83 |
// Define on Scroll event
|
84 |
-
if (
|
85 |
-
|
86 |
-
} else if (
|
87 |
-
|
88 |
} else {
|
89 |
-
|
90 |
}
|
91 |
|
92 |
// Parse multiple Post Types
|
93 |
-
|
94 |
-
|
95 |
|
96 |
// Append 'load More' button to .ajax-load-more-wrap
|
97 |
-
|
98 |
-
|
99 |
|
100 |
|
101 |
-
/*
|
102 |
*
|
103 |
* The function to get posts via Ajax
|
104 |
* @since 2.0.0
|
105 |
*/
|
106 |
-
AjaxLoadMore.loadPosts = function() {
|
107 |
-
|
108 |
-
|
109 |
$.ajax({
|
110 |
type: "GET",
|
111 |
url: alm_localize.ajaxurl,
|
112 |
data: {
|
113 |
action: 'ajax_load_more_init',
|
114 |
nonce: alm_localize.alm_nonce,
|
115 |
-
repeater:
|
116 |
-
postType:
|
117 |
-
postFormat:
|
118 |
-
category:
|
119 |
-
author:
|
120 |
-
taxonomy:
|
121 |
-
taxonomy_terms:
|
122 |
-
taxonomy_operator:
|
123 |
-
tag:
|
124 |
-
order:
|
125 |
-
orderby:
|
126 |
-
search:
|
127 |
-
exclude:
|
128 |
-
numPosts:
|
129 |
-
pageNumber: page,
|
130 |
-
offset:
|
|
|
131 |
},
|
132 |
dataType: "html",
|
133 |
// parse the data as html
|
134 |
beforeSend: function() {
|
135 |
-
if (page != 1) {
|
136 |
-
|
137 |
}
|
138 |
},
|
139 |
success: function(data) {
|
140 |
-
|
141 |
-
//console.log(
|
142 |
-
if (
|
143 |
-
|
144 |
-
|
145 |
}
|
146 |
-
if (
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
if (
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
if (
|
156 |
-
|
157 |
-
|
158 |
}
|
159 |
});
|
160 |
} else { // Slide transition
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
if (
|
165 |
-
|
166 |
-
|
167 |
}
|
168 |
});
|
169 |
}
|
|
|
|
|
|
|
|
|
|
|
170 |
} else {
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
}
|
175 |
},
|
176 |
error: function(jqXHR, textStatus, errorThrown) {
|
177 |
-
|
178 |
-
|
179 |
}
|
180 |
});
|
181 |
};
|
@@ -186,15 +194,15 @@
|
|
186 |
* Load more button click event
|
187 |
* @since 1.0.0
|
188 |
*/
|
189 |
-
|
190 |
-
if(
|
191 |
-
|
192 |
-
AjaxLoadMore.loadPosts();
|
193 |
}
|
194 |
-
if (
|
195 |
-
|
196 |
-
page++;
|
197 |
-
AjaxLoadMore.loadPosts();
|
198 |
}
|
199 |
});
|
200 |
|
@@ -204,12 +212,12 @@
|
|
204 |
* Check to see if element is visible before loading posts
|
205 |
* @since 2.1.2
|
206 |
*/
|
207 |
-
AjaxLoadMore.isVisible = function(){
|
208 |
-
|
209 |
-
if(
|
210 |
-
visible = true;
|
211 |
}
|
212 |
-
return visible;
|
213 |
};
|
214 |
|
215 |
|
@@ -218,14 +226,14 @@
|
|
218 |
* Load posts as user scrolls the page
|
219 |
* @since 1.0
|
220 |
*/
|
221 |
-
if (
|
222 |
-
|
223 |
-
if(AjaxLoadMore.isVisible()){
|
224 |
-
var content_offset =
|
225 |
-
if (
|
226 |
-
|
227 |
-
page++;
|
228 |
-
AjaxLoadMore.loadPosts();
|
229 |
}
|
230 |
}
|
231 |
});
|
@@ -233,17 +241,17 @@
|
|
233 |
|
234 |
|
235 |
//Check for pause variable
|
236 |
-
if(
|
237 |
-
|
238 |
-
|
239 |
}else{
|
240 |
-
AjaxLoadMore.loadPosts();
|
241 |
}
|
242 |
|
243 |
|
244 |
//flag to prevent unnecessary loading of post on init. Hold for 1 second
|
245 |
setTimeout(function() {
|
246 |
-
proceed = true;
|
247 |
}, 1000);
|
248 |
|
249 |
|
@@ -264,9 +272,9 @@
|
|
264 |
*/
|
265 |
$.fn.ajaxloadmore = function() {
|
266 |
return this.each(function() {
|
267 |
-
$.ajaxloadmore($(this));
|
268 |
});
|
269 |
-
}
|
270 |
|
271 |
/*
|
272 |
* Initiate Ajax load More if div is present on screen
|
15 |
"use strict";
|
16 |
$.ajaxloadmore = function(el) {
|
17 |
//Set variables
|
18 |
+
var alm = this;
|
19 |
+
alm.AjaxLoadMore = {};
|
20 |
+
alm.page = 0;
|
21 |
+
alm.speed = 300;
|
22 |
+
alm.proceed = false;
|
23 |
+
alm.init = true;
|
24 |
+
alm.loading = true;
|
25 |
+
alm.finished = false;
|
26 |
+
alm.window = $(window);
|
27 |
+
alm.button_label = '';
|
28 |
+
alm.data;
|
29 |
+
alm.el = el;
|
30 |
+
alm.content = $('.alm-listing', alm.el);
|
31 |
+
alm.scroll = true;
|
32 |
+
alm.prefix = 'alm-';
|
33 |
+
alm.repeater = alm.content.data('repeater');
|
34 |
+
alm.max_pages = alm.content.data('max-pages');
|
35 |
+
alm.pause = alm.content.data('pause');
|
36 |
+
alm.offset = alm.content.data('offset');
|
37 |
+
alm.transition = alm.content.data('transition');
|
38 |
+
alm.lang = alm.content.data('lang'),
|
39 |
+
alm.posts_per_page = alm.content.data('posts-per-page');
|
40 |
|
41 |
$(window).scrollTop(0); //Prevent loading of unnessasry posts - move user to top of page
|
42 |
|
43 |
// Check for pause on init
|
44 |
// Pause could be used to hold the loading of posts for a button click.
|
45 |
+
if (alm.pause === undefined) {
|
46 |
+
alm.pause = false;
|
47 |
}
|
48 |
|
49 |
// Select the repeater template
|
50 |
+
if (alm.repeater === undefined) {
|
51 |
+
alm.repeater = 'default';
|
52 |
}
|
53 |
|
54 |
// Max number of pages to load while scrolling
|
55 |
+
if (alm.max_pages === undefined) {
|
56 |
+
alm.max_pages = 5;
|
57 |
}
|
58 |
+
if (alm.max_pages === 'none') {
|
59 |
+
alm.max_pages = 1000000;
|
60 |
}
|
61 |
|
62 |
// select the transition
|
63 |
+
if (alm.transition === undefined) {
|
64 |
+
alm.transition = 'slide';
|
65 |
+
} else if (alm.transition === "fade") {
|
66 |
+
alm.transition = 'fade';
|
67 |
} else {
|
68 |
+
alm.transition = 'slide';
|
69 |
}
|
70 |
|
71 |
// Define offset
|
72 |
+
if (alm.content.data('offset') === undefined) {
|
73 |
+
alm.offset = 0;
|
74 |
} else {
|
75 |
+
alm.offset = alm.content.data('offset');
|
76 |
}
|
77 |
|
78 |
// Define button text
|
79 |
+
if (alm.content.data('button-label') === undefined) {
|
80 |
+
alm.button_label = 'Older Posts';
|
81 |
} else {
|
82 |
+
alm.button_label = alm.content.data('button-label');
|
83 |
}
|
84 |
|
85 |
// Define on Scroll event
|
86 |
+
if (alm.content.data('scroll') === undefined) {
|
87 |
+
alm.scroll = true;
|
88 |
+
} else if (alm.content.data('scroll') === false) {
|
89 |
+
alm.scroll = false;
|
90 |
} else {
|
91 |
+
alm.scroll = true;
|
92 |
}
|
93 |
|
94 |
// Parse multiple Post Types
|
95 |
+
alm.post_type = alm.content.data('post-type');
|
96 |
+
alm.post_type = alm.post_type.split(",");
|
97 |
|
98 |
// Append 'load More' button to .ajax-load-more-wrap
|
99 |
+
alm.el.append('<div class="'+alm.prefix+'btn-wrap"><button id="load-more" class="'+alm.prefix+'load-more-btn more">' + alm.button_label + '</button></div>');
|
100 |
+
alm.button = $('.alm-load-more-btn', alm.el);
|
101 |
|
102 |
|
103 |
+
/* loadPosts()
|
104 |
*
|
105 |
* The function to get posts via Ajax
|
106 |
* @since 2.0.0
|
107 |
*/
|
108 |
+
alm.AjaxLoadMore.loadPosts = function() {
|
109 |
+
alm.button.addClass('loading');
|
110 |
+
alm.loading = true;
|
111 |
$.ajax({
|
112 |
type: "GET",
|
113 |
url: alm_localize.ajaxurl,
|
114 |
data: {
|
115 |
action: 'ajax_load_more_init',
|
116 |
nonce: alm_localize.alm_nonce,
|
117 |
+
repeater: alm.repeater,
|
118 |
+
postType: alm.post_type,
|
119 |
+
postFormat: alm.content.data('post-format'),
|
120 |
+
category: alm.content.data('category'),
|
121 |
+
author: alm.content.data('author'),
|
122 |
+
taxonomy: alm.content.data('taxonomy'),
|
123 |
+
taxonomy_terms: alm.content.data('taxonomy-terms'),
|
124 |
+
taxonomy_operator: alm.content.data('taxonomy-operator'),
|
125 |
+
tag: alm.content.data('tag'),
|
126 |
+
order: alm.content.data('order'),
|
127 |
+
orderby: alm.content.data('orderby'),
|
128 |
+
search: alm.content.data('search'),
|
129 |
+
exclude: alm.content.data('exclude'),
|
130 |
+
numPosts: alm.content.data('posts-per-page'),
|
131 |
+
pageNumber: alm.page,
|
132 |
+
offset: alm.offset,
|
133 |
+
lang: alm.lang
|
134 |
},
|
135 |
dataType: "html",
|
136 |
// parse the data as html
|
137 |
beforeSend: function() {
|
138 |
+
if (alm.page != 1) {
|
139 |
+
alm.button.addClass('loading');
|
140 |
}
|
141 |
},
|
142 |
success: function(data) {
|
143 |
+
alm.data = $(data); // Convert data to an object
|
144 |
+
//console.log(alm.data.length);
|
145 |
+
if (alm.init) {
|
146 |
+
alm.button.text(alm.button_label);
|
147 |
+
alm.init = false;
|
148 |
}
|
149 |
+
if (alm.data.length > 0) {
|
150 |
+
alm.el = $('<div class="' + alm.prefix + 'reveal"/>');
|
151 |
+
alm.el.append(alm.data);
|
152 |
+
alm.el.hide();
|
153 |
+
alm.content.append(alm.el);
|
154 |
+
if (alm.transition === 'fade') { // Fade transition
|
155 |
+
alm.el.fadeIn(alm.speed, 'alm_easeInOutQuad', function() {
|
156 |
+
alm.loading = false;
|
157 |
+
alm.button.delay(alm.speed).removeClass('loading');
|
158 |
+
if (alm.data.length < alm.posts_per_page) {
|
159 |
+
alm.finished = true;
|
160 |
+
alm.button.addClass('done');
|
161 |
}
|
162 |
});
|
163 |
} else { // Slide transition
|
164 |
+
alm.el.slideDown(alm.speed, 'alm_easeInOutQuad', function() {
|
165 |
+
alm.loading = false;
|
166 |
+
alm.button.delay(alm.speed).removeClass('loading');
|
167 |
+
if (alm.data.length < alm.posts_per_page) {
|
168 |
+
alm.finished = true;
|
169 |
+
alm.button.addClass('done');
|
170 |
}
|
171 |
});
|
172 |
}
|
173 |
+
|
174 |
+
if ($.isFunction($.fn.almComplete)) {
|
175 |
+
$.fn.almComplete(alm);
|
176 |
+
}
|
177 |
+
|
178 |
} else {
|
179 |
+
alm.button.delay(alm.speed).removeClass('loading').addClass('done');
|
180 |
+
alm.loading = false;
|
181 |
+
alm.finished = true;
|
182 |
}
|
183 |
},
|
184 |
error: function(jqXHR, textStatus, errorThrown) {
|
185 |
+
alm.loading = false;
|
186 |
+
alm.button.removeClass('loading');
|
187 |
}
|
188 |
});
|
189 |
};
|
194 |
* Load more button click event
|
195 |
* @since 1.0.0
|
196 |
*/
|
197 |
+
alm.button.on('click', function() {
|
198 |
+
if(alm.pause === true){
|
199 |
+
alm.pause = false;
|
200 |
+
alm.AjaxLoadMore.loadPosts();
|
201 |
}
|
202 |
+
if (!alm.loading && !alm.finished && !$(this).hasClass('done')) {
|
203 |
+
alm.loading = true;
|
204 |
+
alm.page++;
|
205 |
+
alm.AjaxLoadMore.loadPosts();
|
206 |
}
|
207 |
});
|
208 |
|
212 |
* Check to see if element is visible before loading posts
|
213 |
* @since 2.1.2
|
214 |
*/
|
215 |
+
alm.AjaxLoadMore.isVisible = function(){
|
216 |
+
alm.visible = false;
|
217 |
+
if(alm.el.is(":visible")){
|
218 |
+
alm.visible = true;
|
219 |
}
|
220 |
+
return alm.visible;
|
221 |
};
|
222 |
|
223 |
|
226 |
* Load posts as user scrolls the page
|
227 |
* @since 1.0
|
228 |
*/
|
229 |
+
if (alm.scroll) {
|
230 |
+
alm.window.bind("scroll touchstart", function() {
|
231 |
+
if(alm.AjaxLoadMore.isVisible()){
|
232 |
+
var content_offset = alm.button.offset();
|
233 |
+
if (!alm.loading && !alm.finished && alm.window.scrollTop() >= Math.round(content_offset.top - (alm.window.height() - 150)) && alm.page < (alm.max_pages - 1) && alm.proceed) {
|
234 |
+
alm.loading = true;
|
235 |
+
alm.page++;
|
236 |
+
alm.AjaxLoadMore.loadPosts();
|
237 |
}
|
238 |
}
|
239 |
});
|
241 |
|
242 |
|
243 |
//Check for pause variable
|
244 |
+
if(alm.pause === true){
|
245 |
+
alm.button.text(alm.button_label);
|
246 |
+
alm.loading = false;
|
247 |
}else{
|
248 |
+
alm.AjaxLoadMore.loadPosts();
|
249 |
}
|
250 |
|
251 |
|
252 |
//flag to prevent unnecessary loading of post on init. Hold for 1 second
|
253 |
setTimeout(function() {
|
254 |
+
alm.proceed = true;
|
255 |
}, 1000);
|
256 |
|
257 |
|
272 |
*/
|
273 |
$.fn.ajaxloadmore = function() {
|
274 |
return this.each(function() {
|
275 |
+
$(this).data('alm', new $.ajaxloadmore($(this)));
|
276 |
});
|
277 |
+
}
|
278 |
|
279 |
/*
|
280 |
* Initiate Ajax load More if div is present on screen
|
core/js/ajax-load-more.min.js
CHANGED
@@ -11,4 +11,4 @@
|
|
11 |
* Twitter: @KaptonKaos
|
12 |
*/
|
13 |
|
14 |
-
(function(e){"use strict";e.ajaxloadmore=function(t){var n={}
|
11 |
* Twitter: @KaptonKaos
|
12 |
*/
|
13 |
|
14 |
+
(function(e){"use strict";e.ajaxloadmore=function(t){var n=this;n.AjaxLoadMore={};n.page=0;n.speed=300;n.proceed=false;n.init=true;n.loading=true;n.finished=false;n.window=e(window);n.button_label="";n.data;n.el=t;n.content=e(".alm-listing",n.el);n.scroll=true;n.prefix="alm-";n.repeater=n.content.data("repeater");n.max_pages=n.content.data("max-pages");n.pause=n.content.data("pause");n.offset=n.content.data("offset");n.transition=n.content.data("transition");n.lang=n.content.data("lang"),n.posts_per_page=n.content.data("posts-per-page");e(window).scrollTop(0);if(n.pause===undefined){n.pause=false}if(n.repeater===undefined){n.repeater="default"}if(n.max_pages===undefined){n.max_pages=5}if(n.max_pages==="none"){n.max_pages=1e6}if(n.transition===undefined){n.transition="slide"}else if(n.transition==="fade"){n.transition="fade"}else{n.transition="slide"}if(n.content.data("offset")===undefined){n.offset=0}else{n.offset=n.content.data("offset")}if(n.content.data("button-label")===undefined){n.button_label="Older Posts"}else{n.button_label=n.content.data("button-label")}if(n.content.data("scroll")===undefined){n.scroll=true}else if(n.content.data("scroll")===false){n.scroll=false}else{n.scroll=true}n.post_type=n.content.data("post-type");n.post_type=n.post_type.split(",");n.el.append('<div class="'+n.prefix+'btn-wrap"><button id="load-more" class="'+n.prefix+'load-more-btn more">'+n.button_label+"</button></div>");n.button=e(".alm-load-more-btn",n.el);n.AjaxLoadMore.loadPosts=function(){n.button.addClass("loading");n.loading=true;e.ajax({type:"GET",url:alm_localize.ajaxurl,data:{action:"ajax_load_more_init",nonce:alm_localize.alm_nonce,repeater:n.repeater,postType:n.post_type,postFormat:n.content.data("post-format"),category:n.content.data("category"),author:n.content.data("author"),taxonomy:n.content.data("taxonomy"),taxonomy_terms:n.content.data("taxonomy-terms"),taxonomy_operator:n.content.data("taxonomy-operator"),tag:n.content.data("tag"),order:n.content.data("order"),orderby:n.content.data("orderby"),search:n.content.data("search"),exclude:n.content.data("exclude"),numPosts:n.content.data("posts-per-page"),pageNumber:n.page,offset:n.offset,lang:n.lang},dataType:"html",beforeSend:function(){if(n.page!=1){n.button.addClass("loading")}},success:function(t){n.data=e(t);if(n.init){n.button.text(n.button_label);n.init=false}if(n.data.length>0){n.el=e('<div class="'+n.prefix+'reveal"/>');n.el.append(n.data);n.el.hide();n.content.append(n.el);if(n.transition==="fade"){n.el.fadeIn(n.speed,"alm_easeInOutQuad",function(){n.loading=false;n.button.delay(n.speed).removeClass("loading");if(n.data.length<n.posts_per_page){n.finished=true;n.button.addClass("done")}})}else{n.el.slideDown(n.speed,"alm_easeInOutQuad",function(){n.loading=false;n.button.delay(n.speed).removeClass("loading");if(n.data.length<n.posts_per_page){n.finished=true;n.button.addClass("done")}})}if(e.isFunction(e.fn.almComplete)){e.fn.almComplete(n)}}else{n.button.delay(n.speed).removeClass("loading").addClass("done");n.loading=false;n.finished=true}},error:function(e,t,r){n.loading=false;n.button.removeClass("loading")}})};n.button.on("click",function(){if(n.pause===true){n.pause=false;n.AjaxLoadMore.loadPosts()}if(!n.loading&&!n.finished&&!e(this).hasClass("done")){n.loading=true;n.page++;n.AjaxLoadMore.loadPosts()}});n.AjaxLoadMore.isVisible=function(){n.visible=false;if(n.el.is(":visible")){n.visible=true}return n.visible};if(n.scroll){n.window.bind("scroll touchstart",function(){if(n.AjaxLoadMore.isVisible()){var e=n.button.offset();if(!n.loading&&!n.finished&&n.window.scrollTop()>=Math.round(e.top-(n.window.height()-150))&&n.page<n.max_pages-1&&n.proceed){n.loading=true;n.page++;n.AjaxLoadMore.loadPosts()}}})}if(n.pause===true){n.button.text(n.button_label);n.loading=false}else{n.AjaxLoadMore.loadPosts()}setTimeout(function(){n.proceed=true},1e3);e.easing.alm_easeInOutQuad=function(e,t,n,r,i){if((t/=i/2)<1)return r/2*t*t+n;return-r/2*(--t*(t-2)-1)+n}};e.fn.ajaxloadmore=function(){return this.each(function(){e(this).data("alm",new e.ajaxloadmore(e(this)))})};if(e(".ajax-load-more-wrap").length)e(".ajax-load-more-wrap").ajaxloadmore()})(jQuery)
|