+/**
+* Copyright (c) 2012 Erik Sargent <esthepiking at gmail dot com>
+* This file is licensed under the Affero General Public License version 3 or
+* later.
+*/
+
/*****************************
* Keyboard shortcuts for Files app
* ctrl/cmd+n: new folder
*****************************/
var Files = Files || {};
+(function(Files){
var keys = [];
var keyCodes = {
shift: 16,
downArrow: 40,
upArrow: 38,
enter: 13,
- backspace: 8,
del: 46
};
$("#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;
+ select = index + 1;
$(this).removeClass("mouseOver");
}
});
var select = -1;
$("#fileList tr").each(function(index){
if($(this).hasClass("mouseOver")){
- select = index-1;
+ select = index - 1;
$(this).removeClass("mouseOver");
}
});
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)){ //new file/folder prevent browser from responding
- preventDefault = true;
- }
- 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(
+ $.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;//new file/folder prevent browser from responding
}
- 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(
+ !$("#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){//prevent default when renaming file/folder
if($(this).hasClass("mouseOver")){
preventDefault = true;
}
$(document).keyup(function(event){
// do your event.keyCode checks in here
-
- 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 || $.inArray(keyCodes.ctrl, keys) !== -1)){
- if($.inArray(keyCodes.shift, keys) !== -1){ //16=shift, New File
+ 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
newFile();
}
else{ //New Folder
else if(!$("#new").hasClass("active") && $.inArray(keyCodes.enter, keys) !== -1){//open file
enter();
}
- else if(!$("#new").hasClass("active") && ($.inArray(keyCodes.backspace, keys) !== -1 || $.inArray(keyCodes.del, keys) !== -1)) {//delete file
+ else if(!$("#new").hasClass("active") && $.inArray(keyCodes.del, keys) !== -1) {//delete file
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){//rename file
+ 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
+ ){//rename file
rename();
}
removeA(keys, event.keyCode);
});
-};
\ No newline at end of file
+};
+})(Files);
\ No newline at end of file