Projet

Général

Profil

Paste
Télécharger (3,05 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_slideshow / contrib / views_slideshow_simple_pager / views_slideshow_simple_pager.module @ b433176d

1
<?php
2

    
3
/**
4
 * @file
5
 * Provides a simple numeric counter pager for views_slideshow.
6
 */
7

    
8
/**
9
 * Implements hook_views_slideshow_widget_pager_info().
10
 */
11
function views_slideshow_simple_pager_views_slideshow_widget_pager_info($view) {
12
  return array(
13
    'views_slideshow_simple_pager' => array(
14
      'name' => t('Simple counter'),
15
    ),
16
  );
17
}
18

    
19
/**
20
 * Implements hook_theme().
21
 */
22
function views_slideshow_simple_pager_theme($existing, $type, $theme, $path) {
23
  return array(
24
    'views_slideshow_simple_pager' => array(
25
      'variables' => array(
26
        'vss_id' => NULL,
27
        'view' => NULL,
28
        'settings' => array(),
29
        'location' => NULL,
30
        'attributes' => array(),
31
      ),
32
      'template' => 'theme/views-slideshow-pager-fields',
33
      'path' => drupal_get_path('module', 'views_slideshow'),
34
    ),
35
  );
36
}
37

    
38
/**
39
 * Template preprocess function for Views Slideshow simple pager.
40
 *
41
 * @ingroup vss_theme
42
 */
43
function template_preprocess_views_slideshow_simple_pager(&$vars) {
44
  // Call the fields pager preprocess function.
45
  _views_slideshow_preprocess_views_slideshow_pager_fields($vars);
46

    
47
  // Override the (empty) rendered field items with our simple pager.
48
  $vars['rendered_field_items'] = '';
49
  if (empty($vars['settings']['hide_on_single_slide']) || count($vars['view']->result) > 1) {
50
    // Each slide can contain more than one item.
51
    $items_per_slide = $vars['view']->style_options['views_slideshow_cycle']['items_per_slide'];
52
    // The remainder will be put on an additional slide.
53
    $count_remainder = count($vars['view']->result) % $items_per_slide;
54
    // Figure out the number of slides based on result count
55
    // and items per slide, plus one if there is a remainder.
56
    $slide_count = ($count_remainder) ? floor(count($vars['view']->result) / $items_per_slide) + 1 : floor(count($vars['view']->result) / $items_per_slide);
57
    for ($count = 0; $count < $slide_count; ++$count) {
58
      $counted = $count + 1;
59
      $vars['rendered_field_items'] .= theme('views_slideshow_pager_field_item', array(
60
        'vss_id' => $vars['vss_id'],
61
        'item' => l($counted, 'javascript:void(0)', array(
62
          'fragment' => '',
63
          'external' => TRUE,
64
        )),
65
        'count' => $count,
66
        'location' => $vars['location'],
67
      ));
68
    }
69
  }
70

    
71
  // Clone the pager fields JavaScript object and methods.
72
  drupal_add_js('Drupal.viewsSlideshowSimplePager = Drupal.viewsSlideshowPagerFields || {};', 'inline');
73

    
74
  // Add anchor tags in the pager.
75
  drupal_add_js('var uniquePagerID =
76
    jQuery(".views-slideshow-pager-field-item").click(function() {
77
      var eID = jQuery(this).attr("id").replace("views_slideshow_pager_field_item_bottom_","");
78
      var ssID = eID.substring(0,eID.lastIndex("_"));
79
      var sN = eID.substring(eID.lastIndex("_") + 1);
80
      Drupal.viewsSlideshow.action({ "action": "goToSlide", "slideshowID": ssID, "slideNum": sN });
81
    });
82
  ', 'inline');
83

    
84
  // Add minimal styling.
85
  drupal_add_css(drupal_get_path('module', 'views_slideshow_simple_pager') . '/pager.css', array(
86
    'group' => CSS_DEFAULT,
87
    'type' => 'file',
88
  ));
89
}