Projet

Général

Profil

Paste
Télécharger (6,7 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / dhtml_menu / dhtml_menu.admin.inc @ bad4e148

1
<?php
2

    
3

    
4
/**
5
 * @file dhtml_menu.admin.inc
6
 * Functions that are only called on the admin pages.
7
 */
8

    
9
/**
10
 * Module settings form.
11
 */
12
function dhtml_menu_settings($form, &$form_state) {
13
  $settings = variable_get('dhtml_menu_settings');
14

    
15
  $options['nav'] = array(
16
    '#type' => 'radios',
17
    '#title' => t('Static navigation'),
18
    '#options' => array(
19
      'open' => t('<strong>No Collapsing:</strong> Menu items cannot be collapsed dynamically. Instead, clicking on an already expanded item will take you to the page.'),
20
      'bullet' => t('<strong>Expand on Bullet:</strong> All links will continue to function as static links. To expand an item, click the bullet icon next to the link.'),
21
      'clone' => t('<strong>Cloned Menu Link:</strong> At the top of each menu, an extra link will be generated that leads to the page of the parent item.'),
22
      'hover' => t('<strong>Expand on Hover:</strong> Items expand when the cursor hovers over them. Links function normally. <em>This is unfamiliar and causes accessibility problems!</em>'),
23
      'double-click' => t('<strong>Doubleclick:</strong> To expand an item, click the link once. To navigate to the page, click it twice. <em>This will be difficult to find for your users!</em>'),
24
      'none' => t('<strong>None:</strong> Clicking the link will expand the item. Navigating to the page is not possible at all. <em>This will make pages with sub-items very difficult to reach!</em>'),
25
    ),
26
    '#default_value' => $settings['nav'],
27
    '#description' => t('Dynamic expansion of menus competes with the static navigation of content. Choose how to resolve this conflict.'),
28
  );
29

    
30
  $options['animation'] = array(
31
    '#type' => 'fieldset',
32
    '#title' => t('Animation'),
33
    '#collapsible' => TRUE,
34
    '#collapsed' => TRUE,
35
  );
36

    
37
  $options['animation']['effects'] = array(
38
    '#type' => 'checkboxes',
39
    '#title' => t('Effects'),
40
    '#options' => array(
41
      'height' => t('Slide in vertically'),
42
      'width' => t('Slide in horizontally'),
43
      'opacity' => t('Fade in'),
44
    ),
45
    '#description' => t('You may pick any number of animation effects that will accompany the opening and closing of a menu.'),
46
    '#default_value' => $settings['animation']['effects'],
47
  );
48

    
49
  $options['animation']['speed'] = array(
50
    '#type' => 'select',
51
    '#title' => t('Speed'),
52
    '#options' => array(
53
      100  => t('Very Fast (@seconds s)', array('@seconds' => 0.1)), 
54
      500  => t('Fast (@seconds s)', array('@seconds' => 0.5)), 
55
      1000 => t('Medium (@seconds s)', array('@seconds' => 1)),
56
      1500 => t('Slow (@seconds s)', array('@seconds' => 1.5)), 
57
      2000 => t('Very Slow (@seconds s)', array('@seconds' => 2)),
58
    ),
59
    '#default_value' => $settings['animation']['speed'],
60
    '#description' => t('Choose how quickly the menus should expand and collapse.'),
61
  );
62

    
63
  $options['effects'] = array(
64
    '#type' => 'fieldset',
65
    '#title' => t('Other effects'),
66
    '#collapsible' => TRUE,
67
    '#collapsed' => TRUE,
68
  );
69

    
70
  $options['effects']['siblings'] = array(
71
    '#type' => 'radios',
72
    '#title' => t('When a menu opens'),
73
    '#options' => array(
74
      'none' => t('Keep other menus open.'),
75
      'close-all' => t('Close all other open menus on the page.'),
76
      'close-same-tree' => t('Close other open menus in the same tree.'),
77
    ),
78
    '#default_value' => $settings['effects']['siblings'],
79
  );
80

    
81
  $options['effects']['children'] = array(
82
    '#type' => 'radios',
83
    '#title' => t('When a menu closes'),
84
    '#options' => array(
85
      'none' => t('Remember which sub-items were expanded when it next opens.'),
86
      'close-children' => t('Close all its sub-items, too.'),
87
    ),
88
    '#default_value' => $settings['effects']['children'],
89
  );
90

    
91
  $options['effects']['remember'] = array(
92
    '#type' => 'radios',
93
    '#title' => t('When a new page is loaded'),
94
    '#options' => array(
95
      'remember' => t('Remember which items were expanded on the last page.'),
96
      '' => t('Expand only the currently active path.'),
97
    ),
98
    '#default_value' => $settings['effects']['remember'],
99
  );
100

    
101
  $options['filter'] = array(
102
    '#type' => 'fieldset',
103
    '#title' => t('Disabling DHTML'),
104
    '#collapsible' => TRUE,
105
    '#collapsed' => TRUE,
106
  );
107

    
108
  $options['filter']['type'] = array(
109
    '#type' => 'radios',
110
    '#title' => t('Filter type'),
111
    '#options' => array(
112
      'blacklist' => t('Disable DHTML on the menus checked below.'),
113
      'whitelist' => t('Enable DHTML on the menus checked below.'),
114
    ),
115
    '#default_value' => $settings['filter']['type'],
116
  );
117

    
118
  $options['filter']['list'] = array(
119
    '#type' => 'checkboxes',
120
    '#title' => t('List'),
121
    '#options' => _dhtml_menu_menus(),
122
    '#default_value' => $settings['filter']['list'],
123
    '#description' => t('DHTML will be used for all menus by default, but can be switched off for specific menus.'),
124
  );
125
  
126
  if (module_exists('menu_block')) {
127
    $options['filter']['menu_block'] = array(
128
      '#type' => 'checkboxes',
129
      '#title' => t('Menu Blocks'),
130
      '#options' => _dhtml_menu_blocks(),
131
      '#default_value' => $settings['filter']['menu_block'],
132
      '#description' => t('You may enable/disable specific menu blocks here, as long as the corresponding menu is enabled.'),
133
    );
134
  }
135

    
136
  $options['#tree'] = TRUE;
137
  $form['dhtml_menu_settings'] = $options;
138

    
139
  // Disable automatic defaults, which don't work with nested values.
140
  return system_settings_form($form, FALSE);
141
}
142

    
143
/**
144
 * Build a human-readable option list for all non-empty menus.
145
 * Custom menus and book menus are included if the respective modules are enabled.
146
 */
147
function _dhtml_menu_menus() {
148
  if (function_exists('menu_get_menus')) {
149
    // If the menu module is enabled, list custom menus.
150
    $menus = menu_get_menus();
151
  }
152
  else {
153
    // Otherwise, list only system menus.
154
    $menus = menu_list_system_menus();
155
  }
156

    
157
  // If the book module is enabled, also include book menus.
158
  if (function_exists('book_get_books')) {
159
    foreach (book_get_books() as $bid => $link) {
160
      $menus["book-toc-$bid"] = t('Book: %title', array('%title' => $link['title']));
161
    }
162
  }
163

    
164
  // menu_get_names() filters out empty menus, and adds any menus not found using the above calls (edge case).
165
  foreach (menu_get_names() as $menu) {
166
    $menu_names[$menu] = isset($menus[$menu]) ? $menus[$menu] : t('Other menu: %menu', array('%menu' => $menu));
167
  }
168

    
169
  return $menu_names;
170
}
171

    
172
/**
173
 * Build an option list for all menu blocks in the system.
174
 * Only applicable if the Menu Block module is installed.
175
 */
176
function _dhtml_menu_blocks() {
177
  if (function_exists('menu_block_block_info')) {
178
    $block_names = array();
179
    $blocks = menu_block_block_info();
180
    foreach ($blocks as $delta => $block) {
181
      $block_names['menu_block_' . $delta] = $block['info'];
182
    }
183
    
184
    return $block_names;
185
  }
186
  return NULL;
187
}