'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 '

' . t('Responsify your menus! Using any jQuery compatible selector, make elements mobile friendly. Technically you could use this on more than menus... The administration page 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'))) . '

'; // On the admin settings page. case 'admin/config/user-interface/responsive_menus': return '

' . 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.') . '

'; } } /** * 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' => '
', '#suffix' => '
', '#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' => '
' . $style_info['selector'] . '
', ); } // 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 you could use !use', array('@ul' => '