This commit is contained in:
Erik Sargent 2012-11-28 21:00:11 -07:00
parent a73a263543
commit dafe028c11
1 changed files with 44 additions and 6 deletions

View File

@ -17,6 +17,7 @@ Files.bindKeyboardShortcuts = function (document, $) {
var keyCodes = { var keyCodes = {
shift: 16, shift: 16,
n: 78, n: 78,
r: 82,
cmdFirefox: 224, cmdFirefox: 224,
cmdOpera: 17, cmdOpera: 17,
leftCmdWebKit: 91, leftCmdWebKit: 91,
@ -25,15 +26,35 @@ Files.bindKeyboardShortcuts = function (document, $) {
esc: 27, esc: 27,
downArrow: 40, downArrow: 40,
upArrow: 38, upArrow: 38,
enter: 13 enter: 13,
backspace: 8,
delete: 46
}; };
$(document).keydown(function(event){//check for modifier keys $(document).keydown(function(event){//check for modifier keys
var preventDefault = false;
if($.inArray(event.keyCode, keys) === -1) if($.inArray(event.keyCode, keys) === -1)
keys.push(event.keyCode); keys.push(event.keyCode);
console.log(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)){
preventDefault = true;
}
if($.inArray(keyCodes.backspace, keys) !== -1 && !$("#new").hasClass("active")) {
$("#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){
$("#fileList tr").each(function(index){
if($(this).hasClass("mouseOver")){
preventDefault = true;
}
});
}
if(preventDefault){
event.preventDefault(); //Prevent web browser from responding event.preventDefault(); //Prevent web browser from responding
event.stopPropagation(); event.stopPropagation();
return false; return false;
@ -62,12 +83,12 @@ Files.bindKeyboardShortcuts = function (document, $) {
} }
} }
if($("#new").hasClass("active") && $.inArray(keyCodes.esc, keys) !== -1){ else if($("#new").hasClass("active") && $.inArray(keyCodes.esc, keys) !== -1){
$("#controls").trigger('click'); $("#controls").trigger('click');
console.log("close"); console.log("close");
} }
if(!$("#new").hasClass("active") && $.inArray(keyCodes.downArrow, keys) !== -1){ else if($.inArray(keyCodes.downArrow, keys) !== -1){
var select = -1; var select = -1;
$("#fileList tr").each(function(index){ $("#fileList tr").each(function(index){
if($(this).hasClass("mouseOver")){ if($(this).hasClass("mouseOver")){
@ -88,7 +109,7 @@ Files.bindKeyboardShortcuts = function (document, $) {
} }
} }
if(!$("#new").hasClass("active") && $.inArray(keyCodes.upArrow, keys) !== -1){ else if($.inArray(keyCodes.upArrow, keys) !== -1){
var select = -1; var select = -1;
$("#fileList tr").each(function(index){ $("#fileList tr").each(function(index){
if($(this).hasClass("mouseOver")){ if($(this).hasClass("mouseOver")){
@ -109,11 +130,28 @@ Files.bindKeyboardShortcuts = function (document, $) {
} }
} }
if($.inArray(keyCodes.enter, keys) !== -1){ else if(!$("#new").hasClass("active") && $.inArray(keyCodes.enter, keys) !== -1){
$("#fileList tr").each(function(index){ $("#fileList tr").each(function(index){
if($(this).hasClass("mouseOver")){ if($(this).hasClass("mouseOver")){
$(this).removeClass("mouseOver"); $(this).removeClass("mouseOver");
$(this).find("span:first").trigger('click'); $(this).find("span.nametext").trigger('click');
}
});
}
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.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');
} }
}); });
} }