You are here

function responsive_menus_execute in Responsive Menus 7

Final execution for Responsive Menus. Add any js/css and settings required.

2 calls to responsive_menus_execute()
responsive_menus_context_reaction_general::execute in plugins/context/responsive_menus_context_reaction_general.inc
Execute & make those menus responsive.
responsive_menus_page_build in ./responsive_menus.module
Implements hook_page_build().

File

./responsive_menus.module, line 1213
Responsify menus in Drupal.

Code

function responsive_menus_execute($style = NULL, $js_defaults = array()) {

  // Load our style.
  if (!isset($style)) {
    $ignore_admin = variable_get('responsive_menus_ignore_admin', array(
      1 => 1,
    ));
    if ($ignore_admin[1] && path_is_admin(current_path())) {
      return;
    }
    $style = variable_get('responsive_menus_style', 'responsive_menus_simple');
  }
  $jq_update_ignore = variable_get('responsive_menus_no_jquery_update', array(
    1 => 0,
  ));
  $style_info = responsive_menus_style_load($style, $jq_update_ignore);
  if (!$style_info) {
    return;
  }
  $data =& drupal_static(__FUNCTION__, array());
  if (!isset($data['execute_index'])) {
    $data['execute_index'] = -1;
  }
  $data['execute_index']++;
  $js_settings = array();
  $js_files = array();
  $css_files = array();

  // Load JS files from folder.
  if (!empty($style_info['js_folder'])) {
    $js_files = responsive_menus_glob_files($style_info['js_folder'], 'js');
  }

  // Load CSS files from folder.
  if (!empty($style_info['css_folder'])) {
    $css_files = responsive_menus_glob_files($style_info['css_folder'], 'css');
  }

  // Load individual JS files.
  if (!empty($style_info['js_files'])) {
    $js_files = array_unique(array_merge($js_files, $style_info['js_files']));
  }

  // Load individual CSS files.
  if (!empty($style_info['css_files'])) {
    $css_files = array_unique(array_merge($css_files, $style_info['css_files']));
  }

  // Add JS files.
  if (!empty($js_files)) {
    foreach ($js_files as $js_file) {
      drupal_add_js($js_file);
    }
  }

  // Add CSS files.
  if (!empty($css_files)) {
    foreach ($css_files as $css_file) {
      drupal_add_css($css_file);
    }
  }
  $filtered_settings = array();
  foreach ($style_info['js_settings']($js_defaults) as $setting_index => $setting) {
    if (!is_array($setting)) {
      $filtered_settings[$setting_index] = filter_xss_admin($setting);
    }
    else {
      foreach ($setting as $sub_index => $sub_value) {
        $filtered_settings[$setting_index][$sub_index] = filter_xss_admin($sub_value);
      }
    }
  }
  if (!isset($filtered_settings['selectors'])) {
    $filtered_settings['selectors'] = array();
  }

  // Add JS settings.
  $js_settings[$data['execute_index']] = $filtered_settings;
  $js_settings[$data['execute_index']]['responsive_menus_style'] = $style;
  drupal_alter('responsive_menus_execute', $js_settings);
  drupal_add_js(array(
    'responsive_menus' => $js_settings,
  ), 'setting');
}