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

Contents of /contributions/modules/admin_menu_dropdown/admin_menu_dropdown.module

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


Revision 1.9 - (show annotations) (download) (as text)
Tue Dec 16 09:44:48 2008 UTC (11 months, 1 week ago) by deciphered
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +118 -90 lines
File MIME type: text/x-php
Initial port to D7
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Adds the ability to show/hide the Drupal Administration Menu via a selected behavior
7 */
8
9 /**
10 * Implementation of hook_menu().
11 */
12 function admin_menu_dropdown_menu() {
13 $items = array();
14
15 $items['admin/settings/admin_menu/amd_js'] = array(
16 'title' => 'Admin Menu Dropdown JS',
17 'page callback' => 'admin_menu_dropdown_js',
18 'access arguments' => array('access administration menu'),
19 'type' => MENU_CALLBACK
20 );
21
22 return $items;
23 }
24
25 /**
26 * Implementation of hook_init().
27 */
28 function admin_menu_dropdown_init() {
29 if (user_access('access administration menu')) {
30 $behaviors = admin_menu_dropdown_behaviors();
31
32 $js = '';
33
34 $js .= "amdBehavior = '". variable_get('admin_menu_dropdown_behavior', 'amd_key_combo') ."'; ";
35 $js .= "amdPosition = '". variable_get('admin_menu_dropdown_position', 'fixed') ."'; ";
36
37 if (isset($_SESSION['amd_status'])) {
38 $js .= "amdHidden = ". ($_SESSION['amd_status'] == 'off' ? "1" : "0") ."; ";
39 }
40 else {
41 $js .= "amdHidden = ". (variable_get('admin_menu_dropdown_hide', TRUE) ? "1" : "0") ."; ";
42 }
43
44 // Add behavior specific CSS
45 if (isset($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['css'])) {
46 drupal_add_css($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['css'], 'module');
47 }
48
49 // Add behavior specific JavaScript
50 if (isset($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js'])) {
51 drupal_add_js($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js'], 'file');
52 }
53
54 // Add behavior specific JavaScript variables
55 if (isset($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js_vars'])
56 && drupal_function_exists($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js_vars'])) {
57 $js .= call_user_func($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js_vars']);
58 }
59
60 drupal_add_js(drupal_get_path('module', 'admin_menu_dropdown') .'/admin_menu_dropdown.js', 'file');
61 drupal_add_js($js, 'inline');
62 }
63 }
64
65 /**
66 * Implementation of hook_form_alter().
67 */
68 function admin_menu_dropdown_form_alter(&$form, $form_state, $form_id) {
69 if ($form_id == 'admin_menu_theme_settings') {
70 drupal_add_css(drupal_get_path('module', 'admin_menu_dropdown') .'/admin_menu_dropdown_settings.css', 'module');
71
72 $behaviors = admin_menu_dropdown_behaviors();
73
74 // Render Buttons below extra settings form
75 $form['buttons']['#weight'] = '1';
76
77 // Add Global Admin Menu Dropdown settings
78 $form['admin_menu_dropdown'] = array(
79 '#type' => 'fieldset',
80 '#title' => 'Administration Menu Dropdown',
81 );
82 $form['admin_menu_dropdown']['admin_menu_dropdown_hide'] = array(
83 '#type' => 'checkbox',
84 '#title' => t('Hide admin menu by default'),
85 '#default_value' => variable_get('admin_menu_dropdown_hide', TRUE),
86 '#description' => t('If checked the Administration menu is hidden by default'),
87 );
88
89 if (!isset($form['admin_menu_position_fixed'])) {
90 $form['admin_menu_dropdown']['admin_menu_dropdown_position'] = array(
91 '#type' => 'select',
92 '#title' => t('Admin Menu Dropdown position style'),
93 '#options' => array(
94 'static' => 'Static',
95 'fixed' => 'Fixed',
96 ),
97 '#default_value' => variable_get('admin_menu_dropdown_position', 'fixed'),
98 '#description' => t('<strong>Static:</strong> Administration menu will appear at the top of the page requiring you to scroll up to see it.<br />
99 <strong>Fixed:</strong> Administration menu will appear at the top of the window no matter where you are on the page. <em>(May not work in all browsers)</em>'),
100 );
101 }
102
103 $form['admin_menu_dropdown']['admin_menu_dropdown_behavior'] = array(
104 '#type' => 'select',
105 '#title' => t('Admin Menu Dropdown behavior'),
106 '#options' => $behaviors['list'],
107 '#default_value' => variable_get('admin_menu_dropdown_behavior', 'amd_key_combo'),
108 );
109
110 // Add all behavior specific settings
111 foreach ($behaviors['data'] as $behavior => $data) {
112 if (isset($data['settings']) && drupal_function_exists($data['settings'])) {
113 $form['admin_menu_dropdown'][$behavior] = array(
114 '#type' => 'fieldset',
115 '#title' => $data['title'] . t(' settings'),
116 '#collapsible' => TRUE,
117 '#collapsed' => TRUE,
118 );
119 $form['admin_menu_dropdown'][$behavior][] = call_user_func($data['settings']);
120 }
121 }
122
123 }
124 }
125
126 function admin_menu_dropdown_behaviors() {
127 foreach (module_invoke_all('amd_behavior') as $behavior => $data) {
128 $behaviors['list'][$behavior] = $data['title'];
129 $behaviors['data'][$behavior] = $data;
130 }
131
132 return $behaviors;
133 }
134
135 function admin_menu_dropdown_amd_behavior() {
136 include_once drupal_get_path('module', 'admin_menu_dropdown') .'/behaviors/key_combo/key_combo.inc';
137
138 return array(
139 'amd_icon_hotspot' => array(
140 'title' => 'Icon Hotspot',
141 'css' => drupal_get_path('module', 'admin_menu_dropdown') .'/behaviors/icon_hotspot/icon_hotspot.css',
142 'js' => drupal_get_path('module', 'admin_menu_dropdown') .'/behaviors/icon_hotspot/icon_hotspot.js',
143 ),
144 'amd_key_combo' => array(
145 'title' => 'Key Combo',
146 'settings' => 'admin_menu_dropdown_key_combo_settings',
147 'css' => drupal_get_path('module', 'admin_menu_dropdown') .'/behaviors/key_combo/key_combo.css',
148 'js' => drupal_get_path('module', 'admin_menu_dropdown') .'/behaviors/key_combo/key_combo.js',
149 'js_vars' => 'admin_menu_dropdown_key_combo_js_vars',
150 )
151 );
152 }
153
154 function admin_menu_dropdown_js() {
155 $_SESSION['amd_status'] = arg(5);
156 print drupal_json($_SESSION['amd_status']);
157 exit;
158 }

  ViewVC Help
Powered by ViewVC 1.1.2