Projet

Général

Profil

Paste
Télécharger (6,15 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_slideshow / contrib / views_slideshow_cycle / theme / views_slideshow_cycle.theme.inc @ 6eb8d15f

1
<?php
2

    
3
/**
4
 * @file
5
 * Theme & preprocess functions for the Views Slideshow: cycle module.
6
 */
7

    
8
/**
9
 * Views Slideshow: Theme the main frame wrapper.
10
 *
11
 * @ingroup themeable
12
 */
13

    
14
function _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame(&$vars) {
15
  $settings = $vars['settings'];
16
  $rows = $vars['rows'];
17
  $view = $vars['view'];
18
  $vss_id = $vars['vss_id'];
19

    
20
  // Cast the strings into int or bool as necessary.
21
  $new_settings = array();
22
  foreach ($settings as $key => $value) {
23
    if (is_string($value)) {
24
      $value = str_replace("\n", ' ', $value);
25

    
26
      $value = trim($value);
27

    
28
      if (is_numeric($value)) {
29
        $value = (int)$value;
30
      }
31
      elseif (strtolower($value) == 'true') {
32
        $value = TRUE;
33
      }
34
      elseif (strtolower($value) == 'false') {
35
        $value = FALSE;
36
      }
37
    }
38

    
39
    $new_settings[$key] = $value;
40
  }
41

    
42
  $settings = array_merge(
43
    array(
44
      'num_divs' => sizeof($rows),
45
      'id_prefix' => '#views_slideshow_cycle_main_',
46
      'div_prefix' => '#views_slideshow_cycle_div_',
47
      'vss_id' => $vss_id,
48
    ),
49
    $new_settings
50
  );
51

    
52
  // We need to go through the current js setting values to make sure the one we
53
  // want to add is not already there. If it is already there then append -[num]
54
  // to the id to make it unique.
55
  $slideshow_count = 1;
56
  $current_settings = drupal_add_js();
57
  foreach ($current_settings['settings']['data'] AS $current_setting) {
58
    if (isset($current_setting['viewsSlideshowCycle'])) {
59
      $current_keys = array_keys($current_setting['viewsSlideshowCycle']);
60
      if (stristr($current_keys[0], '#views_slideshow_cycle_main_' . $vss_id)) {
61
        $slideshow_count++;
62
      }
63
    }
64
  }
65

    
66
  if ($slideshow_count > 1) {
67
    $vss_id .= '-' . $slideshow_count;
68
    $settings['vss_id'] = $vss_id;
69
  }
70

    
71
  // Don't load javascript unless libraries module is present.
72
  if (module_exists('libraries')) {
73
    // Load jQuery Cycle
74
    if ($cycle_path = _views_slideshow_cycle_library_path()) {
75
      drupal_add_js($cycle_path);
76
    }
77

    
78
    // Load Json2
79
    $json_path = libraries_get_path('json2');
80
    if (!empty($json_path) && file_exists($json_path . '/json2.js')) {
81
      drupal_add_js($json_path . '/json2.js');
82
    }
83

    
84
    // Load our cycle js
85
    $module_path = drupal_get_path('module', 'views_slideshow_cycle');
86
    drupal_add_js($module_path . '/js/views_slideshow_cycle.js');
87

    
88
    // Load the pause library
89
    if (!empty($settings['pause_in_middle']) && $pause_path = _views_slideshow_cycle_pause_library_path()) {
90
      drupal_add_js($pause_path);
91
    }
92
  }
93

    
94
  // Load our cycle css
95
  drupal_add_css($module_path . '/views_slideshow_cycle.css', 'file');
96

    
97
  drupal_add_js(array('viewsSlideshowCycle' => array('#views_slideshow_cycle_main_' . $vss_id => $settings)), 'setting');
98

    
99
  // Add hover intent library
100
  if ($settings['pause']) {
101
    if (module_exists('libraries')) {
102
      // Load jQuery hoverIntent
103
      $hoverIntent_path = libraries_get_path('jquery.hoverIntent');
104
      if (!empty($hoverIntent_path) && file_exists($hoverIntent_path . '/jquery.hoverIntent.js')) {
105
        drupal_add_js($hoverIntent_path . '/jquery.hoverIntent.js');
106
      }
107
    }
108
  }
109

    
110
  // Add the slideshow elements.
111
  $vars['classes_array'][] = 'views_slideshow_cycle_teaser_section';
112

    
113
  $styles = '';
114
  if (isset($view->display_handler->display->display_options['style_options']['views_slideshow_cycle'])) {
115
    $styles = $view->display_handler->display->display_options['style_options']['views_slideshow_cycle'];
116
  }
117

    
118
  $styles_default = '';
119
  if (isset($view->display['default']->display_options['style_options']['views_slideshow_cycle'])) {
120
    $styles_default = $view->display['default']->display_options['style_options']['views_slideshow_cycle'];
121
  }
122

    
123
  // Retrive the number of items per frame
124
  if (isset($styles['items_per_slide']) && $styles['items_per_slide'] > 0) {
125
    $items_per_slide = $styles['items_per_slide'];
126
  }
127
  elseif (isset($styles_default['items_per_slide']) && $styles_default['items_per_slide'] > 0) {
128
    $items_per_slide = $styles_default['items_per_slide'];
129
  }
130
  else {
131
    $items_per_slide = 1;
132
  }
133

    
134
  $vars['items_per_slide'] = $items_per_slide;
135

    
136
  $items = array();
137
  $slideshow_count = 0;
138
  $rendered_rows = '';
139
  foreach ($rows as $count => $item) {
140
    $items[] = $item;
141
    if (count($items) == $items_per_slide || $count == (count($rows)-1)) {
142
      $rendered_rows .= theme(views_theme_functions('views_slideshow_cycle_main_frame_row', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array('vss_id' => $vss_id, 'items' => $items, 'count' => $slideshow_count, 'view' => $vars['view']));
143
      $items = array();
144
      $slideshow_count++;
145
    }
146
  }
147

    
148
  $vars['rendered_rows'] = $rendered_rows;
149
}
150

    
151
/**
152
 * Views Slideshow slideshow rows.
153
 *
154
 * @ingroup themeable
155
 */
156
function _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame_row(&$vars) {
157
  $current = $vars['count'] + 1;
158
  $vars['classes_array'][] = 'views_slideshow_cycle_slide';
159
  $vars['classes_array'][] = 'views_slideshow_slide views-row-' . $current;
160

    
161
  if ($vars['count']) {
162
    $vars['classes_array'][] =  'views_slideshow_cycle_hidden';
163
  }
164
  $vars['classes_array'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
165

    
166
  $vars['rendered_items'] = '';
167
  foreach ($vars['items'] as $item_count => $item) {
168
    $vars['rendered_items'] .= theme(views_theme_functions('views_slideshow_cycle_main_frame_row_item', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array('item' => $item, 'item_count' => $item_count, 'count' => $vars['count'], 'view' => $vars['view'], 'length' => count($vars['view']->result)));
169
  }
170
}
171

    
172
function _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame_row_item(&$vars) {
173
  $vars['classes_array'][] = 'views-row views-row-' . $vars['count'];
174
  $vars['classes_array'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
175
  if ($vars['count'] == 0) {
176
    $vars['classes_array'][] = 'views-row-first';
177
  }
178
  elseif ($vars['count'] == $vars['length'] - 1) {
179
    $vars['classes_array'][] = 'views-row-last';
180
  }
181

    
182
  /**
183
   * Support custom row classes.
184
   */
185
  if ($row_class = $vars['view']->style_plugin->get_row_class($vars['count'])) {
186
    $vars['classes_array'][] = $row_class;
187
  }
188
}