You are here

function _popup_classes in Popup 7

Same name and namespace in other branches
  1. 8 includes/popup.util.inc \_popup_classes()
  2. 7.x includes/popup.util.inc \_popup_classes()
  3. 6.x includes/popup.util.inc \_popup_classes()

Generates the correct classes for each of the popup element, title and body.

Parameters

$attributes:

Return value

keyed array

1 call to _popup_classes()
popup_element in includes/popup.api.inc
Renders a popup elements' HTML

File

includes/popup.util.inc, line 124

Code

function _popup_classes($attributes = array()) {

  // Defaults
  _popup_default($attributes['activate'], 'hover');
  _popup_default($attributes['effect'], 'default');
  _popup_default($attributes['origin'], 'bottom-left');
  _popup_default($attributes['expand'], 'bottom-right');
  _popup_default($attributes['width'], variable_get('popup-width', 150));
  $classes = array(
    'element' => array(
      'popup-element',
      'popup-element-noscript',
    ),
    'title' => array(
      'popup-element-title',
    ),
    'body' => array(
      'popup-element-body',
    ),
  );

  // Add style specific class
  if ($attributes['style-class']) {
    $classes['element'][] = 'popup-style-' . $attributes['style-class'];
  }

  // Add element specific classes
  foreach ($classes as $element => $class_array) {
    if ($attributes[$element . '-class']) {
      $classes[$element][] = $attributes[$element . '-class'];
    }
  }

  // Add additional classes if needed
  if (is_array($attributes['classes'])) {
    foreach ($attributes['classes'] as $element => $add_classes) {
      $classes[$element] = array_merge($attributes['classes'][$element], $classes[$element]);
    }
  }

  // Define which attribute classes apply to which sub-element
  $meta = array(
    'activate' => array(
      'element',
    ),
    'ajax' => array(
      'body',
    ),
    'class' => array(
      'title',
      'element',
      'body',
    ),
    'effect' => array(
      'element',
    ),
    'expand' => array(
      'element',
      'body',
    ),
    'opacity' => array(
      'body',
    ),
    'origin' => array(
      'element',
      'body',
    ),
    'width' => array(
      'body',
    ),
  );
  foreach ($meta as $attribute => $apply_to) {
    if ($attributes[$attribute]) {
      foreach ($apply_to as $element) {
        $classes[$element][] = $attributes[$attribute] == 1 ? $attribute : $attribute . '-' . $attributes[$attribute];
      }
    }
  }
  foreach ($classes as $element => $element_classes) {
    $classes[$element] = implode(' ', $element_classes);
  }
  return $classes;
}