var automaticSaveTimeout;
var runningAutomaticSaveTimeout = false;
var dimensionProperties = ['left', 'top', 'width', 'height'];
+var rulersMagnetValuesX = [];
+var rulersMagnetValuesY = [];
$(function () {
init();
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');
}
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;
}
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));
if (link.uid === undefined) {
link.uid = generateUID();
LINKS[link.uid] = link;
+ updateRulersMagnetValues();
hasChanged();
}