views_show_more.module in Views Show More 7
Same filename and directory in other branches
Views Show More module.
File
views_show_more.moduleView source
<?php
/**
* @file
* Views Show More module.
*/
/**
* Implements hook_views_api().
*/
function views_show_more_views_api() {
return array(
'api' => 3.0,
);
}
/**
* Implements hook_theme().
*/
function views_show_more_theme() {
return array(
'pager_show_more' => array(
'variables' => array(
'tags' => array(),
'quantity' => 10,
'element' => 0,
'parameters' => array(),
),
),
);
}
/**
* Theme function for pager link generation.
*/
function theme_pager_show_more($vars) {
global $pager_total;
$element = $vars['element'];
$parameters = $vars['parameters'];
$pager_classes = array(
'pager',
'pager-show-more',
);
$pager_next = theme('pager_next', array(
'text' => $vars['show_more_text'],
'element' => $element,
'interval' => 1,
'parameters' => $parameters,
));
if (empty($pager_next)) {
$pager_next = empty($vars['show_more_empty_text']) ? ' ' : check_plain($vars['show_more_empty_text']);
$pager_classes[] = 'pager-show-more-empty';
}
if ($pager_total[$element] > 1) {
$items[] = array(
'class' => array(
'pager-show-more-next',
),
'data' => $pager_next,
);
return theme('item_list', array(
'items' => $items,
'title' => NULL,
'type' => 'ul',
'attributes' => array(
'class' => $pager_classes,
),
));
}
}
/**
* Implements hook_views_ajax_data_alter().
*/
function views_show_more_views_ajax_data_alter(&$commands, $view) {
// Checking views have result or not.
if (!$view->total_rows) {
return;
}
$pager = $view->query->pager;
$style_plugin = $view->style_plugin;
if (is_a($pager, 'ViewsShowMorePlugin')) {
// Checking current page number if 1st page then no action.
if ($pager->current_page == 0) {
return;
}
foreach ($commands as $key => $command) {
// Remove "viewsScrollTop" command, not needed.
if ($command['command'] == 'viewsScrollTop') {
unset($commands[$key]);
}
// The replace should the only one, but just in case, we'll make sure.
if ($command['command'] == 'insert' && $command['selector'] == '.view-dom-id-' . $view->dom_id) {
if ($style_plugin->plugin_name == 'list' && in_array($style_plugin->options['type'], array(
'ul',
'ol',
))) {
if (empty($style_plugin->options['wrapper_class'])) {
$target = "> {$style_plugin->options['type']}:not(.links)";
}
else {
$wrapper_classes = str_replace(' ', '.', $style_plugin->options['wrapper_class']);
$target = ".{$wrapper_classes} > {$style_plugin->options['type']}:not(.links)";
}
$commands[$key]['append_at'] = $target;
}
elseif ($style_plugin->plugin_name == 'table') {
$commands[$key]['append_at'] = '.views-table tbody';
}
elseif ($style_plugin->plugin_name == 'grid') {
$commands[$key]['append_at'] = '.views-view-grid tbody';
}
$commands[$key]['command'] = 'viewsShowMore';
$commands[$key]['method'] = $pager->options['result_display_method'];
if (isset($pager->options['effects']) && $pager->options['effects']['type'] != 'none') {
$commands[$key]['effect'] = $pager->options['effects']['type'];
$commands[$key]['speed'] = $pager->options['effects']['speed'];
}
$commands[$key]['options'] = array(
'content_selector' => $pager->options['advance']['content_selector'],
'pager_selector' => $pager->options['advance']['pager_selector'],
);
}
}
}
}
/**
* Implements hook_views_pre_render().
*/
function views_show_more_views_pre_render(&$view) {
// Load js file only if ajax is enabled.
if (!$view->use_ajax) {
return;
}
drupal_add_js(drupal_get_path('module', 'views_show_more') . '/views_show_more.js');
}
Functions
Name | Description |
---|---|
theme_pager_show_more | Theme function for pager link generation. |
views_show_more_theme | Implements hook_theme(). |
views_show_more_views_ajax_data_alter | Implements hook_views_ajax_data_alter(). |
views_show_more_views_api | Implements hook_views_api(). |
views_show_more_views_pre_render | Implements hook_views_pre_render(). |