Advertisement
towfiqi

pagination.js

Mar 14th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.75 KB | None | 0 0
  1. // AJAX POST PAGINATION
  2.  
  3. jQuery(function() {
  4.  
  5.  
  6. jQuery('.widget .ast_pagenav').each(function(index, element) {
  7. if(jQuery(this).data('query-max') >= 10){
  8. jQuery(this).find('.page-numbers:nth-child(1), .page-numbers:nth-child(2), .page-numbers:nth-child(3), .page-numbers:nth-child(1), .page-numbers:nth-child(3), .page-numbers:nth-last-child(3), .page-numbers:nth-last-child(2), .page-numbers:nth-last-child(1)').addClass('pagi_visible');
  9. jQuery( this ).find('.page-numbers:nth-last-child(3)').before('<span class="pagi_dots">....</span>');
  10. }else{
  11. jQuery( this ).find('.page-numbers').addClass('pagi_visible');
  12. }
  13. });
  14.  
  15.  
  16. //PAGINATION AJAX BEGIN
  17. jQuery( '.widget .ast_pagenav .page-numbers, #nav-below a, .ast_navigation i, .widget .ast_pagenav .pagi_prev, .widget .ast_pagenav .pagi_next' ).on( "click", function(e) {
  18. e.preventDefault();
  19.  
  20. //Numbered Pagination Enhancement
  21. if(jQuery(this).parent().data('query-max') >= 10){
  22. jQuery( this ).siblings().not('.page-numbers:nth-last-child(3), .page-numbers:nth-last-child(2), .page-numbers:nth-last-child(1)').removeClass('current current-next current-prev pagi_visible');
  23. jQuery( this ).parent().find('.pagi_dots').remove();
  24. jQuery( this ).addClass('current');
  25. jQuery( this ).next('.page-numbers').addClass('current-next pagi_visible');
  26. jQuery( this ).prev('.page-numbers').prev('.page-numbers').addClass('current-prev pagi_visible');
  27. jQuery( this ).prev('.page-numbers').addClass('current-prev pagi_visible');
  28. jQuery( this ).next('.page-numbers').after('<span class="pagi_dots">....</span>');
  29.  
  30. if(jQuery( this ).is('.page-numbers:nth-last-child(1), .page-numbers:nth-last-child(2), .page-numbers:nth-last-child(3), .page-numbers:nth-last-child(4), .page-numbers:nth-last-child(5)')){
  31. jQuery( this ).siblings().removeClass('current');
  32. jQuery( this ).addClass('current');
  33. jQuery( this ).parent().find('.pagi_dots').remove();
  34. jQuery( this ).parent().find('.page-numbers:nth-last-child(4)').before('<span class="pagi_dots">....</span>');
  35. }
  36. if(jQuery( this ).is('.page-numbers:nth-last-child(1), .page-numbers:nth-last-child(2)')){
  37. jQuery( this ).siblings().removeClass('current current-next current-prev pagi_visible');
  38. jQuery( this ).parent().find('.pagi_dots').remove();
  39. jQuery( this ).addClass('current');
  40. jQuery( this ).next('.page-numbers').addClass('current-next pagi_visible');
  41. jQuery( this ).prev('.page-numbers').addClass('current-prev pagi_visible');
  42. jQuery( this ).prev('.page-numbers').prev('.page-numbers').prev('.page-numbers').prev('.page-numbers').addClass('current-prev pagi_visible');
  43. jQuery( this ).prev('.page-numbers').prev('.page-numbers').prev('.page-numbers').addClass('current-prev pagi_visible');
  44. jQuery( this ).prev('.page-numbers').prev('.page-numbers').addClass('current-prev pagi_visible');
  45. jQuery( this ).parent().find('.page-numbers:nth-last-child(3)').before('<span class="pagi_dots">....</span>');
  46. }
  47. }else{
  48. jQuery( this ).siblings().removeClass('current');
  49. jQuery( this ).addClass('current');
  50. }
  51.  
  52.  
  53. //Ajax Loading Animation
  54. jQuery(this).parentsUntil('.optimposts').find('.hentry, .type-product').animate({"opacity":"0.4"});
  55.  
  56.  
  57. var pagi = jQuery(this).parentsUntil('.optimposts').parent();
  58. var ajaxurl = postsq.ajaxurl;
  59. var layout= pagi.data('post-layout');
  60. var type= pagi.data('post-type');
  61. var count= pagi.data('post-count');
  62. var pages= pagi.data('post-pages');
  63. var category= pagi.data('post-category');
  64. var product_category= pagi.data('product-category');
  65. var previewbtn= pagi.data('post-previewbtn');
  66. var linkbtn= pagi.data('post-linkbtn');
  67. var navigation= pagi.data('post-navigation');
  68.  
  69. if(navigation =='numbered'){
  70. var nextpage= jQuery(this).text();
  71. }
  72.  
  73.  
  74. if(navigation =='infscroll' || navigation =='infscroll_auto'){
  75. var nextpage= jQuery(this).parent().parent().data('infinte-next');
  76. }
  77.  
  78. if(navigation =='oldnew'){
  79. var nextpage = jQuery(this).parent().parent().data('query-count');
  80. //If Next Button is clicked
  81. if(jQuery(this).hasClass('fa-angle-right')){
  82. if(nextpage == jQuery(this).parent().parent().data('query-max')){}else{
  83. var nextpage = nextpage + 1 ;
  84. }
  85. }
  86. //If Previous Button is clicked
  87. if(jQuery(this).hasClass('fa-angle-left')){
  88. if(nextpage == 1){}else{
  89. var nextpage = nextpage -1 ;
  90. }
  91. }
  92. }
  93.  
  94. var value = jQuery.ajax({
  95.  
  96. type: "POST",
  97. url: ajaxurl,
  98. context: this,
  99. data:{
  100. "layout": layout,
  101. "type": type,
  102. "count": count,
  103. "pages": pages,
  104. "category": category,
  105. "product_category": product_category,
  106. "previewbtn": previewbtn,
  107. "previewbtn": previewbtn,
  108. "nextpage": nextpage,
  109. action: "optimizer_posts"
  110. }
  111.  
  112. })
  113. .fail(function(r,status,jqXHR) {
  114. console.log("failed");
  115.  
  116. })
  117. .done(function(response,status,jqXHR) {
  118. //console.log(navigation);
  119. console.log(product_category);
  120. //console.log(response);
  121. var ajaxsource = jQuery('<div>' + response + '</div>');
  122. var newappend = ajaxsource.find('.lay'+layout+'_wrap_ajax').html();
  123.  
  124. if(navigation =='numbered'){
  125. jQuery(this).parentsUntil('.optimposts').find('.lay'+layout+'_wrap_ajax').html(newappend);
  126. //console.log(response);
  127. //console.log(newappend);
  128. //jQuery('html, body').animate({scrollTop: jQuery(this).parentsUntil('.optimposts').offset().top -100}, 'medium');
  129. }
  130. if(navigation =='infscroll' || navigation =='infscroll_auto'){
  131. var currentpage = jQuery(this).parent().parent().data('infinte-next');
  132. jQuery(this).parent().parent().data('infinte-next', currentpage + 1);
  133. //jQuery('html, body').animate({scrollTop: jQuery(this).offset().top -300}, 'medium');
  134. if(layout !== '3'){
  135. jQuery(this).parentsUntil('.optimposts').find('.lay'+layout+'_wrap_ajax').append(newappend);
  136. }
  137. var postoucnt = jQuery(this).parentsUntil('.optimposts').find('.lay'+layout+'_wrap_ajax .hentry').length;
  138.  
  139. if(postoucnt >= jQuery(this).parent().parent().data('infinite-max') ){
  140. jQuery(this).parent().parent().addClass('infloaded');
  141. }
  142. }
  143. //}
  144.  
  145.  
  146. if(navigation =='oldnew'){
  147. jQuery(this).parentsUntil('.optimposts').find('.lay'+layout+'_wrap_ajax').html(newappend);
  148. jQuery(this).parent().parent().data('query-count', nextpage);
  149. if(nextpage == jQuery(this).parent().parent().data('query-max')){
  150. jQuery(this).parent().parent().find('.fa-angle-right').addClass('nav_maxed');
  151. }else{jQuery(this).parent().parent().find('.fa-angle-right').removeClass('nav_maxed');}
  152. if(nextpage == 1){
  153. jQuery(this).parent().parent().find('.fa-angle-left').addClass('nav_maxed');
  154. }else{jQuery(this).parent().parent().find('.fa-angle-left').removeClass('nav_maxed');}
  155. }
  156.  
  157. //Layout1 Animation
  158. jQuery(".lay1").each(function(index, element) {
  159. var divs = jQuery(this).find(".hentry");
  160. for(var i = 0; i < divs.length; i+=3) {
  161. divs.slice(i, i+3).wrapAll("<div class='ast_row'></div>");
  162. }
  163. if (jQuery(window).width() < 1200) {
  164. var flaywidth = jQuery(this).find(".hentry").width();
  165. jQuery(this).find('.post_image').css({"maxHeight":(flaywidth * 66)/100});
  166. }
  167. });
  168.  
  169. jQuery('.lay1.optimposts, .lay2.optimposts, .lay4.optimposts').each(function(index, element) { jQuery(this).waitForImages(function() { jQuery(this).find('.type-product').matchHeight({ property: 'min-height'}); }); });
  170. jQuery('.lay1.optimposts .type-product').each(function(index, element) {
  171. jQuery(this).find('.button.add_to_cart_button').prependTo(jQuery(this).find('.imgwrap'));
  172. jQuery(this).find('span.price').prependTo(jQuery(this).find('.post_image '));
  173. });
  174.  
  175. //FrontPage Post Image Zoom
  176. jQuery(".imgzoom[href$='.jpg'], .imgzoom[href$='.png'], .imgzoom[href$='.gif']").magnificPopup({type:'image',image: {titleSrc: 'data-title'}});
  177.  
  178. //LAYOUT 3 MASONRY
  179. if(layout == 3 && ( navigation == 'numbered' || navigation == 'oldnew')){
  180. var container = jQuery(this).parentsUntil('.optimposts').find('.lay3_wrap_ajax');
  181. console.log(container);
  182. //Layout3 Masonry
  183. var msnry;
  184. imagesLoaded( container, function() {
  185. container.masonry({
  186. // options
  187. itemSelector: '.hentry'
  188. });
  189. });
  190. }
  191. //LAYOUT 3 MASONRY with Infinite Scroll
  192. if(layout == 3 && navigation == 'infscroll' || layout == 3 && navigation == 'infscroll_auto'){
  193. var container = jQuery(this).parentsUntil('.optimposts').find('.lay3_wrap_ajax');
  194. imagesLoaded( container, function() {
  195. container.masonry({
  196. // options
  197. itemSelector: '.hentry'
  198. });
  199. });
  200. jQuery(this).parentsUntil('.optimposts').find('.lay3_wrap').css({"height":"auto"});
  201. container.masonry('reloadItems');
  202. }
  203.  
  204.  
  205. });
  206.  
  207. //Ajax Loading Animation
  208. jQuery(this).parentsUntil('.optimposts').find('.hentry, .type-product').animate({"opacity":"1"});
  209.  
  210. });
  211.  
  212. //Infinite Scroll AUTO
  213. jQuery('div[data-post-navigation="infscroll_auto"] #nav-below').each(function(index, element) {
  214. jQuery(this).find('a').html('<i class="fa fa-circle-o-notch fa-spin"></i> Loading..');
  215. jQuery(this).on('inview', function(event, isInView) {
  216. if (isInView) {
  217. jQuery(this).find('a').click();
  218. var postoucnt = jQuery(this).parentsUntil('.optimposts').find('.hentry').length;
  219. if(postoucnt >= jQuery(this).data('infinite-max') ){
  220. jQuery(this).addClass('infloaded');
  221. jQuery(this).find('a').html('<i class="fa fa-smile-o"></i> Loading Complete');
  222. }
  223. }
  224. });
  225. });
  226.  
  227.  
  228. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement