Skip to content

Commit f47ff24

Browse files
committed
Add option to disable keyboard shortcuts.
They are enabled by default.
1 parent 3c1979d commit f47ff24

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

webapp/public/js/domjudge.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ function disableNotifications()
5555
return true;
5656
}
5757

58+
function enableKeys()
59+
{
60+
setCookie('domjudge_keys', 1);
61+
$("#keys_disable").removeClass('d-none');
62+
$("#keys_disable").show();
63+
$("#keys_enable").hide();
64+
}
65+
66+
function disableKeys()
67+
{
68+
setCookie('domjudge_keys', 0);
69+
$("#keys_enable").removeClass('d-none');
70+
$("#keys_enable").show();
71+
$("#keys_disable").hide();
72+
}
73+
5874
// Send a notification if notifications have been enabled.
5975
// The options argument is passed to the Notification constructor,
6076
// except that the following tags (if found) are interpreted and
@@ -814,6 +830,10 @@ function initializeKeyboardShortcuts() {
814830
var $body = $('body');
815831
var ignore = false;
816832
$body.on('keydown', function(e) {
833+
var keysCookie = getCookie('domjudge_keys');
834+
if (keysCookie != 1 && keysCookie != "") {
835+
return;
836+
}
817837
// Check if the user is not typing in an input field.
818838
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
819839
return;

webapp/templates/jury/base.html.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
}
3535
}
3636
37+
$('#keys_disable').click(disableKeys);
38+
$('#keys_enable').click(enableKeys);
39+
var keysCookie = getCookie('domjudge_keys');
40+
if (keysCookie != 1 && keysCookie != "") {
41+
$('#keys_enable').removeClass('d-none');
42+
} else {
43+
$('#keys_disable').removeClass('d-none');
44+
}
45+
3746
updateMenuAlerts();
3847
setInterval(updateMenuAlerts, 20000);
3948

webapp/templates/jury/menu.html.twig

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,25 @@
116116

117117
{% if refresh is defined and refresh %}
118118
<a class="dropdown-item" href="#" id="refresh-navitem">
119-
<i class="fas fa-sync-alt fa-fw"></i> <span id="refresh-toggle">
120-
{% if refresh_flag %}
121-
Disable Refresh
122-
{% else %}
123-
Enable Refresh
124-
{% endif %}
125-
</span>
126-
{% if refresh %}
127-
<span class="small text-muted">({{ refresh.after }}s)</span>
128-
{% endif %}
119+
<i class="fas fa-sync-alt fa-fw"></i>
120+
<span id="refresh-toggle">
121+
{% if refresh_flag %}
122+
Disable Refresh
123+
{% else %}
124+
Enable Refresh
125+
{% endif %}
126+
</span>
127+
<span class="small text-muted">({{ refresh.after }}s)</span>
129128
</a>
130129
{% endif %}
131130

131+
<a class="dropdown-item d-none" href="#" id="keys_disable">
132+
<i class="fas fa-keyboard fa-fw"></i> Disable keyboard shortcuts
133+
</a>
134+
<a class="dropdown-item d-none" href="#" id="keys_enable">
135+
<i class="fas fa-keyboard fa-fw"></i> Enable keyboard shortcuts
136+
</a>
137+
132138
<a class="dropdown-item" href="{{ path('logout') }}"><i class="fas fa-sign-out-alt fa-fw"></i>Logout </a>
133139
</div>
134140
</li>

0 commit comments

Comments
 (0)