You are here

function _views_slideshow_galleria_add_js in Views Slideshow: Galleria 6

Same name and namespace in other branches
  1. 6.3 views_slideshow_galleria.theme.inc \_views_slideshow_galleria_add_js()
  2. 7.3 views_slideshow_galleria.theme.inc \_views_slideshow_galleria_add_js()
1 call to _views_slideshow_galleria_add_js()
template_preprocess_views_slideshow_galleria in themes/views_slideshow_galleria.theme.inc
We'll grab only the first image from each row.

File

themes/views_slideshow_galleria.theme.inc, line 59
Theme & preprocess functions for the Views Slideshow: Galleria module.

Code

function _views_slideshow_galleria_add_js($options, $id) {
  static $loaded_themes;

  // Keep track of which Galleria plugin JS themes have already been loaded.
  if (!isset($loaded_themes)) {
    $loaded_themes = array();
  }

  // Find the path to our plugin.
  $path = views_slideshow_galleria_path();

  // Add the required JS and CSS.
  drupal_add_js($path . '/galleria.js');
  $drupal_path = drupal_get_path('module', 'views_slideshow_galleria') . '/themes';
  drupal_add_js($drupal_path . '/js/views_slideshow_galleria.js');
  if ($options['advanced']['history']) {
    drupal_add_js($path . '/plugins/galleria.history.js');
  }
  $settings = array(
    'theme' => check_plain($options['theme']),
    'carousel' => $options['carousel'] ? TRUE : 0,
    'carousel_follow' => (bool) $options['carousel_follow'],
    'carousel_speed' => (int) $options['carousel_speed'],
    'data_image_selector' => check_plain($options['advanced']['data_image_selector']),
    'data_source' => check_plain($options['advanced']['data_source']),
    'data_type' => check_plain($options['advanced']['data_type']),
    'debug' => $options['advanced']['debug'] ? TRUE : 0,
    'image_crop' => $options['image_crop'] ? TRUE : 0,
    'image_margin' => (int) $options['image_margin'],
    'image_position' => check_plain($options['image_position']),
    'keep_source' => $options['advanced']['keep_source'] ? TRUE : 0,
    'popup_links' => $options['popup_links'] ? TRUE : 0,
    'queue' => $options['queue'] ? TRUE : 0,
    'show' => (int) $options['show'],
    'thumb_crop' => $options['thumb_crop'] ? TRUE : 0,
    'thumb_margin' => (int) $options['thumb_margin'],
    'transition' => check_plain($options['transition']),
    'transition_speed' => (int) $options['transition_speed'],
  );

  // Set themeURL to the path to the JS theme file for the galleria.
  if ($options['custom_theme_options']['custom_theme'] && $options['custom_theme_options']['theme_path']) {
    $settings['theme'] = check_plain($options['custom_theme_options']['custom_theme']);
    $settings['themeURL'] = base_path() . '/' . $options['custom_theme_options']['theme_path'];
  }
  else {
    if ($settings['theme'] && !$settings['custom_theme_options']['theme_path']) {
      $settings['themeURL'] = base_path() . $path . "/themes/{$settings['theme']}/galleria.{$settings['theme']}.js";
    }
    else {
      if ($settings['custom_theme_options']['theme_path']) {

        // We'll allow a custom theme path to override the default.
        $settings['themeURL'] = base_path() . '/' . $options['custom_theme_options']['theme_path'];
      }
      else {

        // No theme specified; we assume they're using a Drupal theme for styling.
        $settings['themeURL'] = FALSE;
      }
    }
  }
  if ($settings['themeURL'] && !isset($loaded_themes[$settings['themeURL']])) {
    drupal_add_js('Galleria.loadTheme("' . $settings['themeURL'] . '")', 'inline');
    $loaded_themes[$settings['themeURL']] = TRUE;
  }

  // Autoplay is FALSE or the number of MS.
  $settings['autoplay'] = $options['autoplay'] && (int) $options['autoplay_ms'] ? (int) $options['autoplay_ms'] : 0;

  // Carousel_steps is 'auto' or an integer.
  $settings['carousel_steps'] = $options['carousel_steps'] == 'auto' ? 'auto' : (int) $options['carousel_steps'];
  if ($options['advanced']['data_config']) {
    $settings['data_config'] = check_plain($options['advanced']['data_config']);
  }
  if ($options['advanced']['extend']) {
    $settings['extend'] = check_plain($options['advanced']['extend']);
  }

  // Height is 'auto' or an integer.
  if ($options['height'] == 'auto' || !(int) $options['height']) {
    $settings['height'] = 'auto';
  }
  else {
    $settings['height'] = (int) $options['height'];
  }
  if ($options['max_scale_ratio'] && is_numeric($options['max_scale_ratio'])) {
    $settings['max_scale_ratio'] = (int) $options['max_scale_ratio'];
  }
  if ($options['advanced']['on_image']) {
    $settings['on_image'] = $options['advanced']['on_image'];
  }
  $settings['preload'] = $options['preload'] == 'auto' ? 'auto' : (int) $options['preload'];
  $settings['thumb_quality'] = $options['advanced']['thumb_quality'] == 'auto' ? 'auto' : (int) $options['advanced']['thumb_quality'];
  $settings['thumbnails'] = $options['thumbnails'] == 'empty' ? 'empty' : (int) $options['thumbnails'];
  drupal_add_js(array(
    'viewsSlideshowGalleria' => array(
      $id => $settings,
    ),
  ), 'setting');
}