You are here

function royalslider_add in RoyalSlider Integration 7

This function loads the required JavaScripts and settings for a RoyalSlider instance.

Parameters

string: ID attribute for RoyalSlider container. If none is set, it's assumed that the markup and settings are being set manually.

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.

string: Optionally, specify a skin to override the one defined by the Option Set.

3 calls to royalslider_add()
royalslider.api.php in ./royalslider.api.php
API Documentation for RoyalSlider module.
royalsliderfield_preprocess_royalsliderfield in contrib/royalsliderfield/royalsliderfield.module
Implements hook_preprocess_HOOK().
royalslider_preprocess_royalslider in theme/royalslider.theme.inc
Implements hook_preprocess_HOOK().

File

./royalslider.module, line 640
RoyalSlider module.

Code

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';
  }
}