Commit 4c5afb8b authored by Remon Georgy's avatar Remon Georgy

Merge DRUPAL-6--1 back to HEAD

parent da8433e0
div#views_infinite_scroll-ajax-loader {
text-align: center;
}
<?php
// $Id$
/**
* @file
* drush integration for views_infinite_scroll.
*/
/**
* Implementation of hook_drush_command().
*
* In this hook, you specify which commands your
* drush module makes available, what it does and
* description.
*
* Notice how this structure closely resembles how
* you define menu hooks.
*
* @See drush_parse_command() for a list of recognized keys.
*
* @return
* An associative array describing your command(s).
*/
function views_infinite_scroll_drush_command() {
$items = array();
$items['dl-autopager'] = array(
'callback' => 'views_infinite_scroll_drush_autopager_download',
'description' => dt('Downloads the required autopager jquery plugin.'),
);
return $items;
}
/**
* Implementation of hook_drush_help().
*
* This function is called whenever a drush user calls
* 'drush help <name-of-your-command>'
*
* @param
* A string with the help section (prepend with 'drush:')
*
* @return
* A string with the help text for your command.
*/
function views_infinite_scroll_drush_help($section) {
switch ($section) {
case 'drush:dl-autopager':
return dt("Downloads the required autopager jquery plugin.");
}
}
/**
* Example drush command callback.
*
* This is where the action takes place.
*
* In this function, all of Drupals API is (usually) available, including
* any functions you have added in your own modules/themes.
*
* To print something to the terminal window, use drush_print().
*
*/
function views_infinite_scroll_drush_autopager_download() {
if(module_exists('libraries')) {
$path = 'sites/all/libraries/autopager';
// Create the path if it does not exist.
if (!is_dir($path)) {
drush_op('mkdir', $path);
drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
}
}
else {
$path = drupal_get_path('module', 'views_infinite_scroll') . '/js';
}
drush_op('chdir', $path);
// Download the plugin.
if (drush_shell_exec('wget http://jquery-autopager.googlecode.com/files/jquery.autopager-1.0.0.js')) {
drush_log(dt('jquery.autopager-1.0.0.js has been downloaded to @path', array('@path' => $path)), 'success');
}
else {
drush_log(dt('Drush was unable to download jquery.autopager-1.0.0.js to @path', array('@path' => $path)), 'error');
}
}
// $Id:
var views_infinite_scroll_was_initialised = false;
Drupal.behaviors.views_infinite_scroll = function() {
// Make sure that autopager pluginis loaded
// Make sure that autopager plugin is loaded
if($.autopager) {
// Make sure that views ajax is disabled
if(!Drupal.Views) {
$.autopager({
appendTo: Drupal.settings.views_infinite_scroll.content_selector,
content: Drupal.settings.views_infinite_scroll.items_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'));
if(!views_infinite_scroll_was_initialised) {
views_infinite_scroll_was_initialised = true;
// There should not be multiple Infinite Scroll Views on the same page
if(Drupal.settings.views_infinite_scroll.length == 1) {
var settings = Drupal.settings.views_infinite_scroll[0];
var use_ajax = false;
// Make sure that views ajax is disabled
if(Drupal.settings.views && Drupal.settings.views.ajaxViews) {
$.each(Drupal.settings.views.ajaxViews, function(key, value) {
if((value.view_name == settings.view_name) && (value.view_display_id == settings.display)) {
use_ajax = true;
}
});
}
if(!use_ajax) {
var content_selector = 'div.view-id-' + settings.view_name + '.view-display-id-' + settings.display + ' ' + settings.content_selector;
var items_selector = content_selector + ' ' + settings.items_selector;
var next_selector = settings.next_selector;
var img_path = settings.img_path;
var img = '<div id="views_infinite_scroll-ajax-loader"><img src="' + img_path + '" alt="loading..."/></div>';
var img_location = 'div.view-id-' + settings.view_name + '.view-display-id-' + settings.display + ' div.view-content';
$(settings.pager_selector).hide();
$.autopager({
appendTo: content_selector,
content: items_selector,
link: next_selector,
page: 0,
start: function() {
$(img_location).after(img);
},
load: function() {
$('div#views_infinite_scroll-ajax-loader').remove();
Drupal.attachBehaviors();
}
});
}
else {
alert(Drupal.t('Views infinite scroll pager is not compatible with Ajax Views. Please disable "Use Ajax" option.'));
}
}
else if(Drupal.settings.views_infinite_scroll.length > 1) {
alert(Drupal.t('Views Infinite Scroll module can\'t handle more than one infinite view in the same page.'));
}
}
}
else {
alert(Drupal.t('Autopager jquery plugin in not loaded'));
alert(Drupal.t('Autopager jquery plugin in not loaded.'));
}
};
......@@ -4,7 +4,7 @@
* @file
* Theme infinite scroll page
*/
function theme_views_infinite_scroll_pager($tags = array(), $limit = 10, $content_selector = 'div.view-content', $items_selector = 'div.view-content .views-row', $element = 0, $parameters = array(), $quantity = 9) {
function theme_views_infinite_scroll_pager($tags = array(), $limit = 10, $view_name, $current_display, $content_selector = 'div.view-content', $items_selector = 'div.view-content .views-row', $img_path, $element = 0, $parameters = array(), $quantity = 9) {
$PAGER_CLASS = 'pager';
global $pager_page_array, $pager_total;
......@@ -36,14 +36,29 @@ function theme_views_infinite_scroll_pager($tags = array(), $limit = 10, $conten
$settings = array(
'views_infinite_scroll' => array(
'pager_selector' => 'ul.' . $PAGER_CLASS,
'next_selector' => 'li.pager-next a:first',
'content_selector' => $content_selector,
'items_selector' => $items_selector,
)
array(
'view_name' => $view_name,
'display' => $current_display,
'pager_selector' => 'ul.' . $PAGER_CLASS,
'next_selector' => 'li.pager-next a:first',
'content_selector' => $content_selector,
'items_selector' => $items_selector,
'img_path' => $img_path,
),
),
);
drupal_add_css(drupal_get_path('module', 'views_infinite_scroll') . '/css/views_infinite_scroll.css');
drupal_add_js($settings, 'setting' );
drupal_add_js(drupal_get_path('module', 'views_infinite_scroll') . '/js/jquery.autopager-1.0.0.js');
$autopager_path = '';
if (module_exists('libraries')) {
$autopager_path = libraries_get_path('autopager');
}
else {
$autopager_path = drupal_get_path('module', 'views_infinite_scroll') . '/js';
}
drupal_add_js($autopager_path . '/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));
......
; $Id:
name = Views Infinite Scroll
description = Provides an Infinite Scrolling pager for Views
package = Views
......
<?php
// $Id:
/**
* @file
*/
......
......@@ -20,29 +20,30 @@ class views_plugin_pager_infinite_scroll extends views_plugin_pager_full {
}
function render($input) {
global $base_url;
$style_plugin = $this->view->display_handler->default_display->options['style_plugin'];
$content_selector = '';
$items_selector = '';
switch($style_plugin){
$img_path = $base_url . '/' . drupal_get_path('module', 'views_infinite_scroll') . '/images/ajax-loader.gif';
switch($this->view->plugin_name){
case 'default':
$content_selector = 'div.view-content';
$items_selector = 'div.view-content .views-row';
$items_selector = '.views-row';
break;
case 'grid':
$content_selector = 'div.view-content tbody';
$items_selector = 'div.view-content tbody tr';
$items_selector = 'tr';
break;
case 'list':
$content_selector = 'div.view-content .item-list > *';
$items_selector = 'div.view-content .views-row';
$items_selector = '.views-row';
break;
case 'table':
$content_selector = 'div.view-content tbody';
$items_selector = 'div.view-content tbody tr';
$items_selector = 'tr';
break;
}
$pager_theme = views_theme_functions('views_infinite_scroll_pager', $this->view, $this->display);
return theme($pager_theme, $input, $this->options['items_per_page'], $content_selector, $items_selector, $this->options['id']);
return theme($pager_theme, $input, $this->options['items_per_page'], $this->view->name, $this->view->current_display, $content_selector, $items_selector, $img_path, $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