-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_js_events.php
39 lines (33 loc) · 919 Bytes
/
lib_js_events.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
function js_event_register_ctrl_click_2_click_id(string $key = null, string $id = null) : array
{
static $registration = [];
if ($key !== null) {
if ($id !== null)
$registration[$key] = $id;
else
unset($registration[$key]); }
return $registration;
}
function js_event_setup_scriptH()
{
$registration_jsonH = json_encode(js_event_register_ctrl_click_2_click_id());
echo <<<EOS
<script>
(function() {
var registration = $registration_jsonH;
document.body.addEventListener('keydown', function(Ev) {
if (event.ctrlKey || event.metaKey) {
if (event.key in registration) {
var El = document.getElementById(registration[event.key]);
El.click();
Ev.preventDefault(); } }
}, true);
for (var n in registration) {
var El = document.getElementById(registration[n]);
El.innerHTML += ' <kbd>[^' + n.toUpperCase() + ']</kbd>'
}
})();
</script>
EOS;
}