diff --git a/theme/galleria-container.tpl.php b/theme/galleria-container.tpl.php index a8e5690..253aa11 100644 --- a/theme/galleria-container.tpl.php +++ b/theme/galleria-container.tpl.php @@ -4,6 +4,4 @@ * Default output for a galleria node. */ ?> -
- -
+
diff --git a/theme/theme.inc b/theme/theme.inc index ec1e7c4..8d67750 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -9,6 +9,9 @@ /** * Template preprocess handler for 'galleria_container' theme. + * + * Builds the items "data" array. + * @see http://galleria.io/docs/references/data/ */ function template_preprocess_galleria_container(&$vars) { // Each Galleria instance gets a unique id @@ -24,55 +27,88 @@ function template_preprocess_galleria_container(&$vars) { $optionset = galleria_optionset_load('default'); } - // Attach Galleria JavaScript - galleria_add_js($galleria_id, $optionset); - // Prepare image elements $items = $vars['items']; - $vars['items'] = array(); - $thumb_style = empty($optionset->imagestyle_thumb) ? 'galleria_thumb' : $optionset->imagestyle_thumb; + + // All files, text, and html will be added via our "data" array + $data = array(); + + // Cycle through $items and add them to our data array foreach ($items as $delta => $item) { // Stop errors for empty URI. See issue [#1319268] for details. if (empty($item['uri'])) { continue; } - // Get URL for "normal" image - if (empty($optionset->imagestyle_normal)) { - $normal_url = file_create_url($item['uri']); - } - else { - $normal_url = image_style_url($optionset->imagestyle_normal, $item['uri']); - } + // If our $item is an "image" add this to the data array + if ($item['type'] == 'image') { + // Get URL for "thumbnail" image + if (empty($optionset->imagestyle_thumb)) { + $thumb_url = file_create_url($item['uri']); + } + else { + $thumb_url = image_style_url($optionset->imagestyle_thumb, $item['uri']); + } - // Get URL for "big" image (for lightbox and fullscreen) - if (empty($optionset->imagestyle_big)) { - $big_url = file_create_url($item['uri']); - } - elseif ($optionset->imagestyle_big != $optionset->imagestyle_normal) { - $big_url = image_style_url($optionset->imagestyle_big, $item['uri']); - } + // Get URL for "normal" image + if (empty($optionset->imagestyle_normal)) { + $normal_url = file_create_url($item['uri']); + } + else { + $normal_url = image_style_url($optionset->imagestyle_normal, $item['uri']); + } - if (!empty($big_url)) { - $options = array( - 'attributes' => array( - 'rel' => $big_url, - ) + // Get URL for "big" image (for lightbox and fullscreen) + if (empty($optionset->imagestyle_big)) { + $big_url = file_create_url($item['uri']); + } + else { + $big_url = image_style_url($optionset->imagestyle_big, $item['uri']); + } + + // Get slide "title" + if (!empty($item['title'])) { + $title = $item['title']; + } + elseif (isset($item['field_file_image_title_text'][LANGUAGE_NONE][0]['value'])) { + $title = $item['field_file_image_title_text'][LANGUAGE_NONE][0]['value']; + } + else $title = NULL; + + // Get slide "description" + if (!empty($item['alt'])) { + $desc = $item['alt']; + } + elseif (isset($item['field_file_image_alt_text'][LANGUAGE_NONE][0]['value'])) { + $desc = $item['field_file_image_alt_text'][LANGUAGE_NONE][0]['value']; + } + else $desc = NULL; + + $data[] = array( + 'thumb' => $thumb_url, + 'image' => $normal_url, + 'big' => $big_url, + 'title' => $title, + 'description' => $desc, + /* 'link' => 'http://my.destination.com', + 'layer' => '

This image is gr8

And this text will be on top of the image

'*/ ); } - else { - $options = array(); + + // If our $item is a "video" add this to the data array + elseif ($item['type'] == 'video') { + $data[] = array( + 'video' => file_create_url($item['uri']), + 'title' => $item['filename'], + ); } - $vars['items'][$delta] = array( - '#theme' => 'image_formatter', - '#item' => $item, - '#image_style' => $thumb_style, - '#path' => array( - 'path' => $normal_url, - 'options' => $options, - ), - ); } + + // Add "data" array to galleria option "dataSource" + $optionset->options['dataSource'] = $data; + + // Attach Galleria JavaScript + galleria_add_js($galleria_id, $optionset); } /**