You are here

public function ContextConditionBreakpoint::getJSConfig in Context Breakpoint 7

File

plugins/context_condition_breakpoint.inc, line 109
context_condition_resolution.inc Provides the context CTools plugin base class.

Class

ContextConditionBreakpoint
@file context_condition_resolution.inc Provides the context CTools plugin base class.

Code

public function getJSConfig() {
  $conf = array(
    'settings' => context_breakpoint_get_settings(),
    'contexts' => array(),
    'is_admin' => $this
      ->isAdminPage(),
  );
  $valid = array(
    'width',
    'device-width',
    'min-width',
    'min-device-width',
    'max-width',
    'max-device-width',
    'height',
    'device-height',
    'min-height',
    'min-device-height',
    'max-height',
    'max-device-height',
    'aspect-ratio',
    'device-aspect-ratio',
    'min-aspect-ratio',
    'min-device-aspect-ratio',
    'max-aspect-ratio',
    'max-device-aspect-ratio',
  );
  foreach ($this
    ->get_contexts() as $context) {
    $values = $this
      ->fetch_from_context($context, 'values');
    $options = $this
      ->fetch_from_context($context, 'options');
    if (!count($values)) {
      break;
    }
    $name = $values[0];
    $points = array();

    // Check if it is a group.
    if (strpos($name, 'group_') === 0) {

      // A group!
      $group_name = substr($name, 6);
      $group = breakpoints_breakpoint_group_load($group_name);
      if (!$group) {
        break;
      }
      $points = $group->breakpoints;
    }
    else {

      // Just one point.
      $points[] = $name;
    }
    $point_conditions = array();
    foreach ($points as $point_name) {
      $breakpoint = breakpoints_breakpoint_load_by_fullkey($point_name);
      if (!$breakpoint) {
        continue;
      }
      $conditions = $this
        ->parseBreakpoint($breakpoint->breakpoint);
      $point = array();
      foreach ($conditions as $cmd => $value) {
        if (in_array($cmd, $valid)) {
          $point[$cmd] = $value;
        }
      }
      if (count($point)) {
        $point_conditions[$point_name] = $point;
      }
    }
    if (count($point_conditions)) {
      $options['breakpoints'] = $point_conditions;
      $conf['contexts'][$context->name] = $options;
    }
  }
  return $conf;
}