]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5443 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 16 Sep 2022 18:23:45 +0000 (20:23 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 16 Sep 2022 18:23:45 +0000 (20:23 +0200)
public/packages/fluidbook/toolbox/js/linkeditor.js

index 362aee6801d9567fd611ee338c83909bf7b17ff6..d67f9f8b178c4bf015ba7112199132c402eb5db3 100644 (file)
@@ -17,6 +17,8 @@ var unsavedChanges = false;
 var automaticSaveTimeout;
 var runningAutomaticSaveTimeout = false;
 var dimensionProperties = ['left', 'top', 'width', 'height'];
+var rulersMagnetValuesX = [];
+var rulersMagnetValuesY = [];
 
 $(function () {
     init();
@@ -283,10 +285,10 @@ function moveRuler() {
     var v, fbv;
     if ($(movingRuler).data('axis') === 'x') {
         v = editorMouse.x;
-        fbv = attrs['fb-left'] = magnet ? magnetize(fbMouse.x, getRulersMagnetValues('x')) : fbMouse.x;
+        fbv = attrs['fb-left'] = magnet ? magnetize(fbMouse.x, rulersMagnetValuesX) : fbMouse.x;
     } else {
         v = editorMouse.y;
-        fbv = attrs['fb-top'] = magnet ? magnetize(fbMouse.y, getRulersMagnetValues('y')) : fbMouse.y;
+        fbv = attrs['fb-top'] = magnet ? magnetize(fbMouse.y, rulersMagnetValuesY) : fbMouse.y;
     }
     if (v < 16) {
         $(movingRuler).addClass('pending-delete');
@@ -322,19 +324,22 @@ function magnetize(value, values) {
 }
 
 function getLinksOfPage(p) {
-    if (!single && p % 2 === 1) {
-        p--;
-    }
-}
-
-function getRulersMagnetValues(axis) {
-    var res = [0];
-    if (axis === 'x') {
-        res.push(pw);
-        res.push(pw * 2);
+    let pages = [];
+    if (!single) {
+        if (p % 2 === 1) {
+            p--;
+        }
+        pages.push(p);
+        pages.push(p + 1);
     } else {
-        res.push(ph);
+        pages.push(p);
     }
+    let res = {};
+    $.each(LINKS, function (uid, link) {
+        if (pages.indexOf(parseInt(link.page)) >= 0) {
+            res[uid] = link;
+        }
+    });
     return res;
 }
 
@@ -480,10 +485,24 @@ function changePage(page) {
         loadPage(currentPage + 1, 'right');
     }
     $("#linkeditor-page-field input").val(currentPage);
+    updateRulersMagnetValues();
     resize();
     preloadPages();
 }
 
+function updateRulersMagnetValues() {
+    rulersMagnetValuesX = [0, pw, pw * 2];
+    rulersMagnetValuesY = [0, ph];
+    $.each(getLinksOfPage(currentPage), function (uid, link) {
+        const left = parseFloat(link.left);
+        const top = parseFloat(link.top);
+        const width = parseFloat(link.width);
+        const height = parseFloat(link.height);
+        rulersMagnetValuesX.push(left, left + width);
+        rulersMagnetValuesY.push(top, top + height);
+    });
+}
+
 // Convert global coordinates to fluidbook ones
 function globalToFluidbook(x, y, onePage) {
     var res = _globalTo(x, y, fluidbookRect, 1 / (fs * zoom));
@@ -573,6 +592,7 @@ function addLink(link) {
     if (link.uid === undefined) {
         link.uid = generateUID();
         LINKS[link.uid] = link;
+        updateRulersMagnetValues();
         hasChanged();
     }