diff options
author | Erik Sargent <esthepiking@gmail.com> | 2012-11-29 10:18:34 -0700 |
---|---|---|
committer | Erik Sargent <esthepiking@gmail.com> | 2012-11-29 10:18:34 -0700 |
commit | fd4aecf525810bb2d74de59070734eba465f311f (patch) | |
tree | c4253871da0953088ae7c1a19acb589b64af6b39 /apps/files/js/keyboardshortcuts.js | |
parent | dafe028c111a66b622eb920a7ed5f5e3e3d5abdf (diff) | |
download | nextcloud-server-fd4aecf525810bb2d74de59070734eba465f311f.tar.gz nextcloud-server-fd4aecf525810bb2d74de59070734eba465f311f.zip |
cleanup
Diffstat (limited to 'apps/files/js/keyboardshortcuts.js')
-rw-r--r-- | apps/files/js/keyboardshortcuts.js | 212 |
1 files changed, 123 insertions, 89 deletions
diff --git a/apps/files/js/keyboardshortcuts.js b/apps/files/js/keyboardshortcuts.js index c77e2d611cb..8ba32400079 100644 --- a/apps/files/js/keyboardshortcuts.js +++ b/apps/files/js/keyboardshortcuts.js @@ -1,6 +1,33 @@ -// your file +/***************************** +* Keyboard shortcuts for Files app +* ctrl/cmd+n: new folder +* ctrl/cmd+shift+n: new file +* esc (while new file context menu is open): close menu +* up/down: select file/folder +* enter: open file/folder +* delete/backspace: delete file/folder +* ctrl/cmd+shift+r: rename file/folder +*****************************/ var Files = Files || {}; +var keys = []; +var keyCodes = { + shift: 16, + n: 78, + r: 82, + cmdFirefox: 224, + cmdOpera: 17, + leftCmdWebKit: 91, + rightCmdWebKit: 93, + ctrl: 16, + esc: 27, + downArrow: 40, + upArrow: 38, + enter: 13, + backspace: 8, + del: 46 +}; + function removeA(arr) { var what, a = arguments, L = a.length, ax; while (L > 1 && arr.length) { @@ -12,42 +39,107 @@ function removeA(arr) { return arr; } -Files.bindKeyboardShortcuts = function (document, $) { - var keys = []; - var keyCodes = { - shift: 16, - n: 78, - r: 82, - cmdFirefox: 224, - cmdOpera: 17, - leftCmdWebKit: 91, - rightCmdWebKit: 93, - ctrl: 16, - esc: 27, - downArrow: 40, - upArrow: 38, - enter: 13, - backspace: 8, - delete: 46 - }; +function newFile(){ + $("#new").addClass("active"); + $(".popup.popupTop").toggle(true); + $('#new li[data-type="file"]').trigger('click'); + console.log("new file"); + removeA(keys, keyCodes.n); +} +function newFolder(){ + $("#new").addClass("active"); + $(".popup.popupTop").toggle(true); + $('#new li[data-type="folder"]').trigger('click'); + console.log("new folder"); + removeA(keys, keyCodes.n); +} +function esc(){ + $("#controls").trigger('click'); + console.log("close"); +} +function down(){ + 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"); + } + }); + } +} +function up(){ + 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"); + } + }); + } +} +function enter(){ + $("#fileList tr").each(function(index){ + if($(this).hasClass("mouseOver")){ + $(this).removeClass("mouseOver"); + $(this).find("span.nametext").trigger('click'); + } + }); +} +function del(){ + $("#fileList tr").each(function(index){ + if($(this).hasClass("mouseOver")){ + $(this).removeClass("mouseOver"); + $(this).find("a.action.delete").trigger('click'); + } + }); +} +function rename(){ + $("#fileList tr").each(function(index){ + if($(this).hasClass("mouseOver")){ + $(this).removeClass("mouseOver"); + $(this).find("a[data-action='Rename']").trigger('click'); + } + }); +} +Files.bindKeyboardShortcuts = function (document, $) { $(document).keydown(function(event){//check for modifier keys var preventDefault = false; 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 || $.inArray(keyCodes.ctrl, 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)){ //new file/folder prevent browser from responding preventDefault = true; } - if($.inArray(keyCodes.backspace, keys) !== -1 && !$("#new").hasClass("active")) { + if($.inArray(keyCodes.backspace, keys) !== -1 && !$("#new").hasClass("active")) { //prevent default when deleting a file/folder $("#fileList tr").each(function(index){ if($(this).hasClass("mouseOver")){ preventDefault = true; } }); } - if(!$("#new").hasClass("active") && $.inArray(keyCodes.r, 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) && $.inArray(keyCodes.shift, keys) !== -1){ + if(!$("#new").hasClass("active") && $.inArray(keyCodes.r, 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) && $.inArray(keyCodes.shift, keys) !== -1){//prevent default when renaming file/folder $("#fileList tr").each(function(index){ if($(this).hasClass("mouseOver")){ preventDefault = true; @@ -68,92 +160,34 @@ Files.bindKeyboardShortcuts = function (document, $) { 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"); - removeA(keys, keyCodes.n); + newFile(); } else{ //New Folder - $("#new").addClass("active"); - $(".popup.popupTop").toggle(true); - $('#new li[data-type="folder"]').trigger('click'); - console.log("new folder"); - removeA(keys, keyCodes.n); + newFolder(); } } else if($("#new").hasClass("active") && $.inArray(keyCodes.esc, keys) !== -1){ - $("#controls").trigger('click'); - console.log("close"); + esc(); } else if($.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"); - } - }); - } + down(); } else if($.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"); - } - }); - } + up(); } else if(!$("#new").hasClass("active") && $.inArray(keyCodes.enter, keys) !== -1){ - $("#fileList tr").each(function(index){ - if($(this).hasClass("mouseOver")){ - $(this).removeClass("mouseOver"); - $(this).find("span.nametext").trigger('click'); - } - }); + enter(); } - else if(!$("#new").hasClass("active") && ($.inArray(keyCodes.backspace, keys) !== -1 || $.inArray(keyCodes.delete, keys) !== -1)) { - $("#fileList tr").each(function(index){ - if($(this).hasClass("mouseOver")){ - $(this).removeClass("mouseOver"); - $(this).find("a.action.delete").trigger('click'); - } - }); + else if(!$("#new").hasClass("active") && ($.inArray(keyCodes.backspace, keys) !== -1 || $.inArray(keyCodes.del, keys) !== -1)) { + del(); } else if(!$("#new").hasClass("active") && $.inArray(keyCodes.r, 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) && $.inArray(keyCodes.shift, keys) !== -1){ - $("#fileList tr").each(function(index){ - if($(this).hasClass("mouseOver")){ - $(this).removeClass("mouseOver"); - $(this).find("a[data-action='Rename']").trigger('click'); - } - }); + rename(); } removeA(keys, event.keyCode); |