You are here

admin_menu_dropdown.module in Admin Menu Hider 5

Makes drupal administration menu able to be hidden or shown by pressing key combo

File

admin_menu_dropdown.module
View source
<?php

/**                                                            
* @file
* Makes drupal administration menu able to be hidden or shown by pressing key combo
*/

/**
* Implementation of hook_menu().
*/
function admin_menu_dropdown_menu($may_cache) {
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/admin_menu_dropdown',
      'title' => t('Admin menu dropdown'),
      'access' => user_access('administer site configuration'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'admin_menu_dropdown_settings',
      ),
      'description' => t('Edit the settings for Admin Menu Dropdown'),
      'type' => MENU_NORMAL_ITEM,
    );
  }
  if (user_access('access administration menu') && !$may_cache) {
    $css = variable_get('admin_menu_dropdown_hide', TRUE) ? 'admin_menu_dropdown.css' : 'admin_menu_dropdown_show.css';
    $js = variable_get('admin_menu_dropdown_hide', TRUE) ? "hidden = 1;" : "hidden = 0;";
    $js .= " visibilityCombo = '" . variable_get('admin_menu_dropdown_visibility_modifier', 'ctrl + alt');
    $js .= variable_get('admin_menu_dropdown_visibility_key', '') ? " + " . variable_get('admin_menu_dropdown_visibility_key', '') . "';" : "';";
    $js .= " disableCombo = '" . variable_get('admin_menu_dropdown_disable_modifier', 'ctrl + alt + shift');
    $js .= variable_get('admin_menu_dropdown_disable_key', '') ? " + " . variable_get('admin_menu_dropdown_disable_key', '') . "';" : "';";
    drupal_add_css(drupal_get_path('module', 'admin_menu_dropdown') . '/' . $css, 'module');
    drupal_add_js($js, 'inline');
    drupal_add_js(drupal_get_path('module', 'admin_menu_dropdown') . '/admin_menu_dropdown.js', 'module');
  }
  return $items;
}

/**
* Form builder for admin menu dropdown settings.
*/
function admin_menu_dropdown_settings() {
  drupal_add_css(drupal_get_path('module', 'admin_menu_dropdown') . '/admin_menu_dropdown_settings.css', 'module');
  $form['admin_menu_dropdown_visibility_modifier'] = array(
    '#type' => 'select',
    '#title' => t('Display modifier + key'),
    '#options' => admin_menu_dropdown_settings_combos('modifier'),
    '#default_value' => variable_get('admin_menu_dropdown_visibility_modifier', ''),
    '#prefix' => '<div class="inline-element">',
    '#suffix' => '</div>',
  );
  $form['admin_menu_dropdown_visibility_key'] = array(
    '#type' => 'select',
    '#options' => admin_menu_dropdown_settings_combos('key'),
    '#default_value' => variable_get('admin_menu_dropdown_visibility_key', ''),
    '#description' => t('Key combination to show/hide Administration Menu.'),
    '#prefix' => '<div class="inline-element"> + ',
    '#suffix' => '</div>',
  );
  $form['admin_menu_dropdown_disable_modifier'] = array(
    '#type' => 'select',
    '#title' => t('Disable modifier + key'),
    '#options' => admin_menu_dropdown_settings_combos('modifier'),
    '#default_value' => variable_get('admin_menu_dropdown_disable_modifier', 'ctrl + alt + shift'),
    '#prefix' => '<div class="inline-element">',
    '#suffix' => '</div>',
  );
  $form['admin_menu_dropdown_disable_key'] = array(
    '#type' => 'select',
    '#options' => admin_menu_dropdown_settings_combos('key'),
    '#default_value' => variable_get('admin_menu_dropdown_disable_key', ''),
    '#description' => t('Key combination to enable/disable hiding of Administration Menu.'),
    '#prefix' => '<div class="inline-element"> + ',
    '#suffix' => '</div>',
  );
  $form['admin_menu_dropdown_hide'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide admin menu by default'),
    '#default_value' => variable_get('admin_menu_dropdown_hide', TRUE),
    '#description' => t('If checked the Drupal Administration Menu is hidden by default'),
  );
  return system_settings_form($form);
}
function admin_menu_dropdown_settings_validate($form_id, $form_values) {
  if ($form_values['admin_menu_dropdown_visibility_modifier'] == $form_values['admin_menu_dropdown_disable_modifier'] && $form_values['admin_menu_dropdown_visibility_key'] == $form_values['admin_menu_dropdown_disable_key']) {
    form_set_error('', t('Each key combination must be unique.'));
  }
}
function admin_menu_dropdown_settings_combos($type) {
  switch ($type) {
    case 'key':
      $options = array(
        '' => 'None',
        '65' => 'A',
        '66' => 'B',
        '67' => 'C',
        '68' => 'D',
        '69' => 'E',
        '70' => 'F',
        '71' => 'G',
        '72' => 'H',
        '73' => 'I',
        '74' => 'J',
        '75' => 'K',
        '76' => 'L',
        '77' => 'M',
        '78' => 'N',
        '79' => 'O',
        '80' => 'P',
        '81' => 'Q',
        '82' => 'R',
        '83' => 'S',
        '84' => 'T',
        '85' => 'U',
        '86' => 'V',
        '87' => 'W',
        '88' => 'X',
        '89' => 'Y',
        '90' => 'Z',
      );
      break;
    case 'modifier':
      $options = array(
        'ctrl + alt' => 'ctrl + alt',
        'ctrl + shift' => 'ctrl + shift',
        'ctrl + alt + shift' => 'ctrl + alt + shift',
      );
      break;
  }
  return $options;
}

Functions