diff options
author | Erik Sargent <esthepiking@gmail.com> | 2012-11-28 17:32:05 -0700 |
---|---|---|
committer | Erik Sargent <esthepiking@gmail.com> | 2012-11-28 17:32:05 -0700 |
commit | 8802dac02a01a7daeadccac8a331a5b5c2badb2a (patch) | |
tree | 6662f4fdef05c33b229f8e2d6b46b2f094f9d8f0 /apps | |
parent | 8722d3751c8f7ea29746dd0bab663b5400d268a1 (diff) | |
download | nextcloud-server-8802dac02a01a7daeadccac8a331a5b5c2badb2a.tar.gz nextcloud-server-8802dac02a01a7daeadccac8a331a5b5c2badb2a.zip |
Arrow key navigation
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/js/keyboardshortcuts.js | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/apps/files/js/keyboardshortcuts.js b/apps/files/js/keyboardshortcuts.js index 13777fd76b6..8a99bb52691 100644 --- a/apps/files/js/keyboardshortcuts.js +++ b/apps/files/js/keyboardshortcuts.js @@ -5,32 +5,37 @@ function removeA(arr) { var what, a = arguments, L = a.length, ax; while (L > 1 && arr.length) { what = a[--L]; - while ((ax= arr.indexOf(what)) !== -1) { + while ((ax = arr.indexOf(what)) !== -1) { arr.splice(ax, 1); } } return arr; } -Files.bindKeyboardShortcuts = function (document, $){ +Files.bindKeyboardShortcuts = function (document, $) { var keys = []; - keyCodes = { + var keyCodes = { shift: 16, n: 78, cmdFirefox: 224, cmdOpera: 17, leftCmdWebKit: 91, rightCmdWebKit: 93, - esc: 27 + ctrl: 16, + esc: 27, + downArrow: 40, + upArrow: 38 }; $(document).keydown(function(event){//check for modifier keys - if($.inArray(event.keyCode, keys) == -1) + if($.inArray(event.keyCode, keys) === -1) keys.push(event.keyCode); console.log(event.keyCode); - if($.inArray(keyCodes.n, keys) !== -1 && ($.inArray(keyCodes.cmdFirefox, keys) !== -1 || $.inArray(keyCodes.cmdOpera, keys) !== -1 || $.inArray(keyCodes.leftCmdWebKit, keys) !== -1 || $.inArray(keyCodes.rightCmdWebKit, keys) !== -1)){ + if($.inArray(keyCodes.n, keys) !== -1 && ($.inArray(keyCodes.cmdFirefox, keys) !== -1 || $.inArray(keyCodes.cmdOpera, keys) !== -1 || $.inArray(keyCodes.leftCmdWebKit, keys) !== -1 || $.inArray(keyCodes.rightCmdWebKit, keys) !== -1 || $.inArray(keyCodes.ctrl, keys) !== -1)){ event.preventDefault(); //Prevent web browser from responding + event.stopPropagation(); + return false; } }); @@ -39,13 +44,12 @@ Files.bindKeyboardShortcuts = function (document, $){ console.log(JSON.stringify(keys)); - if($.inArray(keyCodes.n, keys) !== -1 && ($.inArray(keyCodes.cmdFirefox, keys) !== -1 || $.inArray(keyCodes.cmdOpera, keys) !== -1 || $.inArray(keyCodes.leftCmdWebKit, keys) !== -1 || $.inArray(keyCodes.rightCmdWebKit, keys) !== -1)){ + if($.inArray(keyCodes.n, keys) !== -1 && ($.inArray(keyCodes.cmdFirefox, keys) !== -1 || $.inArray(keyCodes.cmdOpera, keys) !== -1 || $.inArray(keyCodes.leftCmdWebKit, keys) !== -1 || $.inArray(keyCodes.rightCmdWebKit, keys) !== -1 || $.inArray(keyCodes.ctrl, keys) !== -1)){ if($.inArray(keyCodes.shift, keys) !== -1){ //16=shift, New File $("#new").addClass("active"); $(".popup.popupTop").toggle(true); $('#new li[data-type="file"]').trigger('click'); console.log("new file"); -/* keys.remove($.inArray(keyCodes.n, keys)); */ removeA(keys, keyCodes.n); } else{ //New Folder @@ -53,16 +57,57 @@ Files.bindKeyboardShortcuts = function (document, $){ $(".popup.popupTop").toggle(true); $('#new li[data-type="folder"]').trigger('click'); console.log("new folder"); -/* keys.remove($.inArray(keyCodes.n, keys)); */ removeA(keys, keyCodes.n); } } + if($("#new").hasClass("active") && $.inArray(keyCodes.esc, keys) !== -1){ $("#controls").trigger('click'); console.log("close"); } -/* keys.remove($.inArray(event.keyCode, keys)); */ + if(!$("#new").hasClass("active") && $.inArray(keyCodes.downArrow, keys) !== -1){ + var select = -1; + $("#fileList tr").each(function(index){ + if($(this).hasClass("mouseOver")){ + select = index+1; + $(this).removeClass("mouseOver"); + } + }); + + if(select === -1){ + $("#fileList tr:first").addClass("mouseOver"); + } + else{ + $("#fileList tr").each(function(index){ + if(index === select){ + $(this).addClass("mouseOver"); + } + }); + } + } + + if(!$("#new").hasClass("active") && $.inArray(keyCodes.upArrow, keys) !== -1){ + var select = -1; + $("#fileList tr").each(function(index){ + if($(this).hasClass("mouseOver")){ + select = index-1; + $(this).removeClass("mouseOver"); + } + }); + + if(select === -1){ + $("#fileList tr:last").addClass("mouseOver"); + } + else{ + $("#fileList tr").each(function(index){ + if(index === select){ + $(this).addClass("mouseOver"); + } + }); + } + } + removeA(keys, event.keyCode); }); };
\ No newline at end of file |