You are here

function _colorbox_doheader in Colorbox 6

Same name and namespace in other branches
  1. 7.2 colorbox.module \_colorbox_doheader()
  2. 7 colorbox.module \_colorbox_doheader()

Loads the various js and css files.

1 call to _colorbox_doheader()
colorbox_init in ./colorbox.module
Implementation of hook_init().

File

./colorbox.module, line 162
A light-weight, customizable lightbox plugin for jQuery 1.3

Code

function _colorbox_doheader() {
  static $already_added = FALSE;
  if ($already_added) {
    return;

    // Don't add the JavaScript and CSS multiple times.
  }
  if (!_colorbox_active()) {
    return;

    // Don't add the JavaScript and CSS on specified paths.
  }

  // Insert options and translated strings as javascript settings.
  if (variable_get('colorbox_custom_settings_activate', 0)) {
    $js_settings = array(
      'transition' => variable_get('colorbox_transition_type', 'elastic'),
      'speed' => variable_get('colorbox_transition_speed', 350),
      'opacity' => variable_get('colorbox_opacity', '0.9'),
      'slideshow' => variable_get('colorbox_slideshow', 0) ? TRUE : FALSE,
      'slideshowAuto' => variable_get('colorbox_slideshowauto', 1) ? TRUE : FALSE,
      'slideshowSpeed' => variable_get('colorbox_slideshowspeed', 2500),
      'slideshowStart' => variable_get('colorbox_text_start', 'start slideshow'),
      'slideshowStop' => variable_get('colorbox_text_stop', 'stop slideshow'),
      'current' => variable_get('colorbox_text_current', '{current} of {total}'),
      'previous' => variable_get('colorbox_text_previous', '« Prev'),
      'next' => variable_get('colorbox_text_next', 'Next »'),
      'close' => variable_get('colorbox_text_close', 'Close'),
      'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE,
      'maxWidth' => variable_get('colorbox_maxwidth', '100%'),
      'maxHeight' => variable_get('colorbox_maxheight', '100%'),
    );
  }
  else {
    $js_settings = array(
      'transition' => 'elastic',
      'speed' => 350,
      'opacity' => '0.85',
      'slideshow' => FALSE,
      'slideshowAuto' => FALSE,
      'slideshowSpeed' => 2500,
      'slideshowStart' => '',
      'slideshowStop' => '',
      'current' => t('{current} of {total}'),
      'previous' => t('« Prev'),
      'next' => t('Next »'),
      'close' => t('Close'),
      'overlayClose' => TRUE,
      'maxWidth' => '100%',
      'maxHeight' => '100%',
    );
  }
  $path = drupal_get_path('module', 'colorbox');
  $style = variable_get('colorbox_style', 'default');

  // Give other modules the possibility to override Colorbox settings and style.
  $data =& $js_settings;
  $data['__drupal_alter_by_ref'] = array(
    &$style,
  );
  drupal_alter('colorbox_settings', $data);
  drupal_add_js(array(
    'colorbox' => $js_settings,
  ), 'setting');
  if (module_exists('image') && variable_get('colorbox_auto_image_nodes', 0)) {
    $image_derivative = variable_get('colorbox_image_derivative', 'preview');

    // If the image derivative is set to IMAGE_ORIGINAL check if the
    // user has access before activating Colorbox.
    if (!($image_derivative == IMAGE_ORIGINAL && !user_access('view original images'))) {
      drupal_add_js(array(
        'colorbox' => array(
          'image_derivative' => $image_derivative,
        ),
      ), 'setting');
      drupal_add_js($path . '/js/colorbox_image_module.js');
    }
  }
  if (module_exists('img_assist') && variable_get('colorbox_auto_img_assist_custom', 0)) {
    $img_assist_derivative = variable_get('colorbox_img_assist_derivative', 'preview');

    // If the image derivative is set to IMAGE_ORIGINAL check if the
    // user has access before activating Colorbox.
    if (!($img_assist_derivative == IMAGE_ORIGINAL && !user_access('view original images'))) {
      drupal_add_js(array(
        'colorbox' => array(
          'img_assist_derivative' => $img_assist_derivative,
        ),
      ), 'setting');
      drupal_add_js($path . '/js/colorbox_img_assist_module.js');
    }
  }

  // Add and initialise the Colorbox plugin.
  drupal_add_js(colorbox_get_js());
  drupal_add_js($path . '/js/colorbox.js');

  // Add JS and CSS based on selected style.
  switch ($style) {
    case 'none':
      break;
    case 'default':
      drupal_add_css($path . '/styles/default/colorbox_default_style.css');
      drupal_add_js($path . '/styles/default/colorbox_default_style.js');
      break;
    case 'stockholmsyndrome':
      drupal_add_css($path . '/styles/stockholmsyndrome/colorbox_stockholmsyndrome.css');
      drupal_add_js($path . '/styles/stockholmsyndrome/colorbox_stockholmsyndrome.js');
      break;
    default:
      drupal_add_css($style . '/colorbox.css');
  }
  if (variable_get('colorbox_load', 0)) {
    drupal_add_js($path . '/js/colorbox_load.js');
  }
  if (variable_get('colorbox_inline', 0)) {
    drupal_add_js($path . '/js/colorbox_inline.js');
  }
  if ($GLOBALS['user']->uid == 0 && variable_get('colorbox_login', 0)) {
    drupal_add_js($path . '/js/colorbox_login.js');
  }
  $already_added = TRUE;
}