简体   繁体   中英

Change parameter for infinity scroll module

I have 'Infinite scroll' module for Drupal 7.

Here's code js code from this module.

(function ($) {
  "use strict";

  var $window = $(window);

  // The threshold for how far to the bottom you should reach before reloading.
  var scroll_threshold = 200;
  var vis_index = 0;

  /**
   * Insert a views infinite scroll view into the document after AJAX.
   *
   * @param {object} $new_view The new view coming from the server.
  */
  $.fn.infiniteScrollInsertView = function ($new_view) {
  var $existing_view = this;
  var $existing_content = $existing_view.find('.view-
content').children();
  $new_view.find('.view-content').prepend($existing_content);
$existing_view.replaceWith($new_view);
$(document).trigger('infiniteScrollComplete', [$new_view, $existing_content]);
};

/**
 * Handle the automatic paging based on the scroll amount.
*/
Drupal.behaviors.views_infinite_scroll_automatic = {
attach : function(context, settings) {

  var settings = settings.views_infinite_scroll;
  var loadingImg = '<div class="views_infinite_scroll-ajax-loader"><img src="' + settings.img_path + '" alt="loading..."/></div>';

  $('.pager--infinite-scroll.pager--infinite-scroll-auto', context).once().each(function() {
    var $pager = $(this);
    $pager.find('.pager__item').hide();
    if ($pager.find('.pager__item a').length) {
      $pager.append(loadingImg);
    }
    $window.bind('scroll.views_infinite_scroll_' + vis_index, function() {
      if (window.innerHeight + window.pageYOffset > $pager.offset().top - scroll_threshold) {
        $pager.find('.pager__item a').click();
        $window.unbind('scroll.views_infinite_scroll_' + vis_index);
      }
    });
    vis_index++;
   });
  }
 };
})(jQuery);

After button click some request sending via Ajax and my page has this Form data:

view_name:blog
view_display_id:page
view_args:
view_path:about/media
view_base_path:about/media
view_dom_id:a2acec59ca7b252cfd911b770bc558bc
pager_element:0
page:2

I need to change this page parameter. How can I find him? I something is unclear, please say me in comments. I'll try to provide you with all needed information.

I have a dirty solution which could work for you. You can use hook_init to change the received parameters in the $_SERVER. Just take care enough to change this PAGE parameter when strict conditions are met, otherwise you could end up with a very strange behaivour.

Another way to change this value is using views hooks. See here: https://api.drupal.org/api/views/views.api.php/group/views_hooks/7.x-3.x

And just as a last resort, you can use Javascript to change the pager data on the link before it's pressed.

Hope that help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM