WordPress Infinite Scroll – Ajax Load More - Version 2.2.2

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 Icon 128x128 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 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.1
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 paramaters to pass to the WordPress query. These parameters are passed via shortcode - don't worry, creating your shortcode is simple with our 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,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).'<p class="desc"></p></label>';
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 .'admin/includes/test-writable.txt';
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.1
10
  License: GPL
11
  Copyright: Darren Cooney & Connekt Media
12
  */
13
 
14
 
15
- define('ALM_VERSION', '2.2.1');
16
- define('ALM_RELEASE', 'September 11, 2014');
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 AjaxLoadMore = {},
19
- page = 0,
20
- speed = 300,
21
- proceed = false,
22
- $init = true,
23
- $loading = true,
24
- $finished = false,
25
- $window = $(window),
26
- $button_label = '',
27
- $data,
28
- $el = el,
29
- $content = $('.alm-listing', $el),
30
- $scroll = true,
31
- $prefix = 'alm-',
32
- $repeater = $content.data('repeater'),
33
- $max_pages = $content.data('max-pages'),
34
- $pause = $content.data('pause'),
35
- $offset = $content.data('offset'),
36
- $transition = $content.data('transition'),
37
- $posts_per_page = $content.data('posts-per-page');
 
 
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 ($pause === undefined) {
44
- $pause = false;
45
  }
46
 
47
  // Select the repeater template
48
- if ($repeater === undefined) {
49
- $repeater = 'default';
50
  }
51
 
52
  // Max number of pages to load while scrolling
53
- if ($max_pages === undefined) {
54
- $max_pages = 5;
55
  }
56
- if ($max_pages === 'none') {
57
- $max_pages = 1000000;
58
  }
59
 
60
  // select the transition
61
- if ($transition === undefined) {
62
- $transition = 'slide';
63
- } else if ($transition === "fade") {
64
- $transition = 'fade';
65
  } else {
66
- $transition = 'slide';
67
  }
68
 
69
  // Define offset
70
- if ($content.data('offset') === undefined) {
71
- $offset = 0;
72
  } else {
73
- $offset = $content.data('offset');
74
  }
75
 
76
  // Define button text
77
- if ($content.data('button-label') === undefined) {
78
- $button_label = 'Older Posts';
79
  } else {
80
- $button_label = $content.data('button-label');
81
  }
82
 
83
  // Define on Scroll event
84
- if ($content.data('scroll') === undefined) {
85
- $scroll = true;
86
- } else if ($content.data('scroll') === false) {
87
- $scroll = false;
88
  } else {
89
- $scroll = true;
90
  }
91
 
92
  // Parse multiple Post Types
93
- var $post_type = $content.data('post-type');
94
- $post_type = $post_type.split(",");
95
 
96
  // Append 'load More' button to .ajax-load-more-wrap
97
- $el.append('<div class="'+$prefix+'btn-wrap"><button id="load-more" class="'+$prefix+'load-more-btn more">' + $button_label + '</button></div>');
98
- var $button = $('.alm-load-more-btn', $el);
99
 
100
 
101
- /* AjaxLoadMore.loadPosts()
102
  *
103
  * The function to get posts via Ajax
104
  * @since 2.0.0
105
  */
106
- AjaxLoadMore.loadPosts = function() {
107
- $button.addClass('loading');
108
- $loading = true;
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: $repeater,
116
- postType: $post_type,
117
- postFormat: $content.data('post-format'),
118
- category: $content.data('category'),
119
- author: $content.data('author'),
120
- taxonomy: $content.data('taxonomy'),
121
- taxonomy_terms: $content.data('taxonomy-terms'),
122
- taxonomy_operator: $content.data('taxonomy-operator'),
123
- tag: $content.data('tag'),
124
- order: $content.data('order'),
125
- orderby: $content.data('orderby'),
126
- search: $content.data('search'),
127
- exclude: $content.data('exclude'),
128
- numPosts: $content.data('posts-per-page'),
129
- pageNumber: page,
130
- offset: $offset
 
131
  },
132
  dataType: "html",
133
  // parse the data as html
134
  beforeSend: function() {
135
- if (page != 1) {
136
- $button.addClass('loading');
137
  }
138
  },
139
  success: function(data) {
140
- $data = $(data); // Convert data to an object
141
- //console.log($data.length);
142
- if ($init) {
143
- $button.text($button_label);
144
- $init = false;
145
  }
146
- if ($data.length > 0) {
147
- var $el = $('<div class="' + $prefix + 'reveal"/>');
148
- $el.append($data);
149
- $el.hide();
150
- $content.append($el);
151
- if ($transition === 'fade') { // Fade transition
152
- $el.fadeIn(speed, 'alm_easeInOutQuad', function() {
153
- $loading = false;
154
- $button.delay(speed).removeClass('loading');
155
- if ($data.length < $posts_per_page) {
156
- $finished = true;
157
- $button.addClass('done');
158
  }
159
  });
160
  } else { // Slide transition
161
- $el.slideDown(speed, 'alm_easeInOutQuad', function() {
162
- $loading = false;
163
- $button.delay(speed).removeClass('loading');
164
- if ($data.length < $posts_per_page) {
165
- $finished = true;
166
- $button.addClass('done');
167
  }
168
  });
169
  }
 
 
 
 
 
170
  } else {
171
- $button.delay(speed).removeClass('loading').addClass('done');
172
- $loading = false;
173
- $finished = true;
174
  }
175
  },
176
  error: function(jqXHR, textStatus, errorThrown) {
177
- $loading = false;
178
- $button.removeClass('loading');
179
  }
180
  });
181
  };
@@ -186,15 +194,15 @@
186
  * Load more button click event
187
  * @since 1.0.0
188
  */
189
- $button.on('click', function() {
190
- if($pause === true){
191
- $pause = false;
192
- AjaxLoadMore.loadPosts();
193
  }
194
- if (!$loading && !$finished && !$(this).hasClass('done')) {
195
- $loading = true;
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
- var visible = false;
209
- if($el.is(":visible")){
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 ($scroll) {
222
- $window.bind("scroll touchstart", function() {
223
- if(AjaxLoadMore.isVisible()){
224
- var content_offset = $button.offset();
225
- if (!$loading && !$finished && $window.scrollTop() >= Math.round(content_offset.top - ($window.height() - 150)) && page < ($max_pages - 1) && proceed) {
226
- $loading = true;
227
- page++;
228
- AjaxLoadMore.loadPosts();
229
  }
230
  }
231
  });
@@ -233,17 +241,17 @@
233
 
234
 
235
  //Check for pause variable
236
- if($pause === true){
237
- $button.text($button_label);
238
- $loading = false;
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={},r=0,i=300,s=false,o=true,u=true,a=false,f=e(window),l="",c,h=t,p=e(".alm-listing",h),d=true,v="alm-",m=p.data("repeater"),g=p.data("max-pages"),y=p.data("pause"),b=p.data("offset"),w=p.data("transition"),E=p.data("posts-per-page");e(window).scrollTop(0);if(y===undefined){y=false}if(m===undefined){m="default"}if(g===undefined){g=5}if(g==="none"){g=1e6}if(w===undefined){w="slide"}else if(w==="fade"){w="fade"}else{w="slide"}if(p.data("offset")===undefined){b=0}else{b=p.data("offset")}if(p.data("button-label")===undefined){l="Older Posts"}else{l=p.data("button-label")}if(p.data("scroll")===undefined){d=true}else if(p.data("scroll")===false){d=false}else{d=true}var S=p.data("post-type");S=S.split(",");h.append('<div class="'+v+'btn-wrap"><button id="load-more" class="'+v+'load-more-btn more">'+l+"</button></div>");var x=e(".alm-load-more-btn",h);n.loadPosts=function(){x.addClass("loading");u=true;e.ajax({type:"GET",url:alm_localize.ajaxurl,data:{action:"ajax_load_more_init",nonce:alm_localize.alm_nonce,repeater:m,postType:S,postFormat:p.data("post-format"),category:p.data("category"),author:p.data("author"),taxonomy:p.data("taxonomy"),taxonomy_terms:p.data("taxonomy-terms"),taxonomy_operator:p.data("taxonomy-operator"),tag:p.data("tag"),order:p.data("order"),orderby:p.data("orderby"),search:p.data("search"),exclude:p.data("exclude"),numPosts:p.data("posts-per-page"),pageNumber:r,offset:b},dataType:"html",beforeSend:function(){if(r!=1){x.addClass("loading")}},success:function(t){c=e(t);if(o){x.text(l);o=false}if(c.length>0){var n=e('<div class="'+v+'reveal"/>');n.append(c);n.hide();p.append(n);if(w==="fade"){n.fadeIn(i,"alm_easeInOutQuad",function(){u=false;x.delay(i).removeClass("loading");if(c.length<E){a=true;x.addClass("done")}})}else{n.slideDown(i,"alm_easeInOutQuad",function(){u=false;x.delay(i).removeClass("loading");if(c.length<E){a=true;x.addClass("done")}})}}else{x.delay(i).removeClass("loading").addClass("done");u=false;a=true}},error:function(e,t,n){u=false;x.removeClass("loading")}})};x.on("click",function(){if(y===true){y=false;n.loadPosts()}if(!u&&!a&&!e(this).hasClass("done")){u=true;r++;n.loadPosts()}});n.isVisible=function(){var e=false;if(h.is(":visible")){e=true}return e};if(d){f.bind("scroll touchstart",function(){if(n.isVisible()){var e=x.offset();if(!u&&!a&&f.scrollTop()>=Math.round(e.top-(f.height()-150))&&r<g-1&&s){u=true;r++;n.loadPosts()}}})}if(y===true){x.text(l);u=false}else{n.loadPosts()}setTimeout(function(){s=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.ajaxloadmore(e(this))})};if(e(".ajax-load-more-wrap").length)e(".ajax-load-more-wrap").ajaxloadmore()})(jQuery)
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)