diff --git a/flexslider_fields/flexslider_fields.module b/flexslider_fields/flexslider_fields.module index 8429865..f67d4eb 100644 --- a/flexslider_fields/flexslider_fields.module +++ b/flexslider_fields/flexslider_fields.module @@ -23,6 +23,8 @@ function flexslider_fields_field_formatter_info() { 'optionset' => 'default', 'image_style' => '', 'caption' => FALSE, + 'photoswipe' => FALSE, + 'photoswipe_image_style' => '', ), ), ); @@ -82,6 +84,26 @@ function flexslider_fields_field_formatter_settings_form($field, $instance, $vie } } + if (module_exists('photoswipe')) { + $form['photoswipe'] = array( + '#title' => t('Use PhotoSwipe'), + '#type' => 'checkbox', + '#default_value' => $settings['photoswipe'], + ); + $form['photoswipe_image_style'] = array( + '#title' => t('PhotoSwipe Image style'), + '#type' => 'select', + '#default_value' => $settings['photoswipe_image_style'], + '#empty_option' => t('None (original image)'), + '#options' => $image_styles, + '#states' => array( + 'visible' => array( + ':input[name$="[settings_edit_form][settings][photoswipe]"]' => array('checked' => TRUE), + ), + ), + ); + } + return $form; } @@ -113,10 +135,24 @@ function flexslider_fields_field_formatter_settings_summary($field, $instance, $ $is = t('Image style: None (original image)'); } + // Display PhotoSwipe options + if ($settings['photoswipe']) { + if (!empty($settings['photoswipe_image_style'])) { + $ps = t('PhotoSwipe: %imagestyle', array('%imagestyle' => $settings['photoswipe_image_style'])); + } + else { + $ps = t('PhotoSwipe: Original image'); + } + } + else { + $ps = ''; + } + // Build settings summary $optionset = isset($optionset) ? $optionset->title : t('Default settings'); $summary[] = t('Option set: %optionset', array('%optionset' => $optionset)); $summary[] = $is; + $summary[] = $ps; return implode('
', $summary); } @@ -174,9 +210,40 @@ function flexslider_fields_field_formatter_view($entity_type, $entity, $field, $ $item['caption'] = filter_xss($item['item']['title']); } + // Use PhotoSwipe if needed + if ($display['settings']['photoswipe']) { + $photoswipe_dimensions = array( + 'width' => $item['item']['width'], + 'height' => $item['item']['height'], + ); + + if ($style_name = $display['settings']['photoswipe_image_style']) { + $photoswipe_image_url = image_style_url($style_name,$item['item']['uri']); + image_style_transform_dimensions($style_name, $photoswipe_dimensions); + } else { + $photoswipe_image_url = file_create_url($item['item']['uri']); + } + + $photoswipe_options = array( + 'html' => TRUE, + 'attributes' => array( + 'class' => array('photoswipe'), + 'data-size' => $photoswipe_dimensions['width'] . 'x' . $photoswipe_dimensions['height'] + ), + ); + if ($display['settings']['caption']) { + $photoswipe_options['attributes']['data-overlay-title'] = $item['caption']; + } + $item['slide'] = l($item['slide'], $photoswipe_image_url, $photoswipe_options); + } + $items[$key] = $item; } + if ($display['settings']['photoswipe']) { + photoswipe_load_assets(); + } + $element = array( '#theme' => 'flexslider', '#items' => $items, diff --git a/theme/flexslider.theme.inc b/theme/flexslider.theme.inc index c3b27d4..505e499 100755 --- a/theme/flexslider.theme.inc +++ b/theme/flexslider.theme.inc @@ -15,6 +15,9 @@ function theme_flexslider_list(&$vars) { $optionset = &$vars['settings']['optionset']; $items = &$vars['items']; $attributes = &$vars['settings']['attributes']; + if (isset($vars['settings']['photoswipe']) && $vars['settings']['photoswipe']) { + $attributes['class'][] = 'photoswipe-gallery'; + } $type = &$vars['settings']['type']; $output = '';