Commit e29ec948 authored by Remon Georgy's avatar Remon Georgy

Initial commit of views_infinite_scroll module. The module enables infinite...

Initial commit of views_infinite_scroll module. The module enables infinite scrolling to views' pages.
parents
Drupal.behaviors.views_infinite_scroll = function() {
// Make sure that autopager pluginis loaded
if($.autopager) {
// Make sure that views ajax is disabled
if(!Drupal.Views) {
$.autopager({
content: Drupal.settings.views_infinite_scroll.content_selector,
link: Drupal.settings.views_infinite_scroll.next_selector,
page: 0,
start: function() {
$(Drupal.settings.views_infinite_scroll.pager_selector).hide();
}
});
}
else {
alert(Drupal.t('Views infinite scroll pager is not compatible with Ajax Views. please disable "Use Ajax" option'));
}
}
else {
alert(Drupal.t('Autopager jquery plugin in not loaded'));
}
};
<?php
// $Id$
/**
* @file
* Theme infinite scroll page
*/
function theme_views_infinite_scroll_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
$PAGER_CLASS = 'pager';
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('››')), $limit, $element, 1, $parameters);
if (empty($li_next)) {
$li_next = "&nbsp;";
}
if ($pager_total[$element] > 1) {
$items[] = array(
'class' => 'pager-current',
'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)),
);
$items[] = array(
'class' => 'pager-next',
'data' => $li_next,
);
$settings = array(
'views_infinite_scroll' => array(
'pager_selector' => 'ul.' . $PAGER_CLASS,
'next_selector' => 'li.pager-next a:first',
'content_selector' => 'div.view-content',
)
);
drupal_add_js($settings, 'setting' );
drupal_add_js(drupal_get_path('module', 'views_infinite_scroll') . '/js/jquery.autopager-1.0.0.js');
drupal_add_js(drupal_get_path('module', 'views_infinite_scroll') . '/js/views_infinite_scroll.js');
return theme('item_list', $items, NULL, 'ul', array('class' => $PAGER_CLASS));
}
}
name = Views Infinite Scroll
description = Provides an Infinite Scrolling pager for Views
package = Views
core = 6.x
dependencies[] = views
<?php
/**
* @file
*/
/**
* Implementation of hook_views_api().
*/
function views_infinite_scroll_views_api() {
return array('api' => 2);
}
/**
* Implementation of hook_theme().
*/
function views_infinite_scroll_theme() {
$path = drupal_get_path('module', 'views_infinite_scroll');
// Some quasi clever array merging here.
$base = array(
'file' => 'views_infinite_scroll_theme.inc',
'path' => "$path/theme",
);
// Our extra version of pager from pager.inc
$hooks['views_infinite_scroll_pager'] = $base + array(
'arguments' => array('tags' => array(), 'limit' => 10, 'element' => 0, 'parameters' => array()),
'pattern' => 'views_infinite_scroll_pager__',
);
return $hooks;
}
<?php
// $Id$
/**
* @file
* Provides the views plugin information.
*/
/**
* Implementation of hook_views_plugin().
*/
function views_infinite_scroll_views_plugins() {
return array(
'module' => 'views_infinite_scroll',
'pager' => array(
'infinite_scroll' => array(
'title' => t('Infinite Scroll'),
'help' => t('views_infinite_scroll'),
'handler' => 'views_plugin_pager_infinite_scroll',
'uses options' => TRUE,
'parent' => 'full',
),
),
);
}
<?php
// $Id$
/**
* The plugin to handle full pager.
*
* @ingroup views_pager_plugins
*/
class views_plugin_pager_infinite_scroll extends views_plugin_pager_full {
function init(&$view, &$display, $options = array()) {
parent::init($view, $display, $options);
}
function summary_title() {
return "Infinite Scroll";
if (!empty($this->options['offset'])) {
return format_plural($this->options['items_per_page'], 'Infinite scroll pager, @count item, skip @skip', 'Infinite scroll pager, @count items, skip @skip', array('@count' => $this->options['items_per_page'], '@skip' => $this->options['offset']));
}
return format_plural($this->options['items_per_page'], 'Infinite scroll pager, @count item', 'Infinite scroll pager, @count items', array('@count' => $this->options['items_per_page']));
}
function render($input) {
$pager_theme = views_theme_functions('views_infinite_scroll_pager', $this->view, $this->display);
return theme($pager_theme, $input, $this->options['items_per_page'], $this->options['id']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment