2012-10-18 19:58:10 +02:00
|
|
|
var hotkeys = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-06-11 04:06:16 +02:00
|
|
|
function do_narrow_action(action) {
|
|
|
|
action(current_msg_list.selected_id(), {trigger: 'hotkey'});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
var actions_dropdown_hotkeys = [
|
|
|
|
'down_arrow',
|
|
|
|
'up_arrow',
|
|
|
|
'vim_up',
|
|
|
|
'vim_down',
|
2017-01-12 00:17:43 +01:00
|
|
|
'enter',
|
2013-07-11 23:06:58 +02:00
|
|
|
];
|
|
|
|
|
2016-06-14 00:08:02 +02:00
|
|
|
// Note that multiple keys can map to the same event_name, which
|
|
|
|
// we'll do in cases where they have the exact same semantics.
|
|
|
|
// DON'T FORGET: update keyboard_shortcuts.html
|
|
|
|
|
|
|
|
var hotkeys_shift = {
|
|
|
|
// these can be triggered by shift + key only
|
|
|
|
9: {name: 'shift_tab', message_view_only: false}, // tab
|
2017-01-12 00:17:43 +01:00
|
|
|
32: {name: 'page_up', message_view_only: true}, // space bar
|
2016-06-14 00:08:02 +02:00
|
|
|
};
|
|
|
|
var hotkeys_no_modifiers = {
|
|
|
|
// these can be triggered by key only (without shift)
|
|
|
|
9: {name: 'tab', message_view_only: false}, // tab
|
|
|
|
32: {name: 'page_down', message_view_only: true}, // space bar
|
|
|
|
33: {name: 'page_up', message_view_only: true}, // page up
|
|
|
|
34: {name: 'page_down', message_view_only: true}, // page down
|
|
|
|
35: {name: 'end', message_view_only: true}, // end
|
|
|
|
36: {name: 'home', message_view_only: true}, // home
|
|
|
|
38: {name: 'up_arrow', message_view_only: true}, // up arrow
|
2017-01-12 00:17:43 +01:00
|
|
|
40: {name: 'down_arrow', message_view_only: true}, // down arrow
|
2016-06-14 00:08:02 +02:00
|
|
|
};
|
|
|
|
var hotkeys_shift_insensitive = {
|
|
|
|
// these can be triggered by key or shift + key
|
|
|
|
// Note that codes for letters are still case sensitive!
|
|
|
|
8: {name: 'backspace', message_view_only: true}, // backspace
|
|
|
|
13: {name: 'enter', message_view_only: false}, // enter
|
|
|
|
27: {name: 'escape', message_view_only: false}, // escape
|
|
|
|
47: {name: 'search', message_view_only: false}, // '/'
|
|
|
|
63: {name: 'show_shortcuts', message_view_only: false}, // '?'
|
2016-12-29 04:50:17 +01:00
|
|
|
64: {name: 'compose_reply_with_mention', message_view_only: true}, // '@'
|
2016-06-14 00:08:02 +02:00
|
|
|
65: {name: 'stream_cycle_backward', message_view_only: true}, // 'A'
|
|
|
|
67: {name: 'compose_private_message', message_view_only: true}, // 'C'
|
|
|
|
68: {name: 'stream_cycle_forward', message_view_only: true}, // 'D'
|
|
|
|
74: {name: 'page_down', message_view_only: true}, // 'J'
|
|
|
|
75: {name: 'page_up', message_view_only: true}, // 'K'
|
|
|
|
82: {name: 'respond_to_author', message_view_only: true}, // 'R'
|
|
|
|
83: {name: 'narrow_by_subject', message_view_only: true}, //'S'
|
|
|
|
99: {name: 'compose', message_view_only: true}, // 'c'
|
|
|
|
105: {name: 'message_actions', message_view_only: true}, // 'i'
|
|
|
|
106: {name: 'vim_down', message_view_only: true}, // 'j'
|
|
|
|
107: {name: 'vim_up', message_view_only: true}, // 'k'
|
|
|
|
113: {name: 'query_users', message_view_only: false}, // 'q'
|
|
|
|
114: {name: 'reply_message', message_view_only: true}, // 'r'
|
|
|
|
115: {name: 'narrow_by_recipient', message_view_only: true}, // 's'
|
2016-06-13 22:06:12 +02:00
|
|
|
118: {name: 'narrow_private', message_view_only: true}, // 'v'
|
2017-01-12 00:17:43 +01:00
|
|
|
119: {name: 'query_streams', message_view_only: false}, // 'w'
|
2016-06-14 00:08:02 +02:00
|
|
|
};
|
|
|
|
|
2016-09-28 01:19:20 +02:00
|
|
|
var tab_up_down = (function () {
|
|
|
|
var list = ["#group-pm-list", "#stream_filters", "#global_filters", "#user_presences"];
|
|
|
|
|
|
|
|
return function (e) {
|
|
|
|
var $target = $(e.target);
|
2016-09-28 09:20:50 +02:00
|
|
|
var flag = $target.closest(list.join(", ")).length > 0;
|
2016-09-28 01:19:20 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
flag: flag,
|
|
|
|
next: function () {
|
|
|
|
return $target.closest("li").next().find("a");
|
|
|
|
},
|
|
|
|
prev: function () {
|
|
|
|
return $target.closest("li").prev().find("a");
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-09-28 01:19:20 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
|
2016-06-14 00:08:02 +02:00
|
|
|
function get_hotkey_from_event(e) {
|
2013-06-07 18:37:18 +02:00
|
|
|
|
2013-06-11 04:06:16 +02:00
|
|
|
// We're in the middle of a combo; stop processing because
|
|
|
|
// we want the browser to handle it (to avoid breaking
|
|
|
|
// things like Ctrl-C or Command-C for copy).
|
|
|
|
if (e.metaKey || e.ctrlKey) {
|
2016-06-14 00:08:02 +02:00
|
|
|
return {name: 'ignore', message_view_only: false};
|
2013-06-11 04:06:16 +02:00
|
|
|
}
|
2012-09-21 23:51:31 +02:00
|
|
|
|
2016-06-14 00:08:02 +02:00
|
|
|
if (e.shiftKey && hotkeys_shift[e.which] !== undefined) {
|
|
|
|
return hotkeys_shift[e.which];
|
|
|
|
} else if (!e.shiftKey && hotkeys_no_modifiers[e.which] !== undefined) {
|
|
|
|
return hotkeys_no_modifiers[e.which];
|
|
|
|
} else if (hotkeys_shift_insensitive[e.which] !== undefined) {
|
|
|
|
return hotkeys_shift_insensitive[e.which];
|
2012-12-12 20:34:47 +01:00
|
|
|
}
|
2013-06-11 04:06:16 +02:00
|
|
|
|
2016-06-14 00:08:02 +02:00
|
|
|
return {name: 'ignore', message_view_only: false};
|
2013-06-11 04:06:16 +02:00
|
|
|
}
|
2012-10-23 20:55:24 +02:00
|
|
|
|
2012-11-29 19:55:08 +01:00
|
|
|
// Process a keydown or keypress event.
|
|
|
|
//
|
|
|
|
// Returns true if we handled it, false if the browser should.
|
2012-11-11 22:08:52 +01:00
|
|
|
function process_hotkey(e) {
|
2016-12-02 17:09:31 +01:00
|
|
|
var row;
|
|
|
|
var alert_words_content;
|
|
|
|
var focused_message_edit_content;
|
|
|
|
var focused_message_edit_save;
|
|
|
|
var message_edit_form;
|
2016-06-14 00:08:02 +02:00
|
|
|
var hotkey = get_hotkey_from_event(e);
|
|
|
|
var event_name = hotkey.name;
|
2013-09-06 21:52:12 +02:00
|
|
|
activity.new_user_input = true;
|
2013-09-06 22:04:31 +02:00
|
|
|
|
2016-06-14 00:08:02 +02:00
|
|
|
if (ui.home_tab_obscured() && hotkey.message_view_only) {
|
2012-10-09 20:09:03 +02:00
|
|
|
return false;
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2012-11-30 00:43:41 +01:00
|
|
|
|
2016-09-28 01:19:20 +02:00
|
|
|
var tab_list = tab_up_down(e);
|
|
|
|
if (tab_list.flag) {
|
|
|
|
if (hotkey.name === "up_arrow") {
|
|
|
|
tab_list.prev().focus();
|
|
|
|
return true;
|
|
|
|
} else if (hotkey.name === "down_arrow") {
|
|
|
|
tab_list.next().focus();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 04:06:16 +02:00
|
|
|
if (event_name === 'ignore') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-11 23:06:58 +02:00
|
|
|
if (popovers.actions_popped() && actions_dropdown_hotkeys.indexOf(event_name) !== -1) {
|
|
|
|
popovers.actions_menu_handle_keyboard(event_name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-18 08:16:57 +01:00
|
|
|
// Handle a few keys specially when the send button is focused.
|
|
|
|
if ($('#compose-send-button').is(':focus')) {
|
2013-06-11 04:06:16 +02:00
|
|
|
if (event_name === 'backspace') {
|
2013-02-18 08:16:57 +01:00
|
|
|
// Ignore backspace; don't navigate back a page.
|
|
|
|
return true;
|
2013-06-11 04:06:16 +02:00
|
|
|
} else if (event_name === 'shift_tab') {
|
2013-02-18 08:16:57 +01:00
|
|
|
// Shift-Tab: go back to content textarea and restore
|
|
|
|
// cursor position.
|
|
|
|
ui.restore_compose_cursor();
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-08 17:25:17 +01:00
|
|
|
}
|
|
|
|
|
2013-07-19 23:13:01 +02:00
|
|
|
// In Safari and the desktop app, we can't tab to buttons. Intercept the
|
|
|
|
// tab from the message edit content box to Save and then Cancel.
|
|
|
|
if (event_name === "tab") {
|
2016-06-14 00:08:02 +02:00
|
|
|
alert_words_content = $(".edit-alert-word").filter(":focus");
|
|
|
|
if (alert_words_content.length > 0) {
|
|
|
|
var add_word_li = alert_words_content.closest(".alert-word-item");
|
|
|
|
add_word_li.find(".add-alert-word").focus();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-02 19:25:20 +02:00
|
|
|
focused_message_edit_content = $(".message_edit_content").filter(":focus");
|
|
|
|
if (focused_message_edit_content.length > 0) {
|
|
|
|
message_edit_form = focused_message_edit_content.closest(".message_edit_form");
|
|
|
|
message_edit_form.find(".message_edit_save").focus();
|
2013-07-19 23:13:01 +02:00
|
|
|
return true;
|
2013-08-02 19:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
focused_message_edit_save = $(".message_edit_save").filter(":focus");
|
|
|
|
if (focused_message_edit_save.length > 0) {
|
|
|
|
message_edit_form = focused_message_edit_save.closest(".message_edit_form");
|
|
|
|
message_edit_form.find(".message_edit_cancel").focus();
|
2013-07-19 23:13:01 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-11-21 22:01:23 +01:00
|
|
|
if (event_name === "shift_tab") {
|
|
|
|
// Shift-tabbing from the edit message cancel button takes you to save.
|
|
|
|
if ($(".message_edit_cancel").filter(":focus").length > 0) {
|
|
|
|
$(".message_edit_save").focus();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shift-tabbing from the edit message save button takes you to the content.
|
|
|
|
focused_message_edit_save = $(".message_edit_save").filter(":focus");
|
|
|
|
if (focused_message_edit_save.length > 0) {
|
|
|
|
focused_message_edit_save.closest(".message_edit_form")
|
|
|
|
.find(".message_edit_content").focus();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-07-19 23:13:01 +02:00
|
|
|
|
2016-11-01 22:32:10 +01:00
|
|
|
if (event_name === "escape") {
|
|
|
|
if ($("#overlay").hasClass("show")) {
|
|
|
|
ui.exit_lightbox_photo();
|
|
|
|
return true;
|
2017-01-07 08:43:36 +01:00
|
|
|
} else if ($("#subscription_overlay").is(":visible")) {
|
2016-11-01 22:32:10 +01:00
|
|
|
$("#subscription_overlay").click();
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-29 22:34:23 +02:00
|
|
|
}
|
|
|
|
|
2014-03-12 15:02:14 +01:00
|
|
|
// Process hotkeys specially when in an input, select, textarea, or send button
|
|
|
|
if ($('input:focus,select:focus,textarea:focus,#compose-send-button:focus').length > 0) {
|
2013-06-11 04:06:16 +02:00
|
|
|
if (event_name === 'escape') {
|
2015-10-15 22:34:30 +02:00
|
|
|
// emoji window should trap escape before it is able to close the compose box
|
|
|
|
if ($('.emoji_popover').css('display') === 'inline-block') {
|
|
|
|
popovers.hide_emoji_map_popover();
|
|
|
|
return;
|
|
|
|
}
|
2012-11-29 19:55:08 +01:00
|
|
|
// If one of our typeaheads is open, do nothing so that the Esc
|
|
|
|
// will go to close it
|
|
|
|
if ($("#subject").data().typeahead.shown ||
|
|
|
|
$("#stream").data().typeahead.shown ||
|
2013-01-10 21:17:21 +01:00
|
|
|
$("#private_message_recipient").data().typeahead.shown ||
|
2013-03-11 16:03:47 +01:00
|
|
|
$("#new_message_content").data().typeahead.shown ||
|
|
|
|
$("#search_query").data().typeahead.shown) {
|
|
|
|
// For some reason this code is only needed in Firefox;
|
|
|
|
// in Chrome our typeahead is able to intercept the Esc
|
|
|
|
// event before we even get it.
|
|
|
|
// Regardless, we do nothing in this case.
|
|
|
|
return true;
|
2013-08-01 23:18:42 +02:00
|
|
|
} else if ($(".message_edit_content").filter(":focus").length > 0) {
|
|
|
|
row = $(".message_edit_content").filter(":focus").closest(".message_row");
|
|
|
|
message_edit.end(row);
|
2014-01-14 17:36:52 +01:00
|
|
|
} else if (activity.searching()) {
|
2014-02-14 22:36:20 +01:00
|
|
|
activity.escape_search();
|
2014-01-14 17:36:52 +01:00
|
|
|
return true;
|
2016-06-13 22:06:12 +02:00
|
|
|
} else if (stream_list.searching()) {
|
|
|
|
stream_list.escape_search();
|
|
|
|
return true;
|
2013-03-11 16:03:47 +01:00
|
|
|
} else if (compose.composing()) {
|
2012-11-29 19:55:08 +01:00
|
|
|
// If the user hit the escape key, cancel the current compose
|
|
|
|
compose.cancel();
|
2013-03-11 16:03:47 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// We pressed Esc and something was focused, and the composebox
|
|
|
|
// wasn't open. In that case, we should blur the input.
|
|
|
|
// (this is almost certainly the searchbar)
|
|
|
|
$("input:focus,textarea:focus").blur();
|
|
|
|
return true;
|
2012-11-29 19:55:08 +01:00
|
|
|
}
|
|
|
|
}
|
2013-06-07 18:37:18 +02:00
|
|
|
|
2014-01-14 17:57:34 +01:00
|
|
|
if (event_name === 'enter') {
|
|
|
|
if (activity.searching()) {
|
|
|
|
activity.blur_search();
|
|
|
|
return true;
|
2016-06-13 22:06:12 +02:00
|
|
|
} else if (stream_list.searching()) {
|
|
|
|
stream_list.clear_and_hide_search();
|
|
|
|
return true;
|
2014-01-14 17:57:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 04:06:16 +02:00
|
|
|
if ((event_name === 'up_arrow' || event_name === 'down_arrow')
|
2013-06-07 18:37:18 +02:00
|
|
|
&& compose.composing()
|
2013-06-11 17:30:55 +02:00
|
|
|
&& compose.message_content() === ""
|
2013-07-18 23:11:12 +02:00
|
|
|
&& $('#new_message_content').is(':focus')) {
|
2013-06-07 18:37:18 +02:00
|
|
|
compose.cancel();
|
|
|
|
// don't return, as we still want it to be picked up by the code below
|
|
|
|
} else {
|
|
|
|
// Let the browser handle the key normally.
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-09 19:50:39 +02:00
|
|
|
}
|
|
|
|
|
2013-03-06 23:19:01 +01:00
|
|
|
// If we're on a button or a link and have pressed enter, let the
|
|
|
|
// browser handle the keypress
|
|
|
|
//
|
|
|
|
// This is subtle and here's why: Suppose you have the focus on a
|
|
|
|
// stream name in your left sidebar. j and k will still move your
|
|
|
|
// cursor up and down, but Enter won't reply -- it'll just trigger
|
|
|
|
// the link on the sidebar! So you keep pressing enter over and
|
|
|
|
// over again. Until you click somewhere or press r.
|
2013-06-11 04:06:16 +02:00
|
|
|
if ($('a:focus,button:focus').length > 0 && event_name === 'enter') {
|
2013-03-06 23:19:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-08 00:03:28 +02:00
|
|
|
// Shortcuts that don't require a message
|
2013-06-19 17:10:42 +02:00
|
|
|
switch (event_name) {
|
2013-08-08 00:03:28 +02:00
|
|
|
case 'narrow_private':
|
|
|
|
return do_narrow_action(function (target, opts) {
|
|
|
|
narrow.by('is', 'private', opts);
|
|
|
|
});
|
|
|
|
case 'escape': // Esc: close actions popup, cancel compose, clear a find, or un-narrow
|
2015-10-15 22:34:30 +02:00
|
|
|
if ($('.emoji_popover').css('display') === 'inline-block') {
|
|
|
|
popovers.hide_emoji_map_popover();
|
|
|
|
} else if (popovers.any_active()) {
|
2013-08-08 00:03:28 +02:00
|
|
|
popovers.hide_all();
|
|
|
|
} else if (compose.composing()) {
|
|
|
|
compose.cancel();
|
|
|
|
} else {
|
|
|
|
search.clear_search();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case 'compose': // 'c': compose
|
2013-11-26 21:46:34 +01:00
|
|
|
compose.start('stream', {trigger: "compose_hotkey"});
|
2013-08-08 00:03:28 +02:00
|
|
|
return true;
|
|
|
|
case 'compose_private_message':
|
2013-11-26 21:46:34 +01:00
|
|
|
compose.start('private', {trigger: "compose_hotkey"});
|
2013-08-08 00:03:28 +02:00
|
|
|
return true;
|
2014-02-14 22:49:26 +01:00
|
|
|
case 'query_users':
|
|
|
|
activity.initiate_search();
|
|
|
|
return true;
|
2016-06-13 22:06:12 +02:00
|
|
|
case 'query_streams':
|
|
|
|
stream_list.initiate_search();
|
|
|
|
return true;
|
2013-08-08 00:03:28 +02:00
|
|
|
case 'search':
|
|
|
|
search.initiate_search();
|
|
|
|
return true;
|
|
|
|
case 'show_shortcuts': // Show keyboard shortcuts page
|
|
|
|
$('#keyboard-shortcuts').modal('show');
|
|
|
|
return true;
|
2014-02-14 19:32:40 +01:00
|
|
|
case 'stream_cycle_backward':
|
|
|
|
navigate.cycle_stream('backward');
|
|
|
|
return true;
|
|
|
|
case 'stream_cycle_forward':
|
|
|
|
navigate.cycle_stream('forward');
|
|
|
|
return true;
|
2012-09-21 22:35:32 +02:00
|
|
|
}
|
|
|
|
|
2013-07-24 22:51:13 +02:00
|
|
|
if (current_msg_list.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-08 00:03:28 +02:00
|
|
|
// Navigation shortcuts
|
2013-07-24 22:51:13 +02:00
|
|
|
switch (event_name) {
|
|
|
|
case 'down_arrow':
|
|
|
|
case 'vim_down':
|
2013-08-05 21:52:38 +02:00
|
|
|
navigate.down(true); // with_centering
|
2013-07-24 22:51:13 +02:00
|
|
|
return true;
|
|
|
|
case 'up_arrow':
|
|
|
|
case 'vim_up':
|
|
|
|
navigate.up();
|
|
|
|
return true;
|
|
|
|
case 'home':
|
|
|
|
navigate.to_home();
|
|
|
|
return true;
|
2013-07-24 23:45:19 +02:00
|
|
|
case 'end':
|
|
|
|
navigate.to_end();
|
|
|
|
return true;
|
|
|
|
case 'page_up':
|
|
|
|
navigate.page_up();
|
|
|
|
return true;
|
|
|
|
case 'page_down':
|
|
|
|
navigate.page_down();
|
|
|
|
return true;
|
2013-07-24 22:51:13 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 00:03:28 +02:00
|
|
|
// Shortcuts that operate on a message
|
|
|
|
switch (event_name) {
|
|
|
|
case 'message_actions':
|
2013-11-07 18:12:48 +01:00
|
|
|
return popovers.open_message_menu();
|
2013-08-08 00:03:28 +02:00
|
|
|
case 'narrow_by_recipient':
|
|
|
|
return do_narrow_action(narrow.by_recipient);
|
|
|
|
case 'narrow_by_subject':
|
|
|
|
return do_narrow_action(narrow.by_subject);
|
|
|
|
case 'enter': // Enter: respond to message (unless we need to do something else)
|
2016-06-29 00:27:50 +02:00
|
|
|
compose.respond_to_message({trigger: 'hotkey enter'});
|
2013-08-08 00:03:28 +02:00
|
|
|
return true;
|
|
|
|
case 'reply_message': // 'r': respond to message
|
2016-06-29 00:27:50 +02:00
|
|
|
compose.respond_to_message({trigger: 'hotkey'});
|
2013-08-08 00:03:28 +02:00
|
|
|
return true;
|
|
|
|
case 'respond_to_author': // 'R': respond to author
|
2016-06-29 00:27:50 +02:00
|
|
|
compose.respond_to_message({reply_type: "personal", trigger: 'hotkey pm'});
|
2013-08-08 00:03:28 +02:00
|
|
|
return true;
|
2016-12-29 04:50:17 +01:00
|
|
|
case 'compose_reply_with_mention': // '@': respond to message with mention to author
|
|
|
|
compose.respond_to_message({trigger: 'hotkey'});
|
|
|
|
var message = current_msg_list.selected_message();
|
|
|
|
$("#new_message_content").val('@**' + message.sender_full_name + '** ');
|
|
|
|
return true;
|
2013-08-08 00:03:28 +02:00
|
|
|
}
|
|
|
|
|
2012-09-21 22:35:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-03 17:04:43 +02:00
|
|
|
/* We register both a keydown and a keypress function because
|
|
|
|
we want to intercept pgup/pgdn, escape, etc, and process them
|
|
|
|
as they happen on the keyboard. However, if we processed
|
|
|
|
letters/numbers in keydown, we wouldn't know what the case of
|
|
|
|
the letters were.
|
|
|
|
|
|
|
|
We want case-sensitive hotkeys (such as in the case of r vs R)
|
|
|
|
so we bail in .keydown if the event is a letter or number and
|
|
|
|
instead just let keypress go for it. */
|
|
|
|
|
2012-11-11 22:48:51 +01:00
|
|
|
$(document).keydown(function (e) {
|
2012-10-31 23:10:15 +01:00
|
|
|
// Restrict to non-alphanumeric keys
|
2016-09-22 02:05:24 +02:00
|
|
|
// check if 27 (esc) because it doesn't register under .keypress()
|
2016-12-05 03:39:24 +01:00
|
|
|
if (e.which < 48 || e.which > 90 || e.which === 27) {
|
2013-08-01 17:47:48 +02:00
|
|
|
if (process_hotkey(e)) {
|
2012-11-29 19:55:08 +01:00
|
|
|
e.preventDefault();
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2012-11-29 19:55:08 +01:00
|
|
|
}
|
2014-03-13 19:03:31 +01:00
|
|
|
resize.resize_bottom_whitespace();
|
2012-10-03 17:04:43 +02:00
|
|
|
});
|
|
|
|
|
2012-11-11 22:48:51 +01:00
|
|
|
$(document).keypress(function (e) {
|
2012-10-03 17:04:43 +02:00
|
|
|
// What exactly triggers .keypress may vary by browser.
|
|
|
|
// Welcome to compatability hell.
|
2012-10-15 16:45:31 +02:00
|
|
|
//
|
|
|
|
// In particular, when you press tab in Firefox, it fires a
|
|
|
|
// keypress event with keycode 0 after processing the original
|
|
|
|
// event.
|
2012-11-29 19:55:08 +01:00
|
|
|
if (e.which !== 0 && e.charCode !== 0) {
|
2013-08-01 17:47:48 +02:00
|
|
|
if (process_hotkey(e)) {
|
2012-11-29 19:55:08 +01:00
|
|
|
e.preventDefault();
|
2013-08-01 17:47:48 +02:00
|
|
|
}
|
2012-11-29 19:55:08 +01:00
|
|
|
}
|
2012-09-21 22:35:32 +02:00
|
|
|
});
|
2012-10-18 19:58:10 +02:00
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = hotkeys;
|
|
|
|
}
|