comparison sites/all/modules/flexslider/theme/flexslider.theme.inc @ 2:b74b41bb73f0

-- Google analytics module
author danieleb <danielebarchiesi@me.com>
date Thu, 22 Aug 2013 17:22:54 +0100
parents
children
comparison
equal deleted inserted replaced
1:67ce89da90df 2:b74b41bb73f0
1 <?php
2 /**
3 * @file
4 * Theming functions for the flexslider module.
5 *
6 * Preprocessor functions fill variables for templates and helper
7 * functions to make theming easier.
8 */
9
10 /**
11 * Default theme implementation for flexslider_list
12 */
13 function theme_flexslider_list(&$vars) {
14 // Reference configuration variables
15 $optionset = &$vars['settings']['optionset'];
16 $items = &$vars['items'];
17 $attributes = &$vars['settings']['attributes'];
18 $type = &$vars['settings']['type'];
19 $output = '';
20
21 // Build the list
22 if (!empty($items)) {
23 $output .= "<$type" . drupal_attributes($attributes) . '>';
24 foreach ($items as $i => $item) {
25 // If the slide hasn't been set, build the slide using the image
26 // attributes given (assumes we're using a multi-image field)
27 // @todo need to allow for different types of field and collection fields
28 if (!isset($item['slide'])) {
29 $image_options = array(
30 'style_name' => $optionset->imagestyle_normal,
31 'path' => $item['uri'],
32 'height' => isset($item['height']) ? $item['height'] : '',
33 'width' => isset($item['width']) ? $item['width'] : '',
34 'alt' => $item['alt'],
35 'title' => $item['title'],
36 'attributes' => array(),
37 );
38 }
39
40 $caption = '';
41 if (!empty($item['title'])) {
42 $caption = $item['title'];
43 }
44 $output .= theme('flexslider_list_item', array(
45 'item' => isset($item['slide']) ? $item['slide'] : theme_image_style($image_options),
46 'item' => isset($item['slide']) ? $item['slide'] : ($optionset->imagestyle_normal ? theme_image_style($image_options) : theme_image($image_options)),
47
48 'thumb' => isset($item['thumb']) ? $item['thumb'] : image_style_url($optionset->imagestyle_thumbnail, $item['uri']),
49 'optionset' => $optionset,
50 'caption' => $caption,
51 ));
52 }
53 $output .= "</$type>";
54 }
55
56 return $output;
57 }
58
59 /**
60 * Default theme implementation for flexslider_list_item
61 */
62 function theme_flexslider_list_item(&$vars) {
63 // Reference configuration variables
64 $item = &$vars['item'];
65 $attributes = &$vars['settings']['attributes'];
66
67 if ($vars['optionset']->options['controlNav'] === "thumbnails" &&
68 isset($vars['thumb'])
69 ) {
70 $attributes['data-thumb'] = $vars['thumb'];
71 }
72
73 $caption = '';
74 if (!empty($vars['caption'])) {
75 $caption = '<p class="flex-caption">' . $vars['caption'] . '</p>';
76 }
77
78 $output = '';
79 $output .= '<li' . drupal_attributes($attributes) . '>' . $item . $caption . "</li>\n";
80
81 return $output;
82 }
83
84 /**
85 * Template preprocess handler for 'flexslider' theme.
86 */
87 function template_process_flexslider(&$vars) {
88
89 // Reference configuration variables
90 $optionset = &$vars['settings']['optionset'];
91 $settings = &$vars['settings'];
92 $items = &$vars['items'];
93
94 // Set the default container type
95 if (empty($settings['type'])) {
96 $settings['type'] = 'ul';
97 }
98
99 // Load the selected optionset
100 if (!empty($optionset)) {
101 $optionset = flexslider_optionset_load($optionset);
102 }
103
104 // Check if an optionset was loaded
105 if (empty($optionset)) {
106 // Fall back to 'default' option set
107 $optionset = flexslider_optionset_load('default');
108 watchdog('flexslider', 'Fallback to default optionset.', array(), WATCHDOG_WARNING);
109 }
110
111 // Configure attributes for containing elements
112 $attributes = array();
113 // Merge with defined attributes
114 if (isset($settings['attributes']) and is_array($settings['attributes'])) {
115 $attributes += $settings['attributes'];
116 }
117
118 // Set the ID for each flexslider instance if none is provided
119 if (empty($attributes['id'])) {
120 $flexslider_id = &drupal_static('flexslider_id', 0);
121 $attributes['id'] = 'flexslider-' . ++$flexslider_id;
122 }
123
124 // Add the namespace to any classes
125 // @todo figure out what this is supposed to do
126 if (!empty($attributes['class']) && !empty($optionset->options['namespace'])) {
127 foreach ($attributes['class'] as $key => $value) {
128 $attributes['class'][$key] = $optionset->options['namespace'] . $value;
129 }
130 }
131
132 // Add the flexslider class to be namespaced
133 $attributes['class'][] = 'flexslider';
134
135 // Add the attributes to the settings array.
136 $settings['attributes'] = $attributes;
137
138 // Finally, add the configuration to the page
139 flexslider_add($vars['settings']['attributes']['id'], $vars['settings']['optionset']);
140 }
141
142 /**
143 * Preprocess function for flexslider_list_item
144 */
145 function template_preprocess_flexslider_list(&$vars) {
146 // Reset the list of attributes
147 $vars['settings']['attributes'] = array(
148 // @todo find a way to detect the outter container class if possible
149 'class' => array('slides'),
150 );
151
152 }
153
154 /**
155 * Preprocess function for flexslider_list_item
156 */
157 function template_preprocess_flexslider_list_item(&$vars) {
158 // Reset the list of attributes
159 $vars['settings']['attributes'] = array();
160 //dpm($vars);
161
162 //$vars['item'] = implode('', $vars['item']);
163 // @todo add attributes for thumbnails
164 }