From 952a511c06c57de75a851960d507c69cb6f141b5 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 7 Apr 2015 13:31:23 +0800 Subject: Bug 1149438: keyboard shortcut (hotkey) for "Edit" button --- .../BugModal/template/en/default/bug_modal/header.html.tmpl | 1 + extensions/BugModal/web/bug_modal.js | 12 ++++++++++++ js/jquery/plugins/hotkeys/hotkeys-min.js | 2 ++ 3 files changed, 15 insertions(+) create mode 100644 js/jquery/plugins/hotkeys/hotkeys-min.js diff --git a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl index 70c98641f..f362da540 100644 --- a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl @@ -56,6 +56,7 @@ ); jquery.push( "datetimepicker", + "hotkeys", ); style_urls.push( "extensions/BugModal/web/bug_modal.css", diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js index f39e48575..1eb90f2df 100644 --- a/extensions/BugModal/web/bug_modal.js +++ b/extensions/BugModal/web/bug_modal.js @@ -713,6 +713,18 @@ $(function() { } }) .change(); + + // hotkeys + $('body').hotkey('e', function() { + if ($('#cancel-btn:visible').length == 0) { + $('#mode-btn').click(); + } + } ); + $('body').hotkey('escape', function() { + if ($('#cancel-btn:visible').length != 0) { + $('#cancel-btn').click(); + } + } ); }); function confirmUnsafeURL(url) { diff --git a/js/jquery/plugins/hotkeys/hotkeys-min.js b/js/jquery/plugins/hotkeys/hotkeys-min.js new file mode 100644 index 000000000..f6ecc01db --- /dev/null +++ b/js/jquery/plugins/hotkeys/hotkeys-min.js @@ -0,0 +1,2 @@ +// https://github.com/adrianmalik/jquery-hotkeys +jQuery.fn.hotkey=function(keys,func){var element=$(this[0]);var specialKeyCodes={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"break",20:"caps lock",27:"escape",33:"page up",34:"page down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",96:"numpad 0",97:"numpad 1",98:"numpad 2",99:"numpad 3",100:"numpad 4",101:"numpad 5",102:"numpad 6",103:"numpad 7",104:"numpad 8",105:"numpad 9",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12"};keys=$.trim(keys);if(typeof keys!=="string"){throw"Keys parameter must be a string for jquery hotkeys"}if(keys===""){throw"Keys parameter cannot be empty"}if(keys.indexOf("+")==-1){var arr=[];arr.push(keys);keys=arr}else{keys=keys.split("+")}var keysCount=keys.length;if(keysCount>2){throw"jQuery hotkey supports only maximal combination with two keys like ctrl+c"}var validateFirstKey=false;element.keydown(function(event){var keyCode=event.keyCode;var ch="";if(typeof specialKeyCodes[keyCode]!=="undefined"){ch=specialKeyCodes[keyCode]}else{ch=String.fromCharCode(keyCode).toLowerCase()}if(keysCount===1&&ch===keys[0]){func()}if(keysCount===2&&ch===keys[0]){validateFirstKey=true}}).keyup(function(event){if(validateFirstKey){var keyCode=event.keyCode;var ch="";if(typeof specialKeyCodes[keyCode]!=="undefined"){ch=specialKeyCodes[keyCode]}else{ch=String.fromCharCode(keyCode).toLowerCase()}if(ch===keys[1]){func()}}})}; -- cgit v1.2.3-24-g4f1b