Projet

Général

Profil

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

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

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
function template_preprocess_views_slideshow_simple_pager(&$vars) {
42
  // Call the fields pager preprocess function.
43
  _views_slideshow_preprocess_views_slideshow_pager_fields($vars);
44

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

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

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

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