Explorar o código

Keep dialog window within browser window bounds upon resize

Joeri Exelmans %!s(int64=2) %!d(string=hai) anos
pai
achega
760e827b4e
Modificáronse 1 ficheiros con 13 adicións e 3 borrados
  1. 13 3
      src/main/webapp/myPlugins/dtdesign.js

+ 13 - 3
src/main/webapp/myPlugins/dtdesign.js

@@ -511,10 +511,13 @@ fetch(BACKEND+"/version")
     });
   }
 
+  // make sure the plugin popup window is always within the bounds of the browser window:
+  const dialogPosX = x => Math.max(0, Math.min(x, window.innerWidth - getSetting("dialogWidth")));
+  const dialogPosY = y => Math.max(0, Math.min(y, window.innerHeight - getSetting("dialogHeight")));
+
   const wnd = new mxWindow("ModelVerse", wndDiv,
-    // make sure the plugin popup window is always within the bounds of the browser window:
-    Math.max(0, Math.min(getSetting("dialogPosX"), window.innerWidth-getSetting("dialogWidth"))),
-    Math.max(0, Math.min(getSetting("dialogPosY"), window.innerHeight-getSetting("dialogHeight"))),
+    dialogPosX(getSetting("dialogPosX")),
+    dialogPosY(getSetting("dialogPosY")),
     getSetting("dialogWidth"),
     getSetting("dialogHeight"),
     true, true);
@@ -539,6 +542,13 @@ fetch(BACKEND+"/version")
   window.onresize = event => {
     console.log(wnd);
     console.log(event);
+    // make sure popup window remains within browser window bounds:
+    const newX = dialogPosX(wnd.getX());
+    const newY = dialogPosY(wnd.getY());
+    wnd.div.style.left = newX + "px";
+    wnd.div.style.top = newY + "px";
+    setSetting("dialogPosX", newX);
+    setSetting("dialogPosY", newY);
   }
 
 }) // end of promise that checks the backend version.