From: Vincent Vanwaelscappel Date: Fri, 16 Sep 2022 18:23:45 +0000 (+0200) Subject: wait #5443 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=27bd8ec091393afb107c9b9ee2484f3cf9c63425;p=fluidbook-toolbox.git wait #5443 @0.5 --- diff --git a/public/packages/fluidbook/toolbox/js/linkeditor.js b/public/packages/fluidbook/toolbox/js/linkeditor.js index 362aee680..d67f9f8b1 100644 --- a/public/packages/fluidbook/toolbox/js/linkeditor.js +++ b/public/packages/fluidbook/toolbox/js/linkeditor.js @@ -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(); }