You are here

responsive_menus.module in Responsive Menus 7

Same filename and directory in other branches
  1. 8 responsive_menus.module

Responsify menus in Drupal.

File

responsive_menus.module
View source
<?php

/**
 * @file
 * Responsify menus in Drupal.
 */

/**
 * Implements hook_menu().
 */
function responsive_menus_menu() {
  $items = array();
  $items['admin/config/user-interface/responsive_menus'] = array(
    'title' => 'Responsive Menus',
    'description' => 'Settings for Responsive Menus module',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'responsive_menus_admin_form',
    ),
    'access arguments' => array(
      'administer responsive menus',
    ),
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function responsive_menus_permission() {
  return array(
    'administer responsive menus' => array(
      'title' => t('Administer Responsive Menus'),
      'description' => t('Configure settings for responsive menus module.'),
      'restrict access' => TRUE,
    ),
  );
}

/**
 * Implements hook_help().
 */
function responsive_menus_help($path, $arg) {
  switch ($path) {

    // On the help overview page.
    case 'admin/help#responsive_menus':
      return '<p>' . t('Responsify your menus! Using any jQuery compatible selector, make elements mobile friendly. Technically you could use this on more than menus... The <a href="@admin">administration page</a> provides settings to control which menus to control, what screen size to react to, and a few other options.', array(
        '@admin' => url('admin/config/user-interface/responsive_menus'),
      )) . '</p>';

    // On the admin settings page.
    case 'admin/config/user-interface/responsive_menus':
      return '<p>' . t('This page provides configuration options for responsive menus. You may configure any amount of menus to respond to any screen size by simply adding a jQuery compatible selector to the list below. There is also an option to ignore admin pages where you might not want responsive menus.') . '</p>';
  }
}

/**
 * Implements hook_ctools_plugin_api().
 */
function responsive_menus_ctools_plugin_api($module, $api) {
  if ($module == 'context' && $api == 'plugins') {
    return array(
      'version' => 3,
    );
  }
}

/**
 * Implements hook_context_registry().
 */
function responsive_menus_context_registry() {
  $registry = array();
  $registry['reactions'] = array(
    'responsive_menus_general' => array(
      'title' => t('Responsive Menus'),
      'description' => t('Add & configure a Responsive Menus module reaction.'),
      'plugin' => 'responsive_menus_context_reaction_general',
    ),
  );
  return $registry;
}

/**
 * Implements hook_context_plugins().
 */
function responsive_menus_context_plugins() {
  $plugins = array();
  $plugins['responsive_menus_context_reaction_general'] = array(
    'handler' => array(
      'path' => drupal_get_path('module', 'responsive_menus') . '/plugins/context',
      'file' => 'responsive_menus_context_reaction_general.inc',
      'class' => 'responsive_menus_context_reaction_general',
      'parent' => 'context_reaction',
    ),
  );
  return $plugins;
}

/**
 * Implements hook_libraries_info().
 * @note : Libraries 2.x
 */
function responsive_menus_libraries_info() {
  $libraries['ResponsiveMultiLevelMenu'] = array(
    'name' => 'ResponsiveMultiLevelMenu (codrops)',
    'vendor url' => 'http://tympanus.net/Development/ResponsiveMultiLevelMenu/',
    'download url' => 'http://tympanus.net/Development/ResponsiveMultiLevelMenu/ResponsiveMultiLevelMenu.zip',
    'version arguments' => array(
      'file' => 'js/jquery.dlmenu.js',
      'pattern' => '/v([\\d\\.]+)/',
      'lines' => 3,
      'columns' => 40,
    ),
    'files' => array(
      'js' => array(
        'js/modernizr.custom.js',
        'js/jquery.dlmenu.js',
      ),
      'css' => array(
        'css/component.css',
      ),
    ),
    'integration files' => array(
      'responsive_menus' => array(
        'js' => array(
          'styles/ResponsiveMultiLevelMenu/js/responsive_menus_codrops_responsive_multi.js',
        ),
      ),
    ),
  );
  $libraries['sidr'] = array(
    'name' => 'Sidr',
    'vendor url' => 'http://www.berriart.com/sidr',
    'download url' => 'https://github.com/artberri/sidr-package/archive/1.2.1.zip',
    'version arguments' => array(
      'file' => 'jquery.sidr.min.js',
      'pattern' => '/v([\\d\\.]+)/',
      'lines' => 1,
      'columns' => 40,
    ),
    'files' => array(
      'js' => array(
        'jquery.sidr.min.js',
      ),
      'css' => array(
        'stylesheets/jquery.sidr.dark.css',
      ),
    ),
    'integration files' => array(
      'responsive_menus' => array(
        'js' => array(
          'styles/sidr/js/responsive_menus_sidr.js',
        ),
      ),
    ),
  );
  $sidr_theme = variable_get('responsive_menus_sidr_menu_theme', 'dark');
  if ($sidr_theme == 'light') {
    $libraries['sidr']['files']['css'] = array(
      'stylesheets/jquery.sidr.light.css',
    );
  }
  elseif ($sidr_theme == 'custom') {
    unset($libraries['sidr']['files']['css']);
  }
  $libraries['GoogleNexusWebsiteMenu'] = array(
    'name' => 'Google Nexus (codrops)',
    'vendor url' => 'http://tympanus.net/codrops/2013/07/30/google-nexus-website-menu/',
    'download url' => 'http://tympanus.net/Tutorials/GoogleNexusWebsiteMenu/GoogleNexusWebsiteMenu.zip',
    'version arguments' => array(
      'file' => 'js/gnmenu.js',
      'pattern' => '/v([\\d\\.]+)/',
      'lines' => 2,
      'columns' => 40,
    ),
    'files' => array(
      'js' => array(
        'js/gnmenu.js',
        'js/classie.js',
      ),
      'css' => array(
        'css/component.css',
      ),
    ),
    'integration files' => array(
      'responsive_menus' => array(
        'js' => array(
          'styles/google_nexus/js/responsive_menus_google_nexus.js',
        ),
        'css' => array(
          'styles/google_nexus/css/responsive_menus_google_nexus.css',
        ),
      ),
    ),
  );
  return $libraries;
}

/**
 * Admin settings form for which menus to responsify.
 */
function responsive_menus_admin_form($form, &$form_state) {

  // Gather enabled styles.
  $styles = responsive_menus_styles();
  foreach ($styles as $style => $values) {
    $style_options[$style] = $values['name'];
  }

  // Get style settings form elements from ajax or the currently enabled style.
  if (!empty($form_state['values']['responsive_menus_style'])) {
    $current_style = $form_state['values']['responsive_menus_style'];
  }
  else {
    $current_style = variable_get('responsive_menus_style', 'responsive_menus_simple');
  }

  // Reminders about jQuery requirements if applicable.
  $form['responsive_menus_no_jquery_update'] = array(
    '#type' => 'checkboxes',
    '#description' => t("If the style you want requires newer jQuery version and you don't want to use jquery_update module."),
    '#options' => array(
      1 => t('I will provide my own jQuery library.'),
    ),
    '#default_value' => variable_get('responsive_menus_no_jquery_update', array(
      1 => 0,
    )),
  );

  // Ignore admin pages option.
  $form['responsive_menus_ignore_admin'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
      1 => t('Ignore admin pages?'),
    ),
    '#default_value' => variable_get('responsive_menus_ignore_admin', array(
      1 => 1,
    )),
  );
  $jq_update_ignore = $form['responsive_menus_no_jquery_update']['#default_value'];
  $style_info = responsive_menus_style_load($current_style, $jq_update_ignore);
  $form['responsive_menus_style'] = array(
    '#type' => 'select',
    '#title' => t('Responsive menu style'),
    '#options' => $style_options,
    '#default_value' => $current_style,
    '#ajax' => array(
      'callback' => 'responsive_menus_style_settings_form',
      'wrapper' => 'rm-style-options',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );
  $form['responsive_menus_style_settings'] = array(
    '#title' => t('Style settings'),
    '#description' => t('Settings for chosen menu style.'),
    '#prefix' => '<div id="rm-style-options">',
    '#suffix' => '</div>',
    '#type' => 'fieldset',
    '#tree' => TRUE,
  );

  // Which selector to use info.
  if (!empty($style_info['selector'])) {
    $form['responsive_menus_style_settings']['selector_info'] = array(
      '#type' => 'item',
      '#title' => t('Selector(s) to use for this style:'),
      '#markup' => '<div class="messages status">' . $style_info['selector'] . '</div>',
    );
  }

  // Build additional style settings from style plugins.
  if (!empty($styles[$current_style]['form']) && function_exists($styles[$current_style]['form'])) {
    $styles_function = $styles[$current_style]['form'];
    foreach ($styles_function() as $name => $element) {
      $form['responsive_menus_style_settings'][$name] = $element;
    }
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  if (!empty($_POST) && form_get_errors()) {
    drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
  }
  $form['#submit'][] = 'responsive_menus_admin_form_submit';
  return $form;
}

/**
 * Ajax callback for switching styles.
 */
function responsive_menus_style_settings_form($form, $form_state) {
  return $form['responsive_menus_style_settings'];
}

/**
 * Submit handler for responsive_menus_admin_form.
 */
function responsive_menus_admin_form_submit($form, &$form_state) {

  // Exclude unnecessary elements.
  form_state_values_clean($form_state);

  // Which field types to run filter_xss() on.
  $filter_types = array(
    'textfield',
    'textarea',
  );
  foreach ($form_state['values'] as $key => $value) {
    if (is_array($value) && isset($form_state['values']['array_filter'])) {
      $value = array_keys(array_filter($value));
    }
    if ($key == 'responsive_menus_style_settings') {
      foreach ($value as $style_key => $style_value) {

        // If the field is a type we should filter.
        if (in_array($form['responsive_menus_style_settings'][$style_key]['#type'], $filter_types, TRUE)) {
          variable_set($style_key, filter_xss($style_value));
        }
        else {
          variable_set($style_key, $style_value);
        }
      }
    }
    else {
      variable_set($key, $value);
    }
  }

  // Clear libraries cache if Sidr style in use to allow theme to be updated.
  if ($form_state['values']['responsive_menus_style'] == 'sidr') {
    cache_clear_all('*', 'cache_libraries', TRUE);
  }
  drupal_set_message(t('The configuration options have been saved.'));
}

/**
 * Gather available styles for Responsive Menus.
 *
 * @return array
 *   Array of available styles.
 */
function responsive_menus_styles() {
  $data =& drupal_static(__FUNCTION__, array());
  if (!isset($data['styles'])) {
    $data['styles'] = module_invoke_all('responsive_menus_style_info');
    drupal_alter('responsive_menus_styles', $data['styles']);
  }
  return $data['styles'];
}

/**
 * Load a single style.
 *
 * @param string $style
 *   Style id to be loaded.
 */
function responsive_menus_style_load($style, $jq_update_ignore) {
  $styles = responsive_menus_styles();
  $data =& drupal_static(__FUNCTION__, array());
  if (!isset($data[$style]) && !empty($styles[$style])) {
    $style_info = $styles[$style];

    // @todo module_load_include() the .inc file for the style being loaded.
    // Check for this style's requirements.
    if (!empty($style_info['jquery_version'])) {
      if (!$jq_update_ignore[1]) {
        if (!module_exists('jquery_update')) {

          // jQuery Update not installed.
          drupal_set_message(t('@style style requires !link set to version !version or higher.  Please enable jquery_update.', array(
            '@style' => $style_info['name'],
            '!link' => l(t('jQuery Update'), 'http://drupal.org/project/jquery_update'),
            '!version' => $style_info['jquery_version'],
          )), 'warning');
          $error = TRUE;
        }
        elseif (version_compare(variable_get('jquery_update_jquery_version', '1.5'), $style_info['jquery_version'], '<')) {

          // jQuery Update version not high enough.
          drupal_set_message(t('@style style requires !link set to version !version or higher.', array(
            '@style' => $style_info['name'],
            '!version' => $style_info['jquery_version'],
            '!link' => l(t('jQuery Update'), 'admin/config/development/jquery_update', array(
              'query' => array(
                'destination' => 'admin/config/user-interface/responsive_menus',
              ),
            )),
          )), 'warning');
          $error = TRUE;
        }
      }
      else {
        drupal_set_message(t('@style style requires !link library version !version or higher, but you have opted to provide your own library.  Please ensure you have the proper version of jQuery included.  (note: this is not an error)', array(
          '@style' => $style_info['name'],
          '!link' => l(t('jQuery'), 'http://jquery.com'),
          '!version' => $style_info['jquery_version'],
        )), 'warning');
      }
    }

    // For integration with Libraries.
    if (isset($style_info['use_libraries'])) {

      // Try libraries module.
      if (module_exists('libraries')) {
        if ($library = libraries_load($style_info['library'])) {
          if (!empty($library['error']) || empty($library['loaded'])) {
            drupal_set_message(t('!message !link and extract to your libraries directory as "@library_name". Example: sites/all/libraries/@library_name.  If you are getting "version detection" errors, check file permissions on the library.', array(
              '!message' => $library['error message'],
              '@library_name' => $style_info['library'],
              '!link' => l(t('Download it'), $library['download url']),
            )), 'error');
            $error = TRUE;
          }
        }
      }
      else {

        // Libraries module not installed.
        drupal_set_message(t('@style style requires !link module enabled.', array(
          '@style' => $style_info['name'],
          '!link' => l(t('Libraries 2.x'), 'http://drupal.org/project/libraries'),
        )), 'warning');
        $error = TRUE;
      }
    }

    // Check for errors and load into $data if there are none.
    if (!isset($error)) {
      $data[$style] = $style_info;
      return $data[$style];
    }
    else {

      // Something was wrong loading this style.
      drupal_set_message(t('Responsive Menus found a problem.  Please check the errors.'), 'error');
      return FALSE;
    }
  }
  else {

    // This style is already loaded.
    return $data[$style];
  }
  return FALSE;
}

/**
 * Implements hook_responsive_menus_style_info().
 */
function responsive_menus_responsive_menus_style_info() {
  $path = drupal_get_path('module', 'responsive_menus') . '/styles';
  $styles = array(
    'responsive_menus_simple' => array(
      'name' => t('Simple expanding'),
      'form' => 'responsive_menus_simple_style_settings',
      'js_files' => array(
        $path . '/responsive_menus_simple/js/responsive_menus_simple.js',
      ),
      'css_files' => array(
        $path . '/responsive_menus_simple/css/responsive_menus_simple.css',
      ),
      'js_settings' => 'responsive_menus_simple_style_js_settings',
      'file' => $path . '/responsive_menus_simple/responsive_menus_simple.inc',
      'selector' => t('Anything.  Example: Given <code>@code</code> you could use !use', array(
        '@ul' => '<ul>',
        '@code' => '<div id="parent-div"> <ul class="menu"> </ul> </div>',
        '!use' => '<strong>#parent-div or .menu</strong>',
      )),
    ),
    'mean_menu' => array(
      'name' => t('Mean Menu'),
      'form' => 'responsive_menus_mean_menu_style_settings',
      'js_files' => array(
        $path . '/meanMenu/jquery.meanmenu.min.js',
        $path . '/meanMenu/responsive_menus_mean_menu.js',
      ),
      'css_files' => array(
        $path . '/meanMenu/meanmenu.min.css',
      ),
      'js_settings' => 'responsive_menus_mean_menu_style_js_settings',
      'jquery_version' => 1.7,
      'file' => $path . '/meanMenu/meanMenu.inc',
      'selector' => t('Parent of the @ul.  Example: Given <code>@code</code> you would use !use', array(
        '@ul' => '<ul>',
        '@code' => '<div id="parent-div"> <ul class="menu"> </ul> </div>',
        '!use' => '<strong>#parent-div</strong>',
      )),
    ),
    'codrops_responsive_multi' => array(
      'name' => t('ResponsiveMultiLevelMenu (codrops)'),
      'form' => 'responsive_menus_codrops_responsive_multi_style_settings',
      'js_settings' => 'responsive_menus_codrops_responsive_multi_style_js_settings',
      'use_libraries' => TRUE,
      'library' => 'ResponsiveMultiLevelMenu',
      'jquery_version' => 1.7,
      'file' => $path . '/ResponsiveMultiLevelMenu/ResponsiveMultiLevelMenu.inc',
      'selector' => t('Parent of the @ul.  Example: Given <code>@code</code> you would use !use', array(
        '@ul' => '<ul>',
        '@code' => '<div id="parent-div"> <ul class="menu"> </ul> </div>',
        '!use' => '<strong>#parent-div</strong>',
      )),
    ),
    'sidr' => array(
      'name' => t('Sidr'),
      'form' => 'responsive_menus_sidr_style_settings',
      'js_settings' => 'responsive_menus_sidr_style_js_settings',
      'use_libraries' => TRUE,
      'library' => 'sidr',
      'file' => $path . '/sidr/sidr.inc',
      'selector' => t('Anything (parent of ul preferred).  Example: Given <code>@code</code> you could use !use', array(
        '@ul' => '<ul>',
        '@code' => '<div id="parent-div"> <ul class="menu"> </ul> </div>',
        '!use' => '<strong>#parent-div or .menu</strong>',
      )),
    ),
    'google_nexus' => array(
      'name' => t('Google Nexus (codrops)'),
      'form' => 'responsive_menus_google_nexus_style_settings',
      'js_settings' => 'responsive_menus_google_nexus_style_js_settings',
      'use_libraries' => TRUE,
      'library' => 'GoogleNexusWebsiteMenu',
      'file' => $path . '/google_nexus/google_nexus.inc',
      'selector' => t('The @ul.  Example: Given <code>@code</code> you would use !use', array(
        '@ul' => '<ul>',
        '@code' => '<div id="parent-div"> <ul class="menu"> </ul> </div>',
        '!use' => '<strong>.menu</strong>',
      )),
    ),
    'mlpm' => array(
      'name' => t('Multi Level Push Menu'),
      'form' => 'responsive_menus_mlpm_style_settings',
      'js_settings' => 'responsive_menus_mlpm_style_js_settings',
      'css_files' => _responsive_menus_mlpm_get_css(),
      'js_files' => array(
        '//oss.maxcdn.com/libs/modernizr/2.6.2/modernizr.min.js',
        $path . '/mlpm/js/jquery.multilevelpushmenu.min.js',
        $path . '/mlpm/js/mlpm.js',
      ),
      'jquery_version' => 1.1,
      'file' => $path . '/mlpm/mlpm.inc',
      'selector' => t('Parent of the @ul.  Example: Given <code>@code</code> you would use !use', array(
        '@ul' => '<ul>',
        '@code' => '<div id="parent-div"> <ul class="menu"> </ul> </div>',
        '!use' => '<strong>#parent-div</strong>',
      )),
    ),
  );
  return $styles;
}

/**
 * Form callback from hook_responsive_menus_style_info().
 *
 * @return array
 *   Drupal FAPI formatted array.
 */
function responsive_menus_simple_style_settings() {
  $form['responsive_menus_simple_absolute'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
      1 => t('Use absolute positioning?'),
    ),
    '#default_value' => variable_get('responsive_menus_simple_absolute', array(
      1 => 1,
    )),
    '#description' => t('Using absolute, the menu will open over the page rather than pushing it down.'),
  );
  $form['responsive_menus_disable_mouse_events'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
      1 => t('Disable other mouse events?'),
    ),
    '#default_value' => variable_get('responsive_menus_disable_mouse_events', array(
      1 => 0,
    )),
    '#description' => t('Disable things like drop-down menus on hover.'),
  );
  $form['responsive_menus_remove_attributes'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
      1 => t('Remove other classes & IDs when responded?'),
    ),
    '#default_value' => variable_get('responsive_menus_remove_attributes', array(
      1 => 1,
    )),
    '#description' => t('Helps to ensure styling of menu.'),
  );
  $form['responsive_menus_css_selectors'] = array(
    '#type' => 'textarea',
    '#title' => t('Selectors for which menus to responsify'),
    '#default_value' => variable_get('responsive_menus_css_selectors', '#main-menu'),
    '#description' => t('Enter CSS/jQuery selectors of menus to responsify.  Comma separated or 1 per line'),
  );
  $form['responsive_menus_simple_text'] = array(
    '#type' => 'textarea',
    '#title' => t('Text or HTML for the menu toggle button'),
    '#default_value' => variable_get('responsive_menus_simple_text', '☰ Menu'),
  );
  $form['responsive_menus_media_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Screen width to respond to'),
    '#size' => 5,
    '#default_value' => variable_get('responsive_menus_media_size', 768),
    '#description' => t('Width when we swap out responsive menu e.g. 768'),
  );
  $form['responsive_menus_media_unit'] = array(
    '#type' => 'select',
    '#title' => t('Width unit'),
    '#default_value' => variable_get('responsive_menus_media_unit', 'px'),
    '#options' => array(
      'px' => 'px',
      'em' => 'em',
    ),
    '#description' => t('Unit for the width above'),
  );
  return $form;
}

/**
 * JS callback from hook_responsive_menus_style_info().
 */
function responsive_menus_simple_style_js_settings($js_defaults = array()) {
  $js_settings = array(
    'toggler_text' => responsive_menus_var_get('responsive_menus_simple_text', '☰ Menu', $js_defaults),
    'selectors' => responsive_menus_explode_list('responsive_menus_css_selectors', '#main-menu', $js_defaults),
    'media_size' => responsive_menus_var_get('responsive_menus_media_size', 768, $js_defaults),
    'media_unit' => responsive_menus_var_get('responsive_menus_media_unit', 'px', $js_defaults),
  );
  $absolute = responsive_menus_var_get('responsive_menus_simple_absolute', array(
    1 => 1,
  ), $js_defaults);
  $disable_mouse = responsive_menus_var_get('responsive_menus_disable_mouse_events', array(
    1 => 0,
  ), $js_defaults);
  $remove_attributes = responsive_menus_var_get('responsive_menus_remove_attributes', array(
    1 => 1,
  ), $js_defaults);
  if ($absolute[1]) {
    $js_settings['absolute'] = TRUE;
  }
  if ($disable_mouse[1]) {
    $js_settings['disable_mouse_events'] = TRUE;
  }
  if ($remove_attributes[1]) {
    $js_settings['remove_attributes'] = TRUE;
  }
  return $js_settings;
}

/**
 * Form callback from hook_responsive_menus_style_info().
 *
 * @return array
 *   Drupal FAPI formatted array.
 */
function responsive_menus_mean_menu_style_settings() {
  $form['responsive_menus_mean_menu_css_selectors'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS selectors for which menu to responsify'),
    '#default_value' => variable_get('responsive_menus_mean_menu_css_selectors', '#main-menu'),
    '#description' => t('Enter CSS/jQuery selector of menus to responsify.'),
  );
  $form['responsive_menus_mean_menu_container'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS selector for where to attach the menu on the page'),
    '#default_value' => variable_get('responsive_menus_mean_menu_container', 'body'),
    '#description' => t('Enter CSS/jQuery selector of where MeanMenu gets attached.'),
  );
  $form['responsive_menus_mean_menu_trigger_txt'] = array(
    '#type' => 'textarea',
    '#title' => t('Text or HTML for trigger button'),
    '#default_value' => variable_get('responsive_menus_mean_menu_trigger_txt', '<span /><span /><span />'),
    '#description' => t('Default of 3 spans will show the triple bars (!bars).', array(
      '!bars' => '☰',
    )),
  );
  $form['responsive_menus_mean_menu_close_txt'] = array(
    '#type' => 'textarea',
    '#title' => t('Text or HTML for close button'),
    '#default_value' => variable_get('responsive_menus_mean_menu_close_txt', 'X'),
  );
  $form['responsive_menus_mean_menu_close_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Size of close button'),
    '#size' => 5,
    '#default_value' => variable_get('responsive_menus_mean_menu_close_size', '18px'),
    '#description' => t('Size in px, em, %'),
  );
  $form['responsive_menus_mean_menu_position'] = array(
    '#type' => 'select',
    '#title' => t('Position of the open/close buttons'),
    '#options' => array(
      'right' => t('right'),
      'left' => t('left'),
      'center' => t('center'),
    ),
    '#default_value' => variable_get('responsive_menus_mean_menu_position', 'right'),
  );
  $form['responsive_menus_mean_menu_media_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Screen width to respond to'),
    '#size' => 5,
    '#default_value' => variable_get('responsive_menus_mean_menu_media_size', 480),
    '#description' => t('Width in pixels when we swap out responsive menu e.g. 768'),
  );
  $form['responsive_menus_mean_menu_show_children'] = array(
    '#type' => 'select',
    '#title' => t('Allow multi-level menus'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => variable_get('responsive_menus_mean_menu_show_children', 1),
  );
  $form['responsive_menus_mean_menu_expand_children'] = array(
    '#type' => 'select',
    '#title' => t('Ability to expand & collapse children'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => variable_get('responsive_menus_mean_menu_expand_children', 1),
  );
  $form['responsive_menus_mean_menu_expand_txt'] = array(
    '#type' => 'textfield',
    '#title' => t('Text for the expand children button'),
    '#size' => 5,
    '#default_value' => variable_get('responsive_menus_mean_menu_expand_txt', '+'),
  );
  $form['responsive_menus_mean_menu_contract_txt'] = array(
    '#type' => 'textfield',
    '#title' => t('Text for the collapse children button'),
    '#size' => 5,
    '#default_value' => variable_get('responsive_menus_mean_menu_contract_txt', '-'),
  );
  $form['responsive_menus_mean_menu_remove_attrs'] = array(
    '#type' => 'select',
    '#title' => t('Temporarily remove other classes & IDs (Recommended)'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => variable_get('responsive_menus_mean_menu_remove_attrs', 1),
    '#description' => t('This will help ensure the style of Mean Menus.'),
  );
  return $form;
}

/**
 * JS callback from hook_responsive_menus_style_info().
 */
function responsive_menus_mean_menu_style_js_settings($js_defaults = array()) {
  $js_settings = array(
    'selectors' => responsive_menus_var_get('responsive_menus_mean_menu_css_selectors', '#main-menu', $js_defaults),
    'container' => responsive_menus_var_get('responsive_menus_mean_menu_container', 'body', $js_defaults),
    'trigger_txt' => responsive_menus_var_get('responsive_menus_mean_menu_trigger_txt', '<span /><span /><span />', $js_defaults),
    'close_txt' => responsive_menus_var_get('responsive_menus_mean_menu_close_txt', 'X', $js_defaults),
    'close_size' => responsive_menus_var_get('responsive_menus_mean_menu_close_size', '18px', $js_defaults),
    'position' => responsive_menus_var_get('responsive_menus_mean_menu_position', 'right', $js_defaults),
    'media_size' => responsive_menus_var_get('responsive_menus_mean_menu_media_size', 480, $js_defaults),
    'show_children' => responsive_menus_var_get('responsive_menus_mean_menu_show_children', 1, $js_defaults),
    'expand_children' => responsive_menus_var_get('responsive_menus_mean_menu_expand_children', 1, $js_defaults),
    'expand_txt' => responsive_menus_var_get('responsive_menus_mean_menu_expand_txt', '+', $js_defaults),
    'contract_txt' => responsive_menus_var_get('responsive_menus_mean_menu_contract_txt', '-', $js_defaults),
    'remove_attrs' => responsive_menus_var_get('responsive_menus_mean_menu_remove_attrs', 1, $js_defaults),
  );
  return $js_settings;
}

/**
 * Form callback from hook_responsive_menus_style_info().
 *
 * @return array
 *   Drupal FAPI formatted array.
 */
function responsive_menus_codrops_responsive_multi_style_settings() {
  $form['responsive_menus_codrops_responsive_multi_css_selectors'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS selectors for which menu to responsify'),
    '#default_value' => variable_get('responsive_menus_codrops_responsive_multi_css_selectors', '#main-menu'),
    '#description' => t('Enter CSS/jQuery selector of menus to responsify.'),
  );
  $form['responsive_menus_codrops_responsive_multi_media_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Screen width to respond to'),
    '#size' => 5,
    '#default_value' => variable_get('responsive_menus_codrops_responsive_multi_media_size', 768),
    '#description' => t('Width in pixels when we swap out responsive menu e.g. 768'),
  );
  $form['responsive_menus_codrops_responsive_multi_ani_in'] = array(
    '#type' => 'select',
    '#title' => t('In-animation'),
    '#options' => array(
      'dl-animate-in-1' => t('One'),
      'dl-animate-in-2' => t('Two'),
      'dl-animate-in-3' => t('Three'),
      'dl-animate-in-4' => t('Four'),
      'dl-animate-in-5' => t('Five'),
    ),
    '#default_value' => variable_get('responsive_menus_codrops_responsive_multi_ani_in', 'dl-animate-in-1'),
  );
  $form['responsive_menus_codrops_responsive_multi_ani_out'] = array(
    '#type' => 'select',
    '#title' => t('Out-animation'),
    '#options' => array(
      'dl-animate-out-1' => t('One'),
      'dl-animate-out-2' => t('Two'),
      'dl-animate-out-3' => t('Three'),
      'dl-animate-out-4' => t('Four'),
      'dl-animate-out-5' => t('Five'),
    ),
    '#default_value' => variable_get('responsive_menus_codrops_responsive_multi_ani_out', 'dl-animate-out-1'),
  );
  return $form;
}

/**
 * JS callback from hook_responsive_menus_style_info().
 */
function responsive_menus_codrops_responsive_multi_style_js_settings($js_defaults = array()) {
  $js_settings = array(
    'selectors' => responsive_menus_var_get('responsive_menus_codrops_responsive_multi_css_selectors', '#main-menu', $js_defaults),
    'media_size' => responsive_menus_var_get('responsive_menus_codrops_responsive_multi_media_size', 768, $js_defaults),
    'animation_in' => responsive_menus_var_get('responsive_menus_codrops_responsive_multi_ani_in', 'dl-animate-in-1', $js_defaults),
    'animation_out' => responsive_menus_var_get('responsive_menus_codrops_responsive_multi_ani_out', 'dl-animate-out-1', $js_defaults),
  );
  return $js_settings;
}

/**
 * Form callback from hook_responsive_menus_style_info().
 *
 * @return array
 *   Drupal FAPI formatted array.
 */
function responsive_menus_sidr_style_settings() {
  $form['responsive_menus_sidr_css_selectors'] = array(
    '#type' => 'textarea',
    '#title' => t('CSS selectors for which menu to responsify'),
    '#default_value' => variable_get('responsive_menus_sidr_css_selectors', '#main-menu'),
    '#description' => t('Enter CSS/jQuery selectors of menus to responsify.  Comma separated or 1 per line'),
  );
  $form['responsive_menus_sidr_trigger_txt'] = array(
    '#type' => 'textarea',
    '#title' => t('Text or HTML for trigger button'),
    '#default_value' => variable_get('responsive_menus_sidr_trigger_txt', t('Menu')),
  );
  $form['responsive_menus_sidr_menu_side'] = array(
    '#type' => 'select',
    '#title' => t('Position of the menu (left/right)'),
    '#options' => array(
      'left' => t('Left'),
      'right' => t('Right'),
    ),
    '#default_value' => variable_get('responsive_menus_sidr_menu_side', array(
      'left' => 'Left',
    )),
  );
  $form['responsive_menus_sidr_menu_theme'] = array(
    '#type' => 'select',
    '#title' => t('Theme'),
    '#options' => array(
      'dark' => t('Dark'),
      'light' => t('Light'),
      'custom' => t('Custom'),
    ),
    '#default_value' => variable_get('responsive_menus_sidr_menu_theme', 'dark'),
    '#description' => t('Select which <a href="@theme">theme</a> will be used to style the menu. If "Custom" is selected, no CSS will be added; you will need to add your own styles.', array(
      '@theme' => 'http://www.berriart.com/sidr/#themes',
    )),
  );
  $form['responsive_menus_sidr_animation_speed'] = array(
    '#type' => 'textfield',
    '#title' => t('Sidr animation speed'),
    '#size' => 5,
    '#default_value' => variable_get('responsive_menus_sidr_animation_speed', 200),
    '#description' => t('Speed (in milliseconds) of menu open/close. 1000 = 1 second.'),
  );
  $form['responsive_menus_sidr_media_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Screen width to respond to'),
    '#size' => 5,
    '#default_value' => variable_get('responsive_menus_sidr_media_size', 768),
    '#description' => t('Width in pixels when we swap out responsive menu e.g. 768'),
  );
  $form['responsive_menus_sidr_displace'] = array(
    '#type' => 'select',
    '#title' => t('Displace body content?'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => variable_get('responsive_menus_sidr_displace', 1),
    '#description' => t('This setting controls whether the page is pushed when menu is opened.'),
  );
  $form['responsive_menus_sidr_renaming'] = array(
    '#type' => 'select',
    '#title' => t('Rename classes'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => variable_get('responsive_menus_sidr_renaming', 1),
    '#description' => t('Controls whether Sidr will rename classes within the the selectors specified.'),
  );
  $form['responsive_menus_sidr_on_open'] = array(
    '#type' => 'textarea',
    '#title' => t('onOpen callback (function)'),
    '#description' => t("Enter Javacript to be called when the menu is opened.  Example: alert('Great job'); See !documentation for examples.", array(
      '!documentation' => l(t('Sidr documentation'), 'http://www.berriart.com/sidr/#documentation'),
    )),
    '#default_value' => variable_get('responsive_menus_sidr_on_open', ''),
  );
  $form['responsive_menus_sidr_on_close'] = array(
    '#type' => 'textarea',
    '#title' => t('onClose callback (function)'),
    '#description' => t("Enter Javacript to be called when the menu is closed.  Example: alert('Great job'); See !documentation for examples.", array(
      '!documentation' => l(t('Sidr documentation'), 'http://www.berriart.com/sidr/#documentation'),
    )),
    '#default_value' => variable_get('responsive_menus_sidr_on_close', ''),
  );

  /*
   * Other sidr attributes not implemented:

  renaming (Boolean) Default: true
  When filling the sidr with existing content, choose to rename or not the classes and ids.

  body (String) Default: 'body' [ Version 1.1.0 an above ]
  For doing the page movement the 'body' element is animated by default, you can select another element to animate with this option.

  displace (Boolean) Default: true [ Version 1.2.0 an above ]
  Displace the body content or not.
  */
  return $form;
}

/**
 * JS callback from hook_responsive_menus_style_info().
 */
function responsive_menus_sidr_style_js_settings($js_defaults = array()) {
  $js_settings = array(
    'selectors' => responsive_menus_explode_list('responsive_menus_sidr_css_selectors', '#main-menu', $js_defaults),
    'trigger_txt' => responsive_menus_var_get('responsive_menus_sidr_trigger_txt', t('Menu'), $js_defaults),
    'side' => responsive_menus_var_get('responsive_menus_sidr_menu_side', array(
      'left' => 'Left',
    ), $js_defaults),
    'speed' => responsive_menus_var_get('responsive_menus_sidr_animation_speed', 200, $js_defaults),
    'media_size' => responsive_menus_var_get('responsive_menus_sidr_media_size', 768, $js_defaults),
    'displace' => responsive_menus_var_get('responsive_menus_sidr_displace', 1, $js_defaults),
    'renaming' => responsive_menus_var_get('responsive_menus_sidr_renaming', 1, $js_defaults),
    'onOpen' => responsive_menus_var_get('responsive_menus_sidr_on_open', '', $js_defaults),
    'onClose' => responsive_menus_var_get('responsive_menus_sidr_on_close', '', $js_defaults),
  );
  return $js_settings;
}

/**
 * Form callback from hook_responsive_menus_style_info().
 *
 * @return array
 *   Drupal FAPI formatted array.
 */
function responsive_menus_google_nexus_style_settings() {
  $form['responsive_menus_google_nexus_css_selectors'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS selectors for which menu to responsify'),
    '#default_value' => variable_get('responsive_menus_google_nexus_css_selectors', '#main-menu'),
    '#description' => t('Enter CSS/jQuery selector of menus to responsify.'),
  );
  $form['responsive_menus_google_nexus_use_ecoicons'] = array(
    '#type' => 'select',
    '#title' => t('Use ecofonts font-family'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => variable_get('responsive_menus_google_nexus_use_ecoicons', 1),
    '#description' => t('Uses the ecofonts font-family included with GoogleNexusWebsiteMenu library for icons.'),
  );
  $form['responsive_menus_google_nexus_icons'] = array(
    '#type' => 'textarea',
    '#title' => t('Icons for menu items'),
    '#default_value' => variable_get('responsive_menus_google_nexus_icons', "\\ue005\n\\ue006"),
    '#description' => t('Enter 1 per-line or comma-separated.  See !documentation for examples.', array(
      '!documentation' => l(t('Unicode Character Table'), 'http://unicode-table.com/en/'),
    )),
  );
  $form['responsive_menus_google_nexus_icon_fallback'] = array(
    '#type' => 'textfield',
    '#title' => t('Fallback icon for extra menu items'),
    '#default_value' => variable_get('responsive_menus_google_nexus_icon_fallback', '&#57347;'),
    '#description' => t('This icon will be used for any number of menu items beyond the amount of icons you specified above.  See !documentation for examples.', array(
      '!documentation' => l(t('Unicode Character Table'), 'http://unicode-table.com/en/'),
    )),
  );
  return $form;
}

/**
 * JS callback from hook_responsive_menus_style_info().
 */
function responsive_menus_google_nexus_style_js_settings($js_defaults = array()) {
  $js_settings = array(
    'selectors' => responsive_menus_var_get('responsive_menus_google_nexus_css_selectors', '#main-menu', $js_defaults),
    'use_ecoicons' => responsive_menus_var_get('responsive_menus_google_nexus_use_ecoicons', 1, $js_defaults),
    'icons' => responsive_menus_explode_list('responsive_menus_google_nexus_icons', "\\ue005\n\\ue006", $js_defaults),
    'icon_fallback' => responsive_menus_var_get('responsive_menus_google_nexus_icon_fallback', '&#57347;', $js_defaults),
  );
  return $js_settings;
}

/**
 * Form callback from hook_responsive_menus_style_info().
 *
 * @return array
 *   Drupal FAPI formatted array.
 */
function responsive_menus_mlpm_style_settings() {
  $form['responsive_menus_mlpm_css_selectors'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS selectors for which menu to responsify'),
    '#default_value' => variable_get('responsive_menus_mlpm_css_selectors', '#main-menu'),
    '#description' => t('Enter CSS/jQuery selector of menus to responsify.'),
  );
  $form['responsive_menus_mlpm_media_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Screen width to respond to'),
    '#size' => 5,
    '#default_value' => variable_get('responsive_menus_mlpm_media_size', 768),
    '#description' => t('Width in pixels when we swap out responsive menu e.g. 768 (0 means the responsive menu will always show)'),
  );
  $form['responsive_menus_mlpm_move_to'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS selector to move menu to'),
    '#default_value' => variable_get('responsive_menus_mlpm_move_to', '#page-wrapper'),
    '#description' => t('Enter a CSS/JQuery selector of the container the nav menu will be moved to. This is useful when using a theme you don\'t want to alter.'),
  );
  $form['responsive_menus_mlpm_nav_block'] = array(
    '#type' => 'select',
    '#title' => t('Add nav block?'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => variable_get('responsive_menus_mlpm_nav_block', 1),
    '#description' => t('MLPM requires a nav block to be in place. This can be added using javascript if you don\'t want to alter your theme.'),
  );
  $form['responsive_menus_mlpm_nav_block_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Id for nav block'),
    '#default_value' => variable_get('responsive_menus_mlpm_nav_block_name', 'mlpm-menu'),
    '#description' => t('Enter the id of nav block.'),
  );
  $form['responsive_menus_mlpm_push'] = array(
    '#type' => 'textarea',
    '#title' => t('CSS selectors of containers to push'),
    '#default_value' => variable_get('responsive_menus_mlpm_push', '#page'),
    '#description' => t('CSS/jQuery selectors of the elements that need to be pushed when expading the MLPM (one per line)'),
  );
  $form['responsive_menus_mlpm_menu_height'] = array(
    '#type' => 'textfield',
    '#title' => 'Menu height',
    '#description' => "Menu height (integer, '%', 'px', 'em').",
    '#default_value' => variable_get('responsive_menus_mlpm_menu_height', '100%'),
  );
  $form['responsive_menus_mlpm_direction'] = array(
    '#type' => 'select',
    '#title' => t('Sliding direction'),
    '#options' => array(
      'ltr' => t('Left to right'),
      'rtl' => t('Right to left'),
    ),
    '#description' => '',
    '#default_value' => variable_get('responsive_menus_mlpm_direction', 'ltr'),
  );
  $form['responsive_menus_mlpm_mode'] = array(
    '#type' => 'select',
    '#title' => t('Menu sliding mode'),
    '#options' => array(
      'overlap' => t('Overlap'),
      'cover' => t('Cover'),
    ),
    '#description' => '',
    '#default_value' => variable_get('responsive_menus_mlpm_mode', 'overlap'),
  );
  $form['responsive_menus_mlpm_collapsed'] = array(
    '#type' => 'select',
    '#title' => t('How to load the menu'),
    '#options' => array(
      1 => t('Collapsed'),
      0 => t('Expanded'),
    ),
    '#description' => 'Initialize menu in collapsed/expanded mode',
    '#default_value' => variable_get('responsive_menus_mlpm_collapsed', 1),
  );
  $form['responsive_menus_mlpm_full_collapse'] = array(
    '#type' => 'select',
    '#title' => t('Full collapse'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#description' => 'Do you want to fully hide base level holder when collapsed?',
    '#default_value' => variable_get('responsive_menus_mlpm_full_collapse', 0),
  );
  $form['responsive_menus_mlpm_swipe'] = array(
    '#type' => 'select',
    '#title' => t('Swipe mode'),
    '#options' => array(
      'both' => t('Both'),
      'desktop' => t('Desktop'),
      'touchscreen' => t('Touchscreen'),
    ),
    '#description' => '',
    '#default_value' => variable_get('responsive_menus_mlpm_swipe', 'both'),
  );
  $form['responsive_menus_mlpm_decoration'] = array(
    '#type' => 'fieldset',
    '#title' => t('Menu decoration'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $style = variable_get('responsive_menus_mlpm_decoration', array());
  $form['responsive_menus_mlpm_decoration']['font_awesome'] = array(
    '#type' => 'checkbox',
    '#title' => t('Include font awesome'),
    '#description' => t('By default font awesome is used for the menu icons'),
    '#default_value' => 1,
  );
  $form['responsive_menus_mlpm_decoration']['google_fonts'] = array(
    '#type' => 'checkbox',
    '#title' => t('Include google fonts'),
    '#description' => t('By default google fonts are used to style this menu.'),
    '#default_value' => 1,
  );
  $form['responsive_menus_mlpm_decoration']['back_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Back text'),
    '#description' => t('The text that will appear on the back links leading you to previous levels of the menu.'),
    '#default_value' => isset($style['back_text']) ? $style['back_text'] : 'Back',
  );
  $form['responsive_menus_mlpm_decoration']['back_class'] = array(
    '#type' => 'textfield',
    '#title' => t('Back item class'),
    '#description' => t('The class of the back link that leads to the pervious levels of the menu.'),
    '#default_value' => isset($style['back_class']) ? $style['back_class'] : 'backItemClass',
  );
  $form['responsive_menus_mlpm_decoration']['back_icon'] = array(
    '#type' => 'textfield',
    '#title' => t('Back item icon'),
    '#description' => t('The icon used for the back link that leads to previous levels of the menu (default requires font awesome).'),
    '#default_value' => isset($style['back_icon']) ? $style['back_icon'] : 'fa fa-angle-right',
  );
  $form['responsive_menus_mlpm_decoration']['group_icon'] = array(
    '#type' => 'textfield',
    '#title' => t('Group icon'),
    '#description' => t('The icon used on menu links that lead into new layers of the menu (default requires font awesome).'),
    '#default_value' => isset($style['group_icon']) ? $style['group_icon'] : 'fa fa-angle-left',
  );
  $form['responsive_menus_mlpm_toggle'] = array(
    '#type' => 'fieldset',
    '#title' => t('Toggle control'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $toggle = variable_get('responsive_menus_mlpm_toggle', array());
  $form['responsive_menus_mlpm_toggle']['container'] = array(
    '#type' => 'textfield',
    '#title' => t('Menu toggle control container'),
    '#description' => t('The CSS/jQuery selector you would like an anchor tag that will toggle the menu open and closed (leave blank for no control).'),
    '#default_value' => isset($toggle['container']) ? $toggle['container'] : '',
  );
  $form['responsive_menus_mlpm_toggle']['text'] = array(
    '#type' => 'textarea',
    '#title' => t('Menu toggle control text'),
    '#description' => t('The text/filtered html you would like inside the toggle control'),
    '#default_value' => isset($toggle['text']) ? $toggle['text'] : '',
  );
  $form['responsive_menus_mlpm_toggle']['off_menu'] = array(
    '#type' => 'textfield',
    '#title' => t('Container to detect off menu clicks'),
    '#description' => t('The CSS/jQuery selector that will close the menu when clicked. This is useful for when you want to be able to close the menu by clicking off of the menu.'),
    '#default_value' => isset($toggle['off_menu']) ? $toggle['off_menu'] : '',
  );
  return $form;
}

/**
 * JS callback from hook_responsive_menus_style_info().
 */
function responsive_menus_mlpm_style_js_settings($js_defaults = array()) {
  $toggle = variable_get('responsive_menus_mlpm_toggle', array());
  $style = variable_get('responsive_menus_mlpm_decoration', array());
  $js_settings = array(
    'selectors' => responsive_menus_var_get('responsive_menus_mlpm_css_selectors', '#main-menu', $js_defaults),
    'media_size' => responsive_menus_var_get('responsive_menus_mlpm_media_size', 768, $js_defaults),
    'move_to' => responsive_menus_var_get('responsive_menus_mlpm_move_to', '#page-wrapper', $js_defaults),
    'nav_block' => variable_get('responsive_menus_mlpm_nav_block', 1, $js_defaults),
    'nav_block_name' => variable_get('responsive_menus_mlpm_nav_block_name', 'mlpm-menu', $js_defaults),
    'push' => explode("\n", variable_get('responsive_menus_mlpm_push', '#page', $js_defaults)),
    'menu_height' => variable_get('responsive_menus_mlpm_menu_height', '100%', $js_defaults),
    'direction' => variable_get('responsive_menus_mlpm_direction', 'ltr', $js_defaults),
    'mode' => variable_get('responsive_menus_mlpm_mode', 'overlap', $js_defaults),
    'collapsed' => variable_get('responsive_menus_mlpm_collapsed', 1, $js_defaults),
    'full_collapse' => variable_get('responsive_menus_mlpm_full_collapse', 0, $js_defaults),
    'swipe' => variable_get('responsive_menus_mlpm_swipe', 'both', $js_defaults),
    'toggle_container' => isset($toggle['container']) ? $toggle['container'] : '',
    'toggle_text' => isset($toggle['text']) ? check_markup($toggle['text'], 'filtered_html') : '',
    'off_menu' => isset($toggle['off_menu']) ? $toggle['off_menu'] : '',
    'back_text' => isset($style['back_text']) ? $style['back_text'] : 'Back',
    'back_class' => isset($style['back_class']) ? $style['back_class'] : 'backItemClass',
    'back_icon' => isset($style['back_icon']) ? $style['back_icon'] : 'fa fa-angle-right',
    'group_icon' => isset($style['group_icon']) ? $style['group_icon'] : 'fa fa-angle-left',
  );
  return $js_settings;
}

/**
 * Slight modification of variable_get for context and other usage.
 *
 * @param string $name
 *   Name of the variable.
 * @param mixed $default
 *   The variable's default fallback value.
 * @param array $rm_defaults
 *   The array of values that context (and possibly others) will pass.
 */
function responsive_menus_var_get($name, $default, $rm_defaults = array()) {
  if (!empty($rm_defaults) && !empty($rm_defaults[$name])) {
    return $rm_defaults[$name];
  }
  return variable_get($name, $default);
}

/**
 * Return array of selectors for JS settings.
 *
 * @return array
 *   Array of settings to pass with drupal_add_js().
 */
function responsive_menus_explode_list($style_var, $default, $js_defaults = array()) {
  $selectors = responsive_menus_var_get($style_var, $default, $js_defaults);
  $delimiter = ', ';

  // Strip out carriage returns.
  $selectors = str_replace("\r", '', $selectors);

  // Replace new lines with delimiter.
  $selectors = str_replace("\n", $delimiter, $selectors);

  // Explode to include original delimited.
  $values = explode($delimiter, $selectors);
  $values = array_filter($values);
  return $values;
}

/**
 * Recursively glob for directories.
 *
 * @param string $directory
 *   Directory to glob.
 * @param array $directories
 *   Increasing array of matching directories.
 */
function responsive_menus_glob_recursive($directory, &$directories = array()) {
  foreach (glob($directory, GLOB_ONLYDIR | GLOB_NOSORT) as $folder) {
    $directories[] = $folder;
    responsive_menus_glob_recursive("{$folder}/*", $directories);
  }
}

/**
 * Recursively search through directories for files with given extension.
 *
 * @param string $directory
 *   Directory to search.
 * @param string $extension
 *   File extensions to look for.
 *
 * @return array
 *   Array of matching files.
 */
function responsive_menus_glob_files($directory, $extension) {
  $directories = empty($directories) ? array() : $directories;
  responsive_menus_glob_recursive($directory, $directories);
  $files = array();
  foreach ($directories as $directory) {
    $files = array_merge($files, glob("{$directory}/*.{$extension}"));
  }
  return $files;
}

/**
 * Implements hook_page_build().
 */
function responsive_menus_page_build(&$page) {

  // Context rules.
  if (module_exists('context')) {
    if ($plugin = context_get_plugin('reaction', 'responsive_menus_general')) {
      $plugin
        ->execute();
    }
  }

  // Non-context additions.
  responsive_menus_execute();
}

/**
 * Final execution for Responsive Menus.  Add any js/css and settings required.
 */
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');
}

/**
 * Get the css to include for the multi-level-push menu based on the configuration.
 */
function _responsive_menus_mlpm_get_css() {
  $path = drupal_get_path('module', 'responsive_menus') . '/styles';
  $style = variable_get('responsive_menus_mlpm_decoration', array(
    'font_awesome' => 1,
    'google_fonts' => 1,
  ));
  $mlpm_css = array();
  if (!isset($style['google_fonts']) || $style['google_fonts']) {
    $mlpm_css[] = '//fonts.googleapis.com/css?family=Open+Sans+Condensed:300,300italic,700&subset=latin,cyrillic-ext,latin-ext,cyrillic';
  }
  if (!isset($style['font_awesome']) || $style['font_awesome']) {
    $mlpm_css[] = '//netdna.bootstrapcdn.com/font-awesome/4.0.1/css/font-awesome.min.css?the-file-wont-load-without-a-parameter';
  }
  $mlpm_css[] = $path . '/mlpm/css/jquery.multilevelpushmenu.css';
  return $mlpm_css;
}

Functions

Namesort descending Description
responsive_menus_admin_form Admin settings form for which menus to responsify.
responsive_menus_admin_form_submit Submit handler for responsive_menus_admin_form.
responsive_menus_codrops_responsive_multi_style_js_settings JS callback from hook_responsive_menus_style_info().
responsive_menus_codrops_responsive_multi_style_settings Form callback from hook_responsive_menus_style_info().
responsive_menus_context_plugins Implements hook_context_plugins().
responsive_menus_context_registry Implements hook_context_registry().
responsive_menus_ctools_plugin_api Implements hook_ctools_plugin_api().
responsive_menus_execute Final execution for Responsive Menus. Add any js/css and settings required.
responsive_menus_explode_list Return array of selectors for JS settings.
responsive_menus_glob_files Recursively search through directories for files with given extension.
responsive_menus_glob_recursive Recursively glob for directories.
responsive_menus_google_nexus_style_js_settings JS callback from hook_responsive_menus_style_info().
responsive_menus_google_nexus_style_settings Form callback from hook_responsive_menus_style_info().
responsive_menus_help Implements hook_help().
responsive_menus_libraries_info Implements hook_libraries_info(). @note : Libraries 2.x
responsive_menus_mean_menu_style_js_settings JS callback from hook_responsive_menus_style_info().
responsive_menus_mean_menu_style_settings Form callback from hook_responsive_menus_style_info().
responsive_menus_menu Implements hook_menu().
responsive_menus_mlpm_style_js_settings JS callback from hook_responsive_menus_style_info().
responsive_menus_mlpm_style_settings Form callback from hook_responsive_menus_style_info().
responsive_menus_page_build Implements hook_page_build().
responsive_menus_permission Implements hook_permission().
responsive_menus_responsive_menus_style_info Implements hook_responsive_menus_style_info().
responsive_menus_sidr_style_js_settings JS callback from hook_responsive_menus_style_info().
responsive_menus_sidr_style_settings Form callback from hook_responsive_menus_style_info().
responsive_menus_simple_style_js_settings JS callback from hook_responsive_menus_style_info().
responsive_menus_simple_style_settings Form callback from hook_responsive_menus_style_info().
responsive_menus_styles Gather available styles for Responsive Menus.
responsive_menus_style_load Load a single style.
responsive_menus_style_settings_form Ajax callback for switching styles.
responsive_menus_var_get Slight modification of variable_get for context and other usage.
_responsive_menus_mlpm_get_css Get the css to include for the multi-level-push menu based on the configuration.