1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Key bindings plugin.
|
6 |
|
|
*/
|
7 |
|
|
class sweaver_plugin_kb extends sweaver_plugin {
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Sweaver dependencies.
|
11 |
|
|
*/
|
12 |
|
|
public function sweaver_dependencies() {
|
13 |
|
|
if (!variable_get('sweaver_plugin_status_sweaver_plugin_styles', FALSE)) {
|
14 |
|
|
return array('Manage styles');
|
15 |
|
|
}
|
16 |
|
|
return array();
|
17 |
|
|
}
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* Menu registry.
|
21 |
|
|
*/
|
22 |
|
|
public function sweaver_menu(&$weight, $page_arguments, $base) {
|
23 |
|
|
$items = array();
|
24 |
|
|
|
25 |
|
|
$items['admin/config/user-interface/sweaver/kb'] = $base + array(
|
26 |
|
|
'title' => 'Keyboard',
|
27 |
|
|
'page arguments' => array($page_arguments),
|
28 |
|
|
'type' => MENU_LOCAL_TASK,
|
29 |
|
|
'weight' => $weight++,
|
30 |
|
|
);
|
31 |
|
|
|
32 |
|
|
return $items;
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
* Frontend css and js.
|
37 |
|
|
*/
|
38 |
|
|
public function sweaver_form_css_js(&$inline_settings) {
|
39 |
|
|
drupal_add_js(drupal_get_path('module', 'sweaver') .'/plugins/sweaver_plugin_kb/jquery.hotkeys.js');
|
40 |
|
|
drupal_add_js(drupal_get_path('module', 'sweaver') .'/plugins/sweaver_plugin_kb/sweaver_plugin_kb.js');
|
41 |
|
|
$bindings = $this->sweaver_kb_bindings();
|
42 |
|
|
$binding_options = $this->sweaver_kb_binding_options();
|
43 |
|
|
|
44 |
|
|
foreach ($bindings as $key => $value) {
|
45 |
|
|
|
46 |
|
|
// Do not add when a certain variable isn't set. (eg delete tab)
|
47 |
|
|
if (isset($value['variable']) && !variable_get($value['variable'], FALSE)) {
|
48 |
|
|
continue;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
// Get keyboard key. Make sure it's not empty.
|
52 |
|
|
$keyboard_key = variable_get('sweaver_plugin_kb_'. $key, $value['default']);
|
53 |
|
|
if (!empty($keyboard_key)) {
|
54 |
|
|
$inline_settings['sweaver']['kb'][$key] = array(
|
55 |
|
|
'kb_code' => $keyboard_key,
|
56 |
|
|
'kb_button' => $binding_options[$keyboard_key],
|
57 |
|
|
'element' => isset($value['element']) ? $value['element'] : '',
|
58 |
|
|
);
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
/**
|
64 |
|
|
* Keyboard bindings settings form.
|
65 |
|
|
*/
|
66 |
|
|
public function sweaver_menu_callback() {
|
67 |
|
|
$form = array();
|
68 |
|
|
$bindings = $this->sweaver_kb_bindings();
|
69 |
|
|
$binding_options = $this->sweaver_kb_binding_options();
|
70 |
|
|
|
71 |
|
|
$form['info'] = array(
|
72 |
|
|
'#markup' => t('Select keys for every event possible. Note, there is no validation when saving this form, so make sure every event has a unique key.'),
|
73 |
|
|
);
|
74 |
|
|
|
75 |
|
|
foreach ($bindings as $key => $value) {
|
76 |
|
|
$form['sweaver_plugin_kb_'. $key] = array(
|
77 |
|
|
'#type' => 'select',
|
78 |
|
|
'#options' => $binding_options,
|
79 |
|
|
'#title' => $value['title'],
|
80 |
|
|
'#default_value' => variable_get('sweaver_plugin_kb_'. $key, $value['default']),
|
81 |
|
|
);
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
return system_settings_form($form);
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
/**
|
88 |
|
|
* Possible keyboard bindings.
|
89 |
|
|
*/
|
90 |
|
|
public function sweaver_kb_bindings() {
|
91 |
|
|
$bindings = array(
|
92 |
|
|
'save' => array(
|
93 |
|
|
'title' => t('Save style popup'),
|
94 |
|
|
'default' => '83',
|
95 |
|
|
'element' => '.save-style-popup',
|
96 |
|
|
'double' => TRUE,
|
97 |
|
|
),
|
98 |
|
|
'load' => array(
|
99 |
|
|
'title' => t('Load style popup'),
|
100 |
|
|
'default' => '76',
|
101 |
|
|
'element' => '.load-style-popup',
|
102 |
|
|
'double' => TRUE,
|
103 |
|
|
),
|
104 |
|
|
'publish' => array(
|
105 |
|
|
'title' => t('Publish style popup'),
|
106 |
|
|
'default' => '80',
|
107 |
|
|
'element' => '.publish-style-popup',
|
108 |
|
|
'double' => TRUE,
|
109 |
|
|
),
|
110 |
|
|
'delete' => array(
|
111 |
|
|
'title' => t('Delete style popup'),
|
112 |
|
|
'default' => '68',
|
113 |
|
|
'variable' => 'sweaver_styles_delete_tab',
|
114 |
|
|
'element' => '.delete-style-popup',
|
115 |
|
|
'double' => TRUE,
|
116 |
|
|
),
|
117 |
|
|
'close' => array(
|
118 |
|
|
'title' => t('Close popup'),
|
119 |
|
|
'default' => '27',
|
120 |
|
|
'double' => FALSE,
|
121 |
|
|
),
|
122 |
|
|
);
|
123 |
|
|
|
124 |
|
|
return $bindings;
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
/**
|
128 |
|
|
* All possible keyboard bindings.
|
129 |
|
|
*/
|
130 |
|
|
public function sweaver_kb_binding_options() {
|
131 |
|
|
return array(
|
132 |
|
|
'',
|
133 |
|
|
'27' => 'esc',
|
134 |
|
|
'48' => '0',
|
135 |
|
|
'49' => '1',
|
136 |
|
|
'50' => '2',
|
137 |
|
|
'51' => '3',
|
138 |
|
|
'52' => '4',
|
139 |
|
|
'53' => '5',
|
140 |
|
|
'54' => '6',
|
141 |
|
|
'55' => '7',
|
142 |
|
|
'56' => '8',
|
143 |
|
|
'57' => '9',
|
144 |
|
|
'65' => 'a',
|
145 |
|
|
'66' => 'b',
|
146 |
|
|
'67' => 'c',
|
147 |
|
|
'68' => 'd',
|
148 |
|
|
'69' => 'e',
|
149 |
|
|
'70' => 'f',
|
150 |
|
|
'71' => 'g',
|
151 |
|
|
'72' => 'h',
|
152 |
|
|
'73' => 'i',
|
153 |
|
|
'74' => 'j',
|
154 |
|
|
'75' => 'k',
|
155 |
|
|
'76' => 'l',
|
156 |
|
|
'77' => 'm',
|
157 |
|
|
'78' => 'n',
|
158 |
|
|
'79' => 'o',
|
159 |
|
|
'80' => 'p',
|
160 |
|
|
'81' => 'q',
|
161 |
|
|
'82' => 'r',
|
162 |
|
|
'83' => 's',
|
163 |
|
|
'84' => 't',
|
164 |
|
|
'85' => 'u',
|
165 |
|
|
'86' => 'v',
|
166 |
|
|
'87' => 'w',
|
167 |
|
|
'88' => 'x',
|
168 |
|
|
'89' => 'y',
|
169 |
|
|
'90' => 'z',
|
170 |
|
|
);
|
171 |
|
|
}
|
172 |
|
|
} |