Changeset 2293870
- Timestamp:
- 04/28/2020 08:08:25 PM (5 years ago)
- Location:
- wp-ajax-pagination/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-ajax-pagination/trunk/readme.txt
r2293399 r2293870 1 ===WP Ajax Load More Pagination ===1 ===WP Ajax Load More Pagination and Infinite Scroll=== 2 2 Contributors: Processby 3 3 Donate link: https://www.patreon.com/processby 4 Tags: load more, ajax load more, ajax pagination, pagination, ajax4 Tags: load more, infinite scroll, ajax pagination, pagination, ajax 5 5 Requires at least: 4.0 6 6 Tested up to: 5.4 7 Stable tag: 1.1. 17 Stable tag: 1.1.2 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 21 21 * "Load more" button; 22 22 * "Load more" button and pagination; 23 * Customisable styles; 23 * Infinite Scroll; 24 * Customisable styles. 24 25 25 26 … … 37 38 == Changelog == 38 39 40 41 = 1.1.2 = 42 43 Release Date: Apr 28, 2020 44 45 * Add - Infinite Scroll; 39 46 40 47 = 1.1.1 = -
wp-ajax-pagination/trunk/src/Frontend/Frontend.php
r2293399 r2293870 108 108 justify-content: center; 109 109 margin: 20px 0; 110 111 } 112 110 } 113 111 .wpap-loadmore-wrapper .wpap-loadmore-button{ 114 112 background-color: $button_background; … … 129 127 "; 130 128 129 if ($this->options['paginationType'] == 'infinite-scroll') { 130 echo " 131 .wpap-loadmore-wrapper .wpap-loadmore-button{ 132 visibility: hidden; 133 }"; 134 135 } 136 131 137 if ($enable_loading) { 132 133 138 echo " 134 139 .wp-ajax-pagination-loading{ … … 158 163 $pagingUrl = ''; 159 164 if($this->options['pagingUrl']){ 160 $pagingUrl = "window.history.pushState('', 'Title', link) ";165 $pagingUrl = "window.history.pushState('', 'Title', link);"; 161 166 } 162 167 … … 170 175 try {return new ActiveXObject(\"Microsoft.XMLHTTP\");} 171 176 catch (error) {} 172 177 173 178 throw new Error(\"Could not create HTTP request object.\"); 174 179 }"; … … 181 186 182 187 if($(\"{$postsSelector}\").length != 0){ 183 188 184 189 $(document).on('click', \"{$this->options['navigationSelector'][$i]} a\", function (event) { 185 190 event.preventDefault(); 186 191 187 192 var link = $(this).attr('href'); 193 188 194 $('html, body').animate({ 189 scrollTop: $(\"{$postsSelector}\").offset().top 190 }, 200); 195 scrollTop: ($(\"{$postsSelector}\").offset().top - 200) 196 }, 200); 197 191 198 $pagingUrl 192 199 $('body').append('<div class=\"wp-ajax-pagination-loading\"></div>'); 193 200 194 201 var request = makeHttpObject(); 195 196 202 request.open(\"POST\", link , true); 197 203 request.send(null); … … 396 402 } 397 403 404 405 if ($this->options['paginationType'] == 'infinite-scroll') { 406 407 global $wp_query; 408 $link = html_entity_decode(get_pagenum_link()); 409 $max_pages = $wp_query->max_num_pages; 410 $paged = get_query_var('paged') ? get_query_var('paged') : 1; 411 echo "<script> 412 function makeHttpObject() { 413 try {return new XMLHttpRequest();} 414 catch (error) {} 415 try {return new ActiveXObject(\"Msxml2.XMLHTTP\");} 416 catch (error) {} 417 try {return new ActiveXObject(\"Microsoft.XMLHTTP\");} 418 catch (error) {} 419 420 throw new Error(\"Could not create HTTP request object.\"); 421 }"; 422 423 echo "jQuery(document).ready(function($){"; 424 425 $i = 0; 426 427 if ($paged != $max_pages) { 428 429 foreach ($this->options['postsSelector'] as $postsSelector) { 430 431 echo " 432 433 434 if($(\"{$postsSelector}\").length != 0){ 435 $(\"{$this->options['navigationSelector'][$i]}\").before(\"<div class='wpap-loadmore-wrapper'><span class='wpap-loadmore-button loadmore-button-{$i} wpap_button_text' data-pages='$max_pages' data-page='$paged' data-link='$link'>Load more</span></div>\"); 436 $(\"{$this->options['navigationSelector'][$i]}\").remove(); 437 } 438 var button = $('.loadmore-button-{$i}'); 439 440 if(button.length != 0){ 441 442 var pageNext = button.data('page'); 443 444 var pages = button.data('pages'); 445 446 var isLoading = false; 447 var endLoading = false; 448 449 if(pageNext < pages){ 450 pageNext++; 451 } 452 453 $(window).scroll(function(){ 454 455 if( $(document).scrollTop() + $(window).height() > button.offset().top && button.offset().top > $(document).scrollTop() && !isLoading && !endLoading){ 456 457 var link = button.data('link')+'page/'+pageNext+'/'; 458 $pagingUrl 459 $('body').append('<div class=\"wp-ajax-pagination-loading\"></div>'); 460 isLoading = true; 461 462 var request = makeHttpObject(); 463 464 request.open(\"POST\", link , true); 465 request.send(null); 466 request.onreadystatechange = function() { 467 468 if (request.readyState == 4){ 469 470 var htmlDoc = $( request.responseText ); 471 var html = htmlDoc.find('{$postsSelector}').html(); 472 var htmlNav = htmlDoc.find('{$this->options['navigationSelector'][$i]}').html(); 473 474 $(\"{$postsSelector}\").children().last().after(html); 475 476 $('.wp-ajax-pagination-loading').remove(); 477 isLoading = false; 478 479 if(pageNext == pages){ 480 button.remove(); 481 endLoading = true; 482 }else{ 483 pageNext++; 484 } 485 486 {$this->options['jsCode']} 487 } 488 }; 489 490 } 491 }); 492 493 }"; 494 $i++; 495 } 496 497 } 498 echo '});'; 499 echo '</script>'; 500 } 501 502 398 503 } 399 504 -
wp-ajax-pagination/trunk/views/admin/section/main-settings.php
r2293399 r2293870 45 45 <?php 46 46 _e('"Load more" button', 'wp-ajax-pagination'); 47 ?> 48 </label><br> 49 <label> 50 <input type="radio" name="<?php echo Settings::OPTIONS; ?>[paginationType]" value="infinite-scroll" <?php checked('infinite-scroll', $paginationType); ?>> 51 <?php 52 _e('Infinite Scroll', 'wp-ajax-pagination'); 47 53 ?> 48 54 </label> -
wp-ajax-pagination/trunk/wp-ajax-pagination.php
r2293399 r2293870 8 8 * Plugin URI: https://processby.com/ajax-pagination-plugin-wordpress/ 9 9 * Description: Loading paged content with Ajax. 10 * Version: 1.1. 110 * Version: 1.1.2 11 11 * Author: Processby 12 12 * Author URI: https://processby.com
Note: See TracChangeset
for help on using the changeset viewer.