Browse Source

Added ESC cancel float window operation function (when fw get stuck)

tobychui 4 years ago
parent
commit
ce6305401e
1 changed files with 29 additions and 20 deletions
  1. 29 20
      web/desktop.system

+ 29 - 20
web/desktop.system

@@ -998,7 +998,7 @@
         var movingWindow = false;
         var resizingWindow = false;
         var resizingEdgeID = 0; //Resizing edge. {0, 1, 2, 3, 4, 5} => None, Right, Right Bottom Corner, Bottom, Left Bottom Corner, Left 
-        var stackedFloatWindowListShwon = false;
+        var stackedFloatWindowListShown = false;
 
         //Laucnh icon related
         var multiSelecting = false;
@@ -1662,7 +1662,7 @@
                     var targetFW = getFloatWindowByID(windowIdList[0]);
                     $(targetFW).fadeIn(100);
                     MoveFloatWindowToTop(targetFW);
-                    stackedFloatWindowListShwon = false;
+                    stackedFloatWindowListShown = false;
                     $("#stackedWindowList").hide();
                 } else {
                     //Get icon for each windows and build the list objects
@@ -1673,7 +1673,7 @@
                         $("#stackedWindowList").append(`<div class="item clickable" windowId="${windowIdList[i]}" onclick="bringFloatWindowToFrontByFWB(this,event);"  ontouchstart="bringFloatWindowToFrontByFWB(this,event);"><span><img src="${iconURL}"></img>${title}</span><div class="closebtn" onclick="closeFWviaFWB(this,event);"><img src="img/system/close.png"></img></div></div>`);
                     }
                     $("#stackedWindowList").show();
-                    stackedFloatWindowListShwon = true;
+                    stackedFloatWindowListShown = true;
                 }
 
             });
@@ -1721,7 +1721,7 @@
             }
             $(targetFW).fadeIn(100);
             MoveFloatWindowToTop(targetFW);
-            stackedFloatWindowListShwon = false;
+            stackedFloatWindowListShown = false;
             $("#stackedWindowList").hide();
         }
 
@@ -1738,7 +1738,7 @@
             $(object).parent().remove();
             if ($("#stackedWindowList").find(".item").length == 0) {
                 //There are no more things in this tab. Close this list as well.
-                stackedFloatWindowListShwon = false;
+                stackedFloatWindowListShown = false;
                 $("#stackedWindowList").hide();
             }
         }
@@ -1877,10 +1877,10 @@
 
         //Hook body clicke vents
         $("body").on("click", function(evt) {
-            if (stackedFloatWindowListShwon == true) {
+            if (stackedFloatWindowListShown == true) {
                 //Hide the stacked Float Window list if it is shown
                 $("#stackedWindowList").hide();
-                stackedFloatWindowListShwon = false;
+                stackedFloatWindowListShown = false;
             }
 
             if (renameMode == true){
@@ -4060,18 +4060,20 @@
         }
 
         $(window).on("resize", function(event) {
-                redrawDesktopGrids();
-                resizeAllFloatWindowButtons();
-            })
-            // ======================= DOCUMENT KEY BINDING =====================
-        $(document).keydown(function(event) {
-            if (event.which == "17") {
+            redrawDesktopGrids();
+            resizeAllFloatWindowButtons();
+        })
+
+        // ======================= DOCUMENT KEY BINDING =====================
+        document.addEventListener('keydown', function(event) {
+            let keycode = event.which || event.keyCode;
+            if (keycode == "17") {
                 //Pressdown of Ctrl key
                 ctrlHold = true;
-            } else if (event.which == "16") {
+            } else if (keycode == "16") {
                 //Pressdown of Shift key
                 shiftHold = true;
-            }else if (event.which == "27"){
+            }else if (keycode == "27"){
                 //Cancel all floatwindow events and key events
                 $("#fwdragpanel").hide();
                 $("#tfwdragpanel").hide();
@@ -4082,7 +4084,7 @@
                 multiSelecting = false;
                 ctrlHold = false;
                 shiftHold = false;
-            }else if (event.which == "46"){
+            }else if (keycode == "46"){
                 //Delete key
 
                 if (renameMode){
@@ -4129,7 +4131,7 @@
                     });
                 })
                
-            }else if (event.which == "13"){
+            }else if (keycode == "112"){
                 //Enter key
                 if (!renameMode){
                     //Open selected object by emulating double click
@@ -4149,10 +4151,17 @@
         });
 
         $(document).keyup(function(event) {
-            if (event.which == "17") {
+            let keycode = event.which || event.keyCode;
+            if (keycode == "17") {
                 ctrlHold = false;
-            } else if (event.which == "16") {
+            } else if (keycode == "16") {
                 shiftHold = false;
+            }else if (keycode == "27"){
+                //ESC key, stop all floatWindow operations
+                console.log("%c[Desktop] Dragging function killed. Restarting all dragging elements.", 'color: #e64747');
+                movingWindow = false;
+                resizingWindow = false;
+                event.preventDefault();
             }
         });
 
@@ -5507,7 +5516,7 @@
                         //Check if ramsize > 1.8 GB (2GB). If yes, switch to large memory upload mode
                         var memsize = JSON.parse(data);
                         if (parseFloat(memsize)/ 1024 / 1024 / 1024 >= 3.8){
-                            console.log("[Desktop] Setting upload mode to large memory mode")
+                            console.log("%c[Desktop] Setting upload mode to large memory mode", 'color: #2ba16e');
                             lowMemoryMode = false;
                         }
                     }