views_infinite_scroll.module in Views Infinite Scroll 7.2
Same filename and directory in other branches
Create a pager plugin to allow infinite scroll on views.
File
views_infinite_scroll.moduleView source
<?php
/**
* @file
* Create a pager plugin to allow infinite scroll on views.
*/
/**
* Implements hook_views_api().
*/
function views_infinite_scroll_views_api() {
return array(
'api' => 3,
);
}
/**
* Implements hook_views_plugin().
*/
function views_infinite_scroll_views_plugins() {
return array(
'module' => 'views_infinite_scroll',
'pager' => array(
'infinite_scroll' => array(
'title' => t('Infinite Scroll'),
'handler' => 'views_plugin_pager_infinite_scroll',
'uses options' => TRUE,
'parent' => 'full',
),
),
);
}
/**
* Implements hook_theme().
*/
function views_infinite_scroll_theme() {
return array(
'views_infinite_scroll_pager' => array(
'variables' => array(
'element' => NULL,
),
'template' => 'views-infinite-scroll-pager',
),
);
}
/**
* Implements hook_views_ajax_data_alter().
*/
function views_infinite_scroll_views_ajax_data_alter(&$commands, view $view) {
if (!isset($view->query->pager->plugin_name) || $view->query->pager->plugin_name !== 'infinite_scroll' || !isset($_GET['page'])) {
return;
}
foreach ($commands as $delta => &$command) {
if (!empty($command['method']) && $command['method'] === 'replaceWith') {
// Change the standard replace command to a custom one which will provide
// the infinite scroll effect.
$command['method'] = 'infiniteScrollInsertView';
}
// Remove the behaviour of scrolling to the top of the page.
if ($command['command'] === 'viewsScrollTop') {
unset($commands[$delta]);
}
}
}
/**
* Implements hook_preprocess_views_infinite_scroll_pager().
*/
function views_infinite_scroll_preprocess_views_infinite_scroll_pager(&$vars) {
$vars['button'] = array(
'#theme' => 'pager_next',
'#text' => $vars['text'],
'#element' => $vars['element'],
);
$vars['automatic_scroll_class'] = empty($vars['manual_load']) ? 'pager--infinite-scroll-auto' : '';
}
Functions
Name | Description |
---|---|
views_infinite_scroll_preprocess_views_infinite_scroll_pager | Implements hook_preprocess_views_infinite_scroll_pager(). |
views_infinite_scroll_theme | Implements hook_theme(). |
views_infinite_scroll_views_ajax_data_alter | Implements hook_views_ajax_data_alter(). |
views_infinite_scroll_views_api | Implements hook_views_api(). |
views_infinite_scroll_views_plugins | Implements hook_views_plugin(). |