You are here

royalslider.module in RoyalSlider Integration 7

Same filename and directory in other branches
  1. 8 royalslider.module

RoyalSlider module.

File

royalslider.module
View source
<?php

/**
 * @file
 * RoyalSlider module.
 */
define('ROYALSLIDER_VERSION', '9.4.92');

/**
 * Implements hook_permission().
 */
function royalslider_permission() {
  return array(
    'administer royalslider' => array(
      'title' => t('Administer the RoyalSlider module'),
    ),
  );
}

/**
 * Implements hook_libraries_info().
 */
function royalslider_libraries_info() {
  $libraries['royalslider'] = array(
    'name' => 'RoyalSlider',
    'vendor url' => 'http://dimsemenov.com/plugins/royal-slider/',
    'download url' => 'http://dimsemenov.com/plugins/royal-slider/pricing/',
    'version arguments' => array(
      'file' => 'jquery.royalslider.min.js',
      'pattern' => '/jquery.royalslider v(\\d+\\.+\\d+\\.+\\d+)/',
      'lines' => 3,
    ),
    'files' => array(
      'js' => array(
        'jquery.royalslider.min.js',
      ),
      'css' => array(
        'royalslider.css',
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_libraries_info_alter().
 */
function royalslider_libraries_info_alter(&$libraries) {

  // Add support for jQuery Easing module
  if (module_exists('jqeasing')) {
    $libraries['royalslider']['dependencies'][] = 'easing (>=1.3)';
  }
}

/**
 * Implements hook_library().
 *
 * We also define RoyalSlider through the core library callbacks
 */
function royalslider_library() {
  $library_path = libraries_get_path('royalslider');
  $libraries['royalslider'] = array(
    'title' => 'RoyalSlider',
    'website' => 'http://dimsemenov.com/plugins/royal-slider/',
    'version' => ROYALSLIDER_VERSION,
    'js' => array(
      $library_path . '/jquery.royalslider.min.js' => array(
        'scope' => 'footer',
      ),
    ),
    'css' => array(
      $library_path . '/royalslider.css' => array(
        'type' => 'file',
        'media' => 'screen',
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_theme().
 */
function royalslider_theme($existing, $type, $theme, $path) {
  return array(
    'royalslider' => array(
      'variables' => array(
        'royalslider_id' => '',
        'optionset' => 'default',
        'skin' => '',
        'items' => array(),
      ),
      'path' => $path . '/theme',
      'template' => 'royalslider',
      'file' => 'royalslider.theme.inc',
    ),
    'royalslider_item' => array(
      'variables' => array(
        'royalslider_id' => '',
        'optionset' => 'default',
        'item' => NULL,
      ),
      'path' => $path . '/theme',
      'template' => 'royalslider-item',
      'file' => 'royalslider.theme.inc',
    ),
  );
}

/**
 * Implements hook_help().
 */
function royalslider_help($path, $arg) {
  switch ($path) {
    case 'admin/config/media/royalslider/edit/%':
      return '<p>' . t('An <em>option set</em> defines exactly how a royalslider image gallery looks like on your site. ' . 'It is s a combination of <a href="@styles">image styles</a> for the various image sizes and RoyalSlider library options.', array(
        '@styles' => url('admin/config/media/image-styles'),
      )) . '<br />' . t('For a full documentation of all options, refer to the official @docs.', array(
        '@docs' => l(t('RoyalSlider documentation'), 'http://dimsemenov.com/plugins/royal-slider/'),
      )) . '</p>';
  }
}

/**
 * Implements hook_ctools_plugin_api().
 */
function royalslider_ctools_plugin_api($owner, $api) {
  if ($owner == 'royalslider' && $api == 'royalslider_default_preset') {
    return array(
      'version' => 1,
    );
  }
}

/**
 * Implements hook_ctools_plugin_directory().
 */
function royalslider_ctools_plugin_directory($module, $type) {
  if ($type == 'export_ui') {
    return 'plugins/export_ui';
  }
}

/**
 * Create a new optionset object
 *
 * Note that this function does not save the optionset to the database.
 * @see royalslider_optionset_save()
 */
function royalslider_optionset_create($values = array()) {
  ctools_include('export');
  $optionset = ctools_export_crud_new('royalslider_optionset');

  // Set the options to an array
  $optionset->options = array();

  // Assign specified values
  if (isset($values['name'])) {
    $optionset->name = $values['name'];
  }
  if (isset($values['title'])) {
    $optionset->title = $values['title'];
  }
  if (isset($values['skin'])) {
    $optionset->skin = $values['skin'];
  }
  if (isset($values['imagestyle_fullscreen'])) {
    $optionset->imagestyle_fullscreen = $values['imagestyle_fullscreen'];
  }
  if (isset($values['imagestyle_normal'])) {
    $optionset->imagestyle_normal = $values['imagestyle_normal'];
  }
  if (isset($values['imagestyle_thumbnail'])) {
    $optionset->imagestyle_thumbnail = $values['imagestyle_thumbnail'];
  }
  if (isset($values['options']) and is_array($values['options'])) {
    $optionset->options = $values['options'];
  }

  // Merge default settings with any given settings
  $optionset_defaults = _royalslider_optionset_defaults();
  $optionset->options = $optionset_defaults += $optionset->options;
  return $optionset;
}

/**
 * Fetches all option sets from the database and returns them as an associative array.
 */
function royalslider_optionset_load_all() {
  ctools_include('export');
  $optionsets = ctools_export_crud_load_all('royalslider_optionset');
  foreach ($optionsets as $optionset) {

    // Ensure the optionset is typecast after being loaded from DB.
    _royalslider_typecast_optionset($optionset->options);
  }
  return $optionsets;
}

/**
 * Fetches the given option set and returns it as an object or NULL, if no set could be found.
 */
function royalslider_optionset_load($optionset_name) {
  ctools_include('export');
  $optionset = ctools_export_crud_load('royalslider_optionset', $optionset_name);

  // Ensure the optionset is typecast after being loaded from DB.
  _royalslider_typecast_optionset($optionset->options);
  return $optionset;
}

/**
 * Checks whether an option set with the given name already exists.
 */
function royalslider_optionset_exists($optionset_name) {
  ctools_include('export');
  $optionset = ctools_export_crud_load('royalslider_optionset', $optionset_name);
  return isset($optionset->name);
}

/**
 * Saves the given optionset to the database.
 * Set the $new flag if this optionset has not been written before.
 *
 * @param object
 *   The optionset to save.
 * @param boolean
 *   Whether it's a new optionset or not.
 *
 * @return object|boolean
 *  Returns the newly saved object, FALSE otherwise.
 */
function royalslider_optionset_save($optionset, $new = FALSE) {

  // If the machine name is missing or already in use, return an error.
  if (empty($optionset->name) or FALSE != royalslider_optionset_exists($optionset->name) and $new) {
    return FALSE;
  }

  // Check for an invalid list of options
  if (isset($optionset->options) and !is_array($optionset->options)) {
    return FALSE;
  }

  // If the title is missing, default to the name
  if (empty($optionset->title)) {
    $optionset->title = $optionset->name;
  }

  // Merge default settings with any given settings
  $optionset_defaults = _royalslider_optionset_defaults();
  $optionset->options = $optionset_defaults += $optionset->options;

  // Prepare the database values.
  $db_values = array(
    'name' => $optionset->name,
    'title' => $optionset->title,
    'options' => _royalslider_typecast_optionset($optionset->options),
  );
  if ($new) {
    $result = drupal_write_record('royalslider_optionset', $db_values);
  }
  else {
    $result = drupal_write_record('royalslider_optionset', $db_values, 'name');
  }

  // Return the object if the values were saved successfully.
  if ($new and SAVED_NEW == $result or !$new and SAVED_UPDATED == $result) {
    return $optionset;
  }

  // Otherwise, an error occured
  return FALSE;
}

/**
 * Deletes the given option set from the database.
 *
 * @param object|string $optionset
 *  Optionset object or machine name
 */
function royalslider_optionset_delete($optionset) {
  if (isset($optionset->name)) {
    $name = $optionset->name;
  }
  else {
    $name = $optionset;
  }
  db_delete('royalslider_optionset')
    ->condition('name', $name)
    ->execute();
}

/**
 * Default settings for a newly created option set
 *
 * @param string $key [optional]
 *  Get specific default value
 *
 * @return array
 *
 */
function _royalslider_optionset_defaults($key = NULL) {
  $defaults = array(
    // General.
    'manuallyInit' => FALSE,
    'loop' => FALSE,
    'loopRewind' => FALSE,
    'randomizeSlides' => FALSE,
    'usePreloader' => TRUE,
    'numImagesToPreload' => 4,
    'slidesOrientation' => 'horizontal',
    'globalCaption' => FALSE,
    // Full Screen.
    'fullscreen' => array(
      'enabled' => FALSE,
      'keyboardNav' => TRUE,
      'buttonFS' => TRUE,
      'nativeFS' => FALSE,
    ),
    // Navigation.
    'controlNavigation' => 'bullets',
    'controlsInside' => TRUE,
    'sliderDrag' => TRUE,
    'sliderTouch' => TRUE,
    'keyboardNavEnabled' => FALSE,
    'navigateByClick' => TRUE,
    'arrowsNav' => TRUE,
    'arrowsNavAutoHide' => TRUE,
    'arrowsNavHideOnTouch' => FALSE,
    // Thumbnails.
    'thumbs' => array(
      'drag' => TRUE,
      'touch' => TRUE,
      'orientation' => 'horizontal',
      'arrows' => TRUE,
      'spacing' => 4,
      'arrowsAutoHide' => FALSE,
      'autoCenter' => TRUE,
      'transitionSpeed' => 600,
      'fitInViewport' => TRUE,
      'firstMargin' => TRUE,
      'arrowLeft' => NULL,
      'arrowRight' => NULL,
      'appendSpan' => FALSE,
    ),
    // Transitions.
    'transitionType' => 'move',
    'transitionSpeed' => 600,
    'easeInOut' => 'easeInOutSine',
    'easeOut' => 'easeOutSine',
    'allowCSS3' => TRUE,
    // Note: that since only 3 easing methods are available
    // in CSS3 by default with RoyalSlider and we'd have to implement the rest
    // ourselves, it's probably best to set this to FALSE in most Option Sets.
    // However, in order to maintain compatibility with the RoyalSlider API
    // we're leaving this be.
    'addActiveClass' => FALSE,
    'fadeinLoadedSlide' => TRUE,
    // Dimensions.
    'autoScaleSlider' => FALSE,
    'autoScaleSliderWidth' => 800,
    'autoScaleSliderHeight' => 400,
    'autoHeight' => FALSE,
    'imageScaleMode' => 'fit-if-smaller',
    'imageScalePadding' => 4,
    'imageAlignCenter' => TRUE,
    'imgWidth' => NULL,
    'imgHeight' => NULL,
    'slidesSpacing' => 8,
    // Autoplay
    'autoplay' => array(
      'enabled' => FALSE,
      'stopAtAction' => TRUE,
      'pauseOnHover' => TRUE,
      'delay' => 300,
    ),
    // Visible Nearby
    'visibleNearby' => array(
      'enabled' => TRUE,
      'centerArea' => 0.6,
      'center' => TRUE,
      'navigateByCenterClick' => TRUE,
      'breakpoint' => 0,
      'breakpointCenterArea' => 0.8,
    ),
    // Deep linking
    'deeplinking' => array(
      'enabled' => FALSE,
      'change' => FALSE,
      'prefix' => '',
    ),
    // Video
    'video' => array(
      'autoHideArrows' => TRUE,
      'autoHideControlNav' => FALSE,
      'autoHideBlocks' => FALSE,
      'youTubeCode' => '<iframe src="http://www.youtube.com/embed/%id%?rel=1&autoplay=1&showinfo=0" frameborder="no"></iframe>',
      'vimeoCode' => '<iframe src="http://player.vimeo.com/video/%id%?byline=0&amp;portrait=0&amp;autoplay=1" frameborder="no" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
    ),
    // Drupal-specific.
    'drupalAutoSetSliderDimensions' => FALSE,
    'drupalAutoSetImageDimensions' => TRUE,
  );

  // We add typecasts to ensure the variables get JSON encoded properly.
  _royalslider_typecast_optionset($defaults);

  // Return the specific item.
  if (isset($key) and array_key_exists($key, $defaults)) {
    return $defaults[$key];
  }

  // Return all items
  return $defaults;
}

/**
 * Adds the typecasting to the values so that the generated
 * json array keeps the right values
 */
function _royalslider_typecast_optionset(&$options) {
  if (isset($options) && !empty($options)) {
    foreach ($options as $key => $value) {
      switch ($key) {
        case 'slidesOrientation':
        case 'controlNavigation':
        case 'transitionType':
        case 'easeInOut':
        case 'easeOut':
        case 'imageScaleMode':
          $options[$key] = (string) $value;
          break;
        case 'numImagesToPreload':
        case 'transitionSpeed':
        case 'autoScaleSliderWidth':
        case 'autoScaleSliderHeight':
        case 'imageScalePadding':
        case 'slidesSpacing':
          $options[$key] = (int) $value;
          break;
        case 'manuallyInit':
        case 'loop':
        case 'loopRewind':
        case 'randomizeSlides':
        case 'usePreloader':
        case 'globalCaption':
        case 'controlsInside':
        case 'sliderDrag':
        case 'sliderTouch':
        case 'keyboardNavEnabled':
        case 'navigateByClick':
        case 'arrowsNav':
        case 'arrowsNavAutoHide':
        case 'arrowsNavHideOnTouch':
        case 'allowCSS3':
        case 'addActiveClass':
        case 'fadeinLoadedSlide':
        case 'autoScaleSlider':
        case 'autoHeight':
        case 'imageAlignCenter':
        case 'drupalAutoSetSliderDimensions':
        case 'drupalAutoSetImageDimensions':
          $options[$key] = (bool) $value;
          break;
        case 'imgWidth':
        case 'imgHeight':
          $options[$key] = empty($value) ? NULL : $value;
          break;
        case 'fullscreen':
          foreach ($value as $k => $v) {
            switch ($k) {
              case 'enabled':
              case 'keyboardNav':
              case 'buttonFS':
              case 'nativeFS':
                $options['fullscreen'][$k] = (bool) $v;
                break;
            }
          }
          break;
        case 'thumbs':
          foreach ($value as $k => $v) {
            switch ($k) {
              case 'orientation':
                $options['thumbs'][$k] = (string) $v;
                break;
              case 'spacing':
              case 'transitionSpeed':
                $options['thumbs'][$k] = (int) $v;
                break;
              case 'drag':
              case 'touch':
              case 'arrows':
              case 'arrowsAutoHide':
              case 'autoCenter':
              case 'fitInViewport':
              case 'firstMargin':
              case 'appendSpan':
                $options['thumbs'][$k] = (bool) $v;
                break;
              case 'arrowLeft':
              case 'arrowRight':
                $options['thumbs'][$k] = empty($v) ? NULL : $v;
                break;
            }
          }
          break;
        case 'autoplay':
          foreach ($value as $k => $v) {
            switch ($k) {
              case 'enabled':
              case 'stopAtAction':
              case 'pauseOnHover':
                $options['autoplay'][$k] = (bool) $v;
                break;
              case 'delay':
                $options['autoplay'][$k] = (int) $v;
                break;
            }
          }
          break;
        case 'visibleNearby':
          foreach ($value as $k => $v) {
            switch ($k) {
              case 'enabled':
              case 'center':
              case 'navigateByCenterClick':
                $options['visibleNearby'][$k] = (bool) $v;
                break;
              case 'centerArea':
              case 'breakpoint':
              case 'breakpointCenterArea':
                $options['visibleNearby'][$k] = (double) $v;
                break;
            }
          }
          break;
        case 'deeplinking':
          foreach ($value as $k => $v) {
            switch ($k) {
              case 'enabled':
              case 'change':
                $options['deeplinking'][$k] = (bool) $v;
                break;
              case 'prefix':
                $options['deeplinking'][$k] = (string) $v;
                break;
            }
          }
          break;
        case 'video':
          foreach ($value as $k => $v) {
            switch ($k) {
              case 'autoHideArrows':
              case 'autoHideControlNav':
              case 'autoHideBlocks':
                $options['video'][$k] = (bool) $v;
                break;
              case 'youTubeCode':
              case 'vimeoCode':
                $options['video'][$k] = (string) $v;
                break;
            }
          }
          break;
      }
    }
  }
}

/**
 * List of all easing methods available from jQuery Easing v1.3.
 *
 * Note: This should really go in the jqeasing module. But we're keeping it here
 * since that module doesn't seem like it's getting updated too often.
 *
 * @return array
 */
function _royalslider_jqeasing_options() {
  $easing_methods =& drupal_static(__FUNCTION__);
  if (!isset($easing_methods)) {
    $easing_methods = array(
      'jswing',
      'def',
      'easeInQuad',
      'easeOutQuad',
      'easeInOutQuad',
      'easeInCubic',
      'easeOutCubic',
      'easeInOutCubic',
      'easeInQuart',
      'easeOutQuart',
      'easeInOutQuart',
      'easeInQuint',
      'easeOutQuint',
      'easeInOutQuint',
      'easeInSine',
      'easeOutSine',
      'easeInOutSine',
      'easeInExpo',
      'easeOutExpo',
      'easeInOutExpo',
      'easeInCirc',
      'easeOutCirc',
      'easeInOutCirc',
      'easeInElastic',
      'easeOutElastic',
      'easeInOutElastic',
      'easeInBack',
      'easeOutBack',
      'easeInOutBack',
      'easeInBounce',
      'easeOutBounce',
      'easeInOutBounce',
    );

    // Allow other modules to alter this.
    drupal_alter('royalslider_easing', $easing_methods);

    // Make this into an associative array.
    $easing_methods = drupal_map_assoc($easing_methods);
  }
  return $easing_methods;
}

/**
 * This function loads the required JavaScripts and settings for a RoyalSlider
 * instance.
 *
 * @param string
 *  ID attribute for RoyalSlider container. If none is set, it's assumed that
 *  the markup and settings are being set manually.
 * @param object
 *  Optionally, specify an Option Set to load settings from. If left blank,
 *  it's assumed that the markup and settings are being set manually.
 * @param string
 *  Optionally, specify a skin to override the one defined by the Option Set.
 */
function royalslider_add($id = NULL, $optionset = NULL, $skin = '') {

  // Check optionset value
  if (is_string($optionset)) {
    if (!($optionset = royalslider_optionset_load($optionset))) {
      watchdog('royalslider', 'Invalid optionset name supplied to royalslider_add: @name', array(
        '@name' => $name,
      ), WATCHDOG_WARNING);
      return;
    }
  }

  // If the ID or optionset aren't set, it is assumed the settings will be set
  // manually.
  if (!empty($id) && !empty($optionset)) {

    // Strip out default values so we're not adding extraneous settings.
    $js_options = _royalslider_remove_default_optionset_options($optionset->options);

    // Add JavaScript settings
    $js_settings = array(
      'optionsets' => array(
        $optionset->name => $js_options,
      ),
      'instances' => array(
        $id => array(
          'optionset' => $optionset->name,
        ),
      ),
    );

    // Allow other modules to alter this.
    drupal_alter('royalslider_settings', $js_settings, $id, $optionset);

    // Finally add JS settings.
    drupal_add_js(array(
      'royalslider' => $js_settings,
    ), 'setting');
  }

  // Add RoyalSlider library (JS + CSS).
  libraries_load('royalslider');

  // Static cache to avoid loading the same resources multiple times.
  $loaded =& drupal_static(__FUNCTION__, array());

  // Now add skin resources.
  if (empty($skin)) {
    $skin = !empty($optionset) ? $optionset->skin : 'default';
  }
  if (!array_key_exists($skin, $loaded)) {
    drupal_add_css(libraries_get_path('royalslider') . "/skins/{$skin}/rs-{$skin}.css");
    $loaded[] = $skin;
  }

  // Finally, add RoyalSlider loader JS.
  if (!array_key_exists('royalslider.load', $loaded)) {
    drupal_add_js(drupal_get_path('module', 'royalslider') . '/js/royalslider.load.js', array(
      'type' => 'file',
      'scope' => 'footer',
    ));
    $loaded[] = 'royalslider.load';
  }
}

/**
 * Returns an array of available RoyalSlider skins, keyed by machine-name.
 * Custom skins should adopt the same naming conventions for directory and
 * filenames as the ones provided by default by RoyalSlider, ie: foo/rs-foo.css
 *
 * @return array
 */
function royalslider_skins() {
  $skins =& drupal_static(__FUNCTION__, NULL);
  if (!isset($skins)) {
    $skins = array(
      'default' => array(
        'name' => t('Default'),
        'class' => 'rsDefault',
      ),
      'default-inverted' => array(
        'name' => t('Default inverted'),
        'class' => 'rsDefaultInv',
      ),
      'minimal-white' => array(
        'name' => t('Minimal white'),
        'class' => 'rsMinW',
      ),
      'universal' => array(
        'name' => t('Universal'),
        'class' => 'rsUni',
      ),
    );

    // Let other modules alter this.
    drupal_alter('royalslider_skins', $skins);
  }
  return $skins;
}

/**
 * Return an array of RoyalSlider Option Sets.
 * It's used to populate select form items.
 *
 * @return array
 *   An array of Option Set titles, keyed by machine name.
 */
function _royalslider_optionsets() {
  $optionsets = array();
  foreach (royalslider_optionset_load_all() as $name => $info) {
    $optionsets[$name] = $info->title;
  }
  return $optionsets;
}

/**
 * Return an array of RoyalSlider Skins.
 * It's used to populate select form items.
 *
 * @return array
 *   An array of skin names, keyed by machine name.
 */
function _royalslider_skins() {
  $skins = array(
    '' => t('Use Option Set skin'),
  );
  foreach (royalslider_skins() as $name => $info) {
    $skins[$name] = $info['name'];
  }
  return $skins;
}

/**
 * Implements hook_field_formatter_info().
 */
function royalslider_field_formatter_info() {
  $return = array();
  $return['royalslider'] = array(
    'label' => t('Royalslider'),
    'description' => t('Display images in a RoyalSlider slideshow.'),
    'field types' => array(
      'image',
    ),
    'settings' => array(
      // All settings stored in option sets.
      'optionset' => 'default',
      // Allow the skin to be overridden per field formatter instance.
      'skin' => '',
      // Allow limiting to max images
      'max' => '#',
    ),
  );
  return $return;
}

/**
 * Implements hook_field_formatter_settings_form().
 */
function royalslider_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $element = array();
  switch ($display['type']) {
    case 'royalslider':
      $element['optionset'] = array(
        '#title' => t('Option Set'),
        '#description' => t('All RoyalSlider settings are stored in Option Sets.'),
        '#type' => 'select',
        '#options' => _royalslider_optionsets(),
        '#default_value' => $settings['optionset'],
      );
      $element['skin'] = array(
        '#title' => t('Skin'),
        '#description' => t('Override the Option Set\'s skin.'),
        '#type' => 'select',
        '#options' => _royalslider_skins(),
        '#default_value' => $settings['skin'],
      );
      $element['max'] = array(
        '#title' => t('Max Images'),
        '#description' => t('Limit the number of images displayed.'),
        '#type' => 'textfield',
        '#size' => 3,
        '#default_value' => $settings['max'],
      );
      break;
  }
  return $element;
}

/**
 * Implements hook_field_formatter_settings_summary().
 */
function royalslider_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $return = array();
  switch ($display['type']) {
    case 'royalslider':
      $optionsets = _royalslider_optionsets();
      $return[] = t('Option Set: @optionset', array(
        '@optionset' => $optionsets[$settings['optionset']],
      ));
      if (!empty($settings['skin'])) {
        $skins = _royalslider_skins();
        $return[] = t('Skin override: @skin', array(
          '@skin' => $skins[$settings['skin']],
        ));
      }
      $return[] = t('Max Images: @max', array(
        '@max' => $settings['max'],
      ));
      break;
  }
  return implode('<br />', $return);
}

/**
 * Implements hook_field_formatter_view().
 */
function royalslider_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, &$items, $display) {
  $settings = $display['settings'];
  $element = array();
  switch ($display['type']) {
    case 'royalslider':
      list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
      $images = $settings['max'] === '#' ? $items : array_slice($items, 0, $settings['max']);

      // We merge all items into one slideshow element.
      $element[0] = array(
        '#theme' => 'royalslider',
        '#royalslider_id' => "royalslider-{$entity_type}-{$bundle}-{$instance['field_name']}-{$id}",
        '#optionset' => $settings['optionset'],
        '#skin' => $settings['skin'],
        '#items' => $images,
      );
      break;
  }
  return $element;
}

/**
 * Strip options with default values from the Option Set options so that we
 * don't add unecessary options.
 *
 * @param array
 *   An array of Option Set options.
 * @return array
 *   An array of reduced Option Set options.
 */
function _royalslider_remove_default_optionset_options($options) {
  $defaults = _royalslider_optionset_defaults();
  foreach ($options as $key => $value) {
    if (array_key_exists($key, $defaults)) {
      if (is_array($value)) {
        foreach ($value as $k => $v) {

          // For nested option groups, if it has an "enabled" flag and it's set to
          // FALSE, remove the entire sub-group.
          if ($k === 'enabled' && $v === FALSE) {
            unset($options[$key]);
            if ($key === 'visibleNearby') {

              // As false is not the default option for visibleNearby.
              // Add the enabled key again.
              $options[$key][$k] = $v;
            }
          }
          else {
            if ($key === 'visibleNearby' && $k === 'enabled' && $v === TRUE) {

              // Exception for the visibleNearby option.
              // This is the only nested option group that has TRUE as its default for enabled.
              // "enabled" needs to be part of the optionset for it to work.
              // Therefor it is not unset here.
            }
            else {
              if ($v === $defaults[$key][$k]) {
                unset($options[$key][$k]);
              }
            }
          }
        }

        // "Thumbs" is the exception, because it doesn't have an "enabled"
        // flag and, instead, is toggled on or off by the "controlNavigation"
        // option.
        if ($key === 'thumbs') {
          if (!isset($options['controlNavigation']) || $options['controlNavigation'] !== 'thumbnails') {
            unset($options[$key]);
          }
        }
      }
      else {
        if ($value === $defaults[$key]) {
          unset($options[$key]);
        }
      }
    }
  }
  return $options;
}

Functions

Namesort descending Description
royalslider_add This function loads the required JavaScripts and settings for a RoyalSlider instance.
royalslider_ctools_plugin_api Implements hook_ctools_plugin_api().
royalslider_ctools_plugin_directory Implements hook_ctools_plugin_directory().
royalslider_field_formatter_info Implements hook_field_formatter_info().
royalslider_field_formatter_settings_form Implements hook_field_formatter_settings_form().
royalslider_field_formatter_settings_summary Implements hook_field_formatter_settings_summary().
royalslider_field_formatter_view Implements hook_field_formatter_view().
royalslider_help Implements hook_help().
royalslider_libraries_info Implements hook_libraries_info().
royalslider_libraries_info_alter Implements hook_libraries_info_alter().
royalslider_library Implements hook_library().
royalslider_optionset_create Create a new optionset object
royalslider_optionset_delete Deletes the given option set from the database.
royalslider_optionset_exists Checks whether an option set with the given name already exists.
royalslider_optionset_load Fetches the given option set and returns it as an object or NULL, if no set could be found.
royalslider_optionset_load_all Fetches all option sets from the database and returns them as an associative array.
royalslider_optionset_save Saves the given optionset to the database. Set the $new flag if this optionset has not been written before.
royalslider_permission Implements hook_permission().
royalslider_skins Returns an array of available RoyalSlider skins, keyed by machine-name. Custom skins should adopt the same naming conventions for directory and filenames as the ones provided by default by RoyalSlider, ie: foo/rs-foo.css
royalslider_theme Implements hook_theme().
_royalslider_jqeasing_options List of all easing methods available from jQuery Easing v1.3.
_royalslider_optionsets Return an array of RoyalSlider Option Sets. It's used to populate select form items.
_royalslider_optionset_defaults Default settings for a newly created option set
_royalslider_remove_default_optionset_options Strip options with default values from the Option Set options so that we don't add unecessary options.
_royalslider_skins Return an array of RoyalSlider Skins. It's used to populate select form items.
_royalslider_typecast_optionset Adds the typecasting to the values so that the generated json array keeps the right values

Constants

Namesort descending Description
ROYALSLIDER_VERSION @file RoyalSlider module.