/[drupal]/contributions/modules/lucid_menu/lucid_menu.module
ViewVC logotype

Contents of /contributions/modules/lucid_menu/lucid_menu.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri Apr 11 04:42:56 2008 UTC (19 months, 2 weeks ago) by develCuy
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +251 -0 lines
File MIME type: text/x-php
Initial commit of HEAD. Lucid menu is a highly customizable javascript menu which replaces the current menus with new ones.
1 <?php
2 /* $Id$ */
3 /**
4 * Lucid menus
5 *
6 * Allow advanced javascript menu manupulations. I've used dhtml_menu as a starting point, thanks merlinofchaos
7 */
8
9 if (variable_get('lucid_menu_defaults', 0))
10 _lucid_menu_delete_globals();
11
12 /**
13 * Implementation of hook_block
14 *
15 */
16 function lucid_menu_block($op = 'list', $delta = 0, $edit = array())
17 {
18 if ($op == 'list')
19 {
20 $blocks = array();
21 $root_menus = menu_get_root_menus();
22 foreach ($root_menus as $mid => $title) {
23 $blocks[$mid]['info'] = t('Lucid: ') .$title;
24 }
25
26 return $blocks;
27 }
28 else if ($op == 'view')
29 {
30 $path = drupal_get_path('module', 'lucid_menu');
31
32 drupal_add_js("$path/js/doiMenuDOM.js");
33 drupal_add_js("$path/js/lucid_menu_custom.js");
34 drupal_add_css("$path/css/lucid_menu.css");
35
36 $item = menu_get_item($delta);
37 $data['subject'] = check_plain($item['title']);
38
39 $block_settings = variable_get("lucid_menu_$delta", '');
40
41 $block_settings = trim($block_settings);
42
43 if (!empty($block_settings))
44 $block_settings = unserialize($block_settings);
45
46 if ($block_settings['options'])
47 $block_settings['options'] = str_replace('%theme_path', path_to_theme(), $block_settings['options']);
48
49 if ($block_settings['options'])
50 $block_settings['options'] = str_replace('%module_path', drupal_get_path('module', 'lucid_menu'),
51 $block_settings['options']);
52
53 // create main menu
54
55 $GLOBALS['LUCID_MENU_DEPTH'] = 0;
56 $GLOBALS['DELTA'] = $delta;
57 unset($GLOBALS['LAST_MENU_IN_DEPTH']);
58 $GLOBALS['LAST_MENU_IN_DEPTH'] = array();
59 $GLOBALS['COUNTER'] = 0;
60
61 $data['content'] = "var menu_{$delta}_{$GLOBALS['LUCID_MENU_DEPTH']}_0 = new TMainMenu('menu_{$delta}_{$GLOBALS['LUCID_MENU_DEPTH']}_0', '{$block_settings['direction']}');\n";
62
63 if ($block_settings['direction'] && $block_settings['direction'] == 'horizontal')
64 $global_settings = variable_get('lucid_menu_horizontal', _lucid_menu_horizontal_defaults());
65 else
66 $global_settings = variable_get('lucid_menu_vertical', _lucid_menu_vertical_defaults());
67
68 $global_settings = str_replace('%theme_path', path_to_theme(), $global_settings);
69 $global_settings = str_replace('%module_path', drupal_get_path('module', 'lucid_menu'), $global_settings);
70
71 $global_settings = explode("\n", $global_settings);
72
73 foreach ($global_settings AS $key => $value)
74 if (!empty($value))
75 $data['content'] .= "menu_{$delta}_{$GLOBALS['LUCID_MENU_DEPTH']}_0.".$value.";\n";
76
77 $block_settings['options'] = explode("\n", $block_settings['options']);
78
79 foreach ($block_settings['options'] AS $key => $value)
80 if (!empty($value))
81 $data['content'] .= "menu_{$delta}_{$GLOBALS['LUCID_MENU_DEPTH']}_0.".$value.";\n";
82
83 $GLOBALS['LAST_MENU_IN_DEPTH'][0] = "menu_{$delta}_{$GLOBALS['LUCID_MENU_DEPTH']}_0";
84
85 $menu_content = lucid_menu_tree($delta, TRUE)."\n";
86
87 if (trim($menu_content) != '')
88 $data['content'] = "<div class=\"doiMenuDOM\"><script type=\"text/javascript\">{$data['content']}\n{$menu_content}menu_{$delta}_{$GLOBALS['LUCID_MENU_DEPTH']}_0.Build();\n</script></div>";
89 else
90 $data['content'] = '';
91
92 return $data;
93 }
94
95 else if ($op == 'configure')
96 {
97 $values = variable_get("lucid_menu_$delta", '');
98
99 $values = trim($values);
100
101 if (!empty($values))
102 $values = unserialize($values);
103
104 $form['direction'] = array(
105 '#type' => 'select',
106 '#title' => t('Please choose the desired menu type'),
107 '#default_value' => $values['direction'] ? $values['direction'] : 'horizontal',
108 '#options' => array (
109 'horizontal' => t('Horizontal'),
110 'vertical' => t('Vertical')
111 ),
112 );
113
114 $form['options'] = array(
115 '#type' => 'textarea',
116 '#title' => t('Customizations'),
117 '#description' => t('Refer to the doc.htm for details on javascript customizations. You can also use "%theme_path"'.
118 'and %module_path to refer to the theme path and to the module path respectively. Include each '.
119 'directive on a seperate line. '.
120 'Examples of customizations :<br />SetPosition(\'absolute\',100,100)<br />'.
121 '_pop.SetPadding(0)'),
122 '#default_value' => $values['options'] ? $values['options'] : '',
123 );
124
125 return $form;
126 }
127 else if ($op == 'save')
128 variable_set("lucid_menu_$delta", serialize($edit));
129 }
130
131 function theme_lucid_menu_item($mid) {
132 $menu_leaf = menu_item_link($mid, FALSE);
133
134 $GLOBALS['LAST_MENU_IN_DEPTH'][$GLOBALS['LUCID_MENU_DEPTH']] = "menu_{$GLOBALS['DELTA']}_{$GLOBALS['LUCID_MENU_DEPTH']}_{$GLOBALS['COUNTER']}";
135
136 $menu = "var menu_{$GLOBALS['DELTA']}_{$GLOBALS['LUCID_MENU_DEPTH']}_{$GLOBALS['COUNTER']} = new TPopMenu('".addslashes($menu_leaf['title'])."', '16px', 'a', '".url($menu_leaf['href'])."', '".addslashes($menu_leaf['title'])."');\n";
137
138 $last_menu_in_parent_depth = $GLOBALS['LAST_MENU_IN_DEPTH'][$GLOBALS['LUCID_MENU_DEPTH'] - 1];
139
140 $menu .= "$last_menu_in_parent_depth.Add(menu_{$GLOBALS['DELTA']}_{$GLOBALS['LUCID_MENU_DEPTH']}_{$GLOBALS['COUNTER']});\n".$children;
141
142 $GLOBALS['COUNTER']++;
143
144 return $menu;
145 }
146
147 function lucid_menu_tree($pid = 1, $skip_parent) {
148 $menu = menu_get_menu();
149 $output = '';
150
151 if ($skip_parent && !(isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children'])) return '';
152
153 if (!$skip_parent)
154 $GLOBALS['LUCID_MENU_DEPTH']++;
155 if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children'])
156 {
157 if (!$skip_parent)
158 $output .= theme_lucid_menu_item($pid);
159 foreach ($menu['visible'][$pid]['children'] as $mid)
160 {
161 $type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;
162 $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;
163 $output .= lucid_menu_tree($mid, FALSE);
164 }
165 }
166 else
167 $output .= theme('lucid_menu_item', $pid);
168
169 if (!$skip_parent)
170 $GLOBALS['LUCID_MENU_DEPTH']--;
171
172 return $output;
173 }
174
175 /**
176 * Implementation of hook_menu().
177 *
178 */
179 function lucid_menu_menu($may_cache)
180 {
181 $items = array();
182
183 if (!$may_cache)
184 {
185 $items[] = array(
186 'path' => 'admin/settings/lucid_menu',
187 'title' => t('Lucid menu'),
188 'description' => t('These options control common menu properties.'),
189 'callback' => 'drupal_get_form',
190 'callback arguments' => array('lucid_menu_admin_settings'),
191 'access' => user_access('administer site configuration'),
192 'type' => MENU_NORMAL_ITEM);
193 }
194
195 return $items;
196 }
197
198 function lucid_menu_admin_settings()
199 {
200 $form = array();
201
202 $form['lucid_menu_horizontal'] = array(
203 '#type' => 'textarea',
204 '#title' => t('Horizontal menu common customizations'),
205 '#description' => t('Refer to the doc.htm for details on javascript customizations. You can also use "%theme_path"'.
206 'and %module_path to refer to the theme path and to the module path respectively. Include each '.
207 'directive on a seperate line. '.
208 'Examples of customizations :<br />SetPosition(\'absolute\',100,100)<br />'.
209 '_pop.SetPadding(0)'),
210 '#default_value' => variable_get("lucid_menu_horizontal",
211 _lucid_menu_horizontal_defaults()),
212 );
213
214 $form['lucid_menu_vertical'] = array(
215 '#type' => 'textarea',
216 '#title' => t('Vertical menu common customizations'),
217 '#description' => t('Refer to the doc.htm for details on javascript customizations. You can also use "%theme_path"'.
218 'and %module_path to refer to the theme path and to the module path respectively. Include each '.
219 'directive on a seperate line. '.
220 'Examples of customizations :<br />SetPosition(\'absolute\',100,100)<br />'.
221 '_pop.SetPadding(0)'),
222 '#default_value' => variable_get("lucid_menu_vertical",
223 _lucid_menu_vertical_defaults()),
224 );
225
226 $form['lucid_menu_defaults'] = array(
227 '#type' => 'checkbox',
228 '#title' => t('Revert to defaults'),
229 '#description' => t('This will revert the global options to the defaults'),
230 '#default_value' => 0
231 );
232
233 return system_settings_form($form);
234 }
235
236 function _lucid_menu_vertical_defaults()
237 {
238 return "SetBackground('%module_path/m5.gif')\nSetCorrection(-19, -152)\n_pop.SetCorrection(-12, -152)\nSetExpandIcon(true,'','')";
239 }
240
241 function _lucid_menu_horizontal_defaults()
242 {
243 return "SetCorrection(-19, -152)\n_pop.SetCorrection(-12, -152)\nSetExpandIcon(true,'','')";
244 }
245
246 function _lucid_menu_delete_globals()
247 {
248 variable_del('lucid_menu_horizontal');
249 variable_del('lucid_menu_vertical');
250 variable_del('lucid_menu_defaults');
251 }

  ViewVC Help
Powered by ViewVC 1.1.2