Cleanup
This commit is contained in:
parent
b6e3460871
commit
6060d063a9
1 changed files with 51 additions and 26 deletions
|
@ -1,3 +1,9 @@
|
|||
/**
|
||||
* 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
|
||||
|
@ -10,6 +16,7 @@
|
|||
*****************************/
|
||||
var Files = Files || {};
|
||||
|
||||
(function(Files){
|
||||
var keys = [];
|
||||
var keyCodes = {
|
||||
shift: 16,
|
||||
|
@ -24,7 +31,6 @@ var keyCodes = {
|
|||
downArrow: 40,
|
||||
upArrow: 38,
|
||||
enter: 13,
|
||||
backspace: 8,
|
||||
del: 46
|
||||
};
|
||||
|
||||
|
@ -43,25 +49,22 @@ 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;
|
||||
select = index + 1;
|
||||
$(this).removeClass("mouseOver");
|
||||
}
|
||||
});
|
||||
|
@ -81,7 +84,7 @@ function up(){
|
|||
var select = -1;
|
||||
$("#fileList tr").each(function(index){
|
||||
if($(this).hasClass("mouseOver")){
|
||||
select = index-1;
|
||||
select = index - 1;
|
||||
$(this).removeClass("mouseOver");
|
||||
}
|
||||
});
|
||||
|
@ -127,20 +130,28 @@ Files.bindKeyboardShortcuts = function (document, $) {
|
|||
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.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($.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){//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;
|
||||
}
|
||||
|
@ -155,11 +166,15 @@ Files.bindKeyboardShortcuts = function (document, $) {
|
|||
|
||||
$(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
|
||||
|
@ -179,13 +194,23 @@ Files.bindKeyboardShortcuts = function (document, $) {
|
|||
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);
|
||||
});
|
||||
};
|
||||
};
|
||||
})(Files);
|
Loading…
Reference in a new issue