You are here

function theme_layout_responsive_admin in Layout 7

Draw the responsive layout admin interface.

@todo Embeddig the grid CSS inline is evil. Fix it.

File

plugins/layouts/responsive.inc, line 281

Code

function theme_layout_responsive_admin($vars) {
  $css_id = $vars['css_id'];
  $content = $vars['content'];
  $settings = $vars['settings'];
  $display = $vars['display'];
  $layout = $vars['layout'];
  $handler = $vars['renderer'];

  // We never draw stored responsive layouts in admin mode; they must be edited
  // from the stored layout UI at that point. This can happen if the layout is
  // displayed in an admin context, but not to administer the layout per say but
  // to administer other thigns on top of the layout, such as rearranging panes
  // when switching layouts or when adding new panes.
  if (!empty($layout['layout'])) {
    return theme_layout_responsive(array(
      'css_id' => $css_id,
      'content' => $content,
      'settings' => $settings,
      'display' => $display,
      'layout' => $layout,
      'renderer' => $handler,
    ));
  }
  layout_responsive_merge_default_settings($settings, $layout);

  // Add required libraries.
  drupal_add_library('system', 'ui.dialog');

  // JSON2 is required for stringifying JavaScript data structures in older browsers.
  $name = 'json2';
  if (!libraries_detect($name)) {
    watchdog('responsive', 'The JSON-js library is recommended for this module to function properly. Some older browsers do not provide the JSON function natively. Please visit !url to obtain this library.', array(
      '!url' => l('JSON-js (Github)', 'https://github.com/douglascrockford/JSON-js', array(
        'absolute' => TRUE,
        'external' => TRUE,
      )),
    ), WATCHDOG_NOTICE);
  }
  else {
    libraries_load($name);
  }

  // Add the ResponsiveLayoutDesigner application.
  layout_responsive_load_rld_application($layout['path']);

  // Add integration code for Drupal.
  drupal_add_js($layout['path'] . '/responsive-admin.js');

  // Add data about the layout and global list of regions.
  $default_regions = layout_region_load_all();
  $default_breakpoints = layout_breakpoint_load_all();
  $default_grids = gridbuilder_load_all();
  drupal_add_js(array(
    'responsiveLayout' => array(
      'settings' => $settings,
      'defaultRegions' => $default_regions,
      'defaultBreakpoints' => $default_breakpoints,
      'defaultGrids' => $default_grids,
    ),
  ), 'setting');
  drupal_add_library('system', 'ui.sortable');

  // Embed the grid css inline for now. Yeah, I know this is evil.
  // It is just a prototype for now, ok? I know it is evil. Yes.
  $grid_css = layout_breakpoint_get_css(FALSE);
  drupal_add_css($grid_css, array(
    'type' => 'inline',
  ));

  // This is filled in on the client side.
  return '<div id="responsive-layout-designer"></div>';
}