From 08f83a7fd0618065e2cbae443674e44fac8102e2 Mon Sep 17 00:00:00 2001 From: Acho Arnold Date: Thu, 17 Apr 2014 16:44:08 +0100 Subject: Bug 984980 - add framework for keyboard shortcuts, and key to switch between preview and edit mode. Patch by , r=gerv, a=justdave. --- js/field.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'js') diff --git a/js/field.js b/js/field.js index 892c8669f..b7e90ce1c 100644 --- a/js/field.js +++ b/js/field.js @@ -1083,3 +1083,33 @@ function updateRemainingTime() { // if the remaining time is changed manually, update bz_remaining_time bz_remaining_time = document.changeform.remaining_time.value; } + +var keys = []; +function keys_pressed(e, bug_id) { + // Store an entry for every key pressed + keys[e.keyCode] = true; + + // (Ctrl XOR cmd) + Shift + P + if ((!keys[17] != !keys[224]) && keys[16] && keys[80]) { + // Check if we are already in preview mode + if (YAHOO.util.Dom.hasClass('comment_preview_tab', 'active_comment_tab')){ + show_comment_edit(); + document.getElementById('comment').focus(); + YAHOO.util.Event.preventDefault(e); + } + + else { + // Ensure that we switch to preview mode only if the textarea is in focus + var comment = document.getElementById('comment'); + if (document.activeElement == comment) { + show_comment_preview(bug_id); + YAHOO.util.Event.preventDefault(e); + } + } + } +} + +function keys_released(e) { + // Mark keys that were released + keys[e.keyCode] = false; +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b