mirror of https://github.com/zulip/zulip.git
Move hotkeys into a new file
(imported from commit a589cd4623c4707122d5d5936aa0bc555c38557a)
This commit is contained in:
parent
d3bb97a21f
commit
a53cbc9f36
|
@ -29,6 +29,7 @@
|
|||
<script type="text/javascript" src="/static/third/jquery/jquery.form.js"></script>
|
||||
<script type="text/javascript" src="/static/third/ich/ICanHaz.min.js"></script>
|
||||
<script type="text/javascript" src="/static/js/zephyr.js"></script>
|
||||
<script type="text/javascript" src="/static/js/hotkey.js"></script>
|
||||
|
||||
{% if debug %}
|
||||
<script type="text/javascript" src="/static/js/debug.js"></script>
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
function process_hotkey(code) {
|
||||
var next_zephyr;
|
||||
|
||||
switch (code) {
|
||||
case 40: // down arrow
|
||||
case 38: // up arrow
|
||||
if (code === 40) {
|
||||
next_zephyr = get_next_visible(selected_zephyr);
|
||||
} else {
|
||||
next_zephyr = get_prev_visible(selected_zephyr);
|
||||
}
|
||||
if (next_zephyr.length !== 0) {
|
||||
select_zephyr(next_zephyr, true);
|
||||
}
|
||||
if ((next_zephyr.length === 0) && (code === 40)) {
|
||||
// At the last zephyr, scroll to the bottom so we have
|
||||
// lots of nice whitespace for new zephyrs coming in.
|
||||
$("#main_div").scrollTop($("#main_div").prop("scrollHeight"));
|
||||
}
|
||||
return process_hotkey;
|
||||
|
||||
case 36: // Home: Go to first message
|
||||
case 38: // End: Go to last message
|
||||
if (code === 38) {
|
||||
next_zephyr = get_last_visible();
|
||||
} else {
|
||||
next_zephyr = get_first_visible();
|
||||
}
|
||||
if (next_zephyr.length !== 0) {
|
||||
select_zephyr(next_zephyr, true);
|
||||
}
|
||||
if ((next_zephyr.length === 0) && (code === 38)) {
|
||||
// At the last zephyr, scroll to the bottom so we have
|
||||
// lots of nice whitespace for new zephyrs coming in.
|
||||
$("#main_div").scrollTop($("#main_div").prop("scrollHeight"));
|
||||
}
|
||||
return process_hotkey;
|
||||
|
||||
case 27: // Esc: hide compose pane
|
||||
hide_compose();
|
||||
return process_hotkey;
|
||||
|
||||
case 82: // 'r': respond to zephyr
|
||||
respond_to_zephyr();
|
||||
return process_key_in_input;
|
||||
|
||||
case 71: // 'g': start of "go to" command
|
||||
return process_goto_hotkey;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function process_goto_hotkey(code) {
|
||||
var zephyr = zephyr_dict[selected_zephyr_id];
|
||||
switch (code) {
|
||||
case 67: // 'c': narrow by recipient
|
||||
narrow_by_recipient(zephyr);
|
||||
break;
|
||||
|
||||
case 73: // 'i': narrow by instance
|
||||
if (zephyr.type === 'class') {
|
||||
narrow_instance();
|
||||
}
|
||||
break;
|
||||
|
||||
case 80: // 'p': narrow to personals
|
||||
narrow_all_personals();
|
||||
break;
|
||||
|
||||
case 65: // 'a': un-narrow
|
||||
show_all_messages();
|
||||
break;
|
||||
|
||||
case 27: // Esc: hide compose pane
|
||||
hide_compose();
|
||||
break;
|
||||
}
|
||||
|
||||
/* Always return to the initial hotkey mode, even
|
||||
with an unrecognized "go to" command. */
|
||||
return process_hotkey;
|
||||
}
|
||||
|
||||
function process_key_in_input(code) {
|
||||
if (code === 27) {
|
||||
// User hit Escape key
|
||||
hide_compose();
|
||||
return process_hotkey;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* The current handler function for keydown events.
|
||||
It should return a new handler, or 'false' to
|
||||
decline to handle the event. */
|
||||
var keydown_handler = process_hotkey;
|
||||
|
||||
$(document).keydown(function (event) {
|
||||
var result = keydown_handler(event.keyCode);
|
||||
if (typeof result === 'function') {
|
||||
keydown_handler = result;
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
|
@ -409,127 +409,6 @@ function show_email() {
|
|||
selected_zephyr.find('.zephyr_sender_email').removeClass('invisible');
|
||||
}
|
||||
|
||||
|
||||
function process_hotkey(code) {
|
||||
var next_zephyr;
|
||||
|
||||
switch (code) {
|
||||
case 40: // down arrow
|
||||
case 38: // up arrow
|
||||
if (code === 40) {
|
||||
next_zephyr = get_next_visible(selected_zephyr);
|
||||
} else {
|
||||
next_zephyr = get_prev_visible(selected_zephyr);
|
||||
}
|
||||
if (next_zephyr.length !== 0) {
|
||||
select_zephyr(next_zephyr, true);
|
||||
}
|
||||
if ((next_zephyr.length === 0) && (code === 40)) {
|
||||
// At the last zephyr, scroll to the bottom so we have
|
||||
// lots of nice whitespace for new zephyrs coming in.
|
||||
$("#main_div").scrollTop($("#main_div").prop("scrollHeight"));
|
||||
}
|
||||
return process_hotkey;
|
||||
|
||||
case 36: // Home: Go to first message
|
||||
case 38: // End: Go to last message
|
||||
if (code === 38) {
|
||||
next_zephyr = get_last_visible();
|
||||
} else {
|
||||
next_zephyr = get_first_visible();
|
||||
}
|
||||
if (next_zephyr.length !== 0) {
|
||||
select_zephyr(next_zephyr, true);
|
||||
}
|
||||
if ((next_zephyr.length === 0) && (code === 38)) {
|
||||
// At the last zephyr, scroll to the bottom so we have
|
||||
// lots of nice whitespace for new zephyrs coming in.
|
||||
$("#main_div").scrollTop($("#main_div").prop("scrollHeight"));
|
||||
}
|
||||
return process_hotkey;
|
||||
case 27: // Esc: hide compose pane
|
||||
hide_compose();
|
||||
return process_hotkey;
|
||||
|
||||
case 82: // 'r': respond to zephyr
|
||||
respond_to_zephyr();
|
||||
return process_key_in_input;
|
||||
|
||||
case 71: // 'g': start of "go to" command
|
||||
return process_goto_hotkey;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function narrow_by_recipient(zephyr) {
|
||||
if (zephyr === undefined) {
|
||||
zephyr = zephyr_dict[selected_zephyr_id];
|
||||
}
|
||||
|
||||
// called when the narrow-class keycode is typed
|
||||
if (zephyr.type === 'personal') {
|
||||
narrow_personals();
|
||||
} else if (zephyr.type === 'huddle') {
|
||||
narrow_huddle();
|
||||
} else if (zephyr.type === 'class') {
|
||||
narrow_class();
|
||||
}
|
||||
}
|
||||
|
||||
function process_goto_hotkey(code) {
|
||||
var zephyr = zephyr_dict[selected_zephyr_id];
|
||||
switch (code) {
|
||||
case 67: // 'c': narrow by recipient
|
||||
narrow_by_recipient(zephyr);
|
||||
break;
|
||||
|
||||
case 73: // 'i': narrow by instance
|
||||
if (zephyr.type === 'class') {
|
||||
narrow_instance();
|
||||
}
|
||||
break;
|
||||
|
||||
case 80: // 'p': narrow to personals
|
||||
narrow_all_personals();
|
||||
break;
|
||||
|
||||
case 65: // 'a': un-narrow
|
||||
show_all_messages();
|
||||
break;
|
||||
|
||||
case 27: // Esc: hide compose pane
|
||||
hide_compose();
|
||||
break;
|
||||
}
|
||||
|
||||
/* Always return to the initial hotkey mode, even
|
||||
with an unrecognized "go to" command. */
|
||||
return process_hotkey;
|
||||
}
|
||||
|
||||
function process_key_in_input(code) {
|
||||
if (code === 27) {
|
||||
// User hit Escape key
|
||||
hide_compose();
|
||||
return process_hotkey;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* The current handler function for keydown events.
|
||||
It should return a new handler, or 'false' to
|
||||
decline to handle the event. */
|
||||
var keydown_handler = process_hotkey;
|
||||
|
||||
$(document).keydown(function (event) {
|
||||
var result = keydown_handler(event.keyCode);
|
||||
if (typeof result === 'function') {
|
||||
keydown_handler = result;
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
// NB: This just binds to current elements, and won't bind to elements
|
||||
// created after ready() is called.
|
||||
|
||||
|
@ -650,6 +529,21 @@ function narrow_instance() {
|
|||
});
|
||||
}
|
||||
|
||||
function narrow_by_recipient(zephyr) {
|
||||
if (zephyr === undefined) {
|
||||
zephyr = zephyr_dict[selected_zephyr_id];
|
||||
}
|
||||
|
||||
// called when the narrow-class keycode is typed
|
||||
if (zephyr.type === 'personal') {
|
||||
narrow_personals();
|
||||
} else if (zephyr.type === 'huddle') {
|
||||
narrow_huddle();
|
||||
} else if (zephyr.type === 'class') {
|
||||
narrow_class();
|
||||
}
|
||||
}
|
||||
|
||||
function show_all_messages() {
|
||||
if (!narrowed) {
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue