]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cleanup
authorErik Sargent <esthepiking@gmail.com>
Thu, 29 Nov 2012 23:52:41 +0000 (16:52 -0700)
committerErik Sargent <esthepiking@gmail.com>
Thu, 29 Nov 2012 23:52:41 +0000 (16:52 -0700)
apps/files/js/keyboardshortcuts.js

index b00fd649687cda60d804787b8f14e0939e7ee4d8..41578e7f4ae5b18633387b2525192a85c57a36bd 100644 (file)
@@ -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.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;
                        }
@@ -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);
        });
-};
\ No newline at end of file
+};
+})(Files);
\ No newline at end of file