]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5479 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 10 Oct 2022 17:12:31 +0000 (19:12 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 10 Oct 2022 17:12:31 +0000 (19:12 +0200)
resources/linkeditor/js/linkeditor.js
resources/linkeditor/js/linkeditor.links.js
resources/linkeditor/js/linkeditor.rulers.js
resources/linkeditor/js/linkeditor.save.js
resources/views/fluidbook_publication/link_editor.blade.php

index 2d14c9d577457b3d1719e22937a3d07b7c9cbd30..ed5918e7d0a3a7ad55beabbc28608467a090afed 100644 (file)
@@ -175,7 +175,6 @@ LinkEditor.prototype = {
     },
 
     _updateFBElements: function (force) {
-        console.log('_updateFBElements');
         let $this = this;
         let selector = '[fb-ref]';
         if (force !== true) {
@@ -246,7 +245,6 @@ LinkEditor.prototype = {
             this.loader.loadPage(this.currentPage + 1, 'right');
         }
         $("#linkeditor-page-field input").val(this.currentPage);
-        this.rulers.updateRulersMagnetValues();
         this.resize.resize();
         this.loader.preloadPages();
     },
index f2c2e46f8d72032dd01407c83e063d868dd80f02..be035a46bc1e4f2a3bd03f9fc116fde82069f35e 100644 (file)
@@ -192,10 +192,21 @@ LinkeditorLinks.prototype = {
                 .attr('fb-width', newWidth)
                 .attr('fb-height', newHeight)
                 .attr('fb-update', '1');
+
+            $this.updateLinkData($(this).attr('fb-uid'), {
+                top: newTop, left: newLeft, width: newWidth, height: newHeight
+            });
         });
         this.linkeditor.updateFBElements(false);
     },
 
+    updateLinkData: function (id, data) {
+        $.each(data, function (k, v) {
+            LINKS[id][k] = v;
+        });
+        this.linkeditor.rulers.updateMagnetValues();
+    },
+
     startDragLink: function () {
         this.dragLinkPos = {x: this.linkeditor.mx, y: this.linkeditor.my};
         $(".link.selected").each(function () {
@@ -236,6 +247,10 @@ LinkeditorLinks.prototype = {
                 .attr('fb-left', left)
                 .attr('fb-top', top)
                 .attr('fb-update', '1');
+
+            $this.updateLinkData($(this).attr('fb-uid'), {
+                top: top, left: left,
+            });
         });
         this.linkeditor.updateFBElements(false);
     },
@@ -328,14 +343,14 @@ LinkeditorLinks.prototype = {
         $.each(link, function (k, v) {
             attrs['fb-' + k] = v;
         });
-        attrs['fb-ref']="editor";
-        attrs['fb-update']="1";
+        attrs['fb-ref'] = "editor";
+        attrs['fb-update'] = "1";
 
         let e = $('<div class="link" fb-ref="editor" fb-update="1"></div>');
         $(e).attr(attrs);
         $("#linkeditor-links").append(e);
         if (change) {
-            this.linkeditor.rulers.updateRulersMagnetValues();
+            this.linkeditor.rulers.updateMagnetValues();
             this.linkeditor.hasChanged();
         }
         return e;
index 62ef11bcd0954c4e599ffc556449d780b7068227..b48c4ad4421003c1374fc7947d8a2d9536070b42 100644 (file)
@@ -35,17 +35,19 @@ LinkeditorRulers.prototype = {
 
     loadRulers: function (page, side) {
         let $this = this;
-        $.each(this.getRulersOfPage(page), function (uid, ruler) {
+        $.each(this.getRulersOfPage(page, side), function (uid, ruler) {
             $this.addRuler(ruler.type, ruler.pos, ruler.uid);
         });
         this.linkeditor.links.updateMagnetValues();
     },
 
-    getRulersOfPage(page) {
-        var pages = this.linkeditor.getCurrentPages(page);
+    getRulersOfPage(page, side) {
+        if (page === undefined) {
+            page = this.linkeditor.currentPage;
+        }
         var res = {};
         $.each(RULERS, function (uid, ruler) {
-            if (pages.indexOf(parseInt(ruler.page)) === -1) {
+            if (page != ruler.page) {
                 return;
             }
             res[uid] = ruler;
@@ -136,7 +138,7 @@ LinkeditorRulers.prototype = {
         return res;
     },
 
-    updateRulersMagnetValues: function () {
+    updateMagnetValues: function () {
         var $this = this;
         this.rulersMagnetValuesX = [0, this.linkeditor.pw, this.linkeditor.pw * 2];
         this.rulersMagnetValuesY = [0, this.linkeditor.ph];
@@ -207,6 +209,7 @@ LinkeditorRulers.prototype = {
     },
 
     addRuler: function (axis, pos, uid) {
+
         if (undefined === uid) {
             uid = this.linkeditor.utils.generateUID();
             RULERS[uid] = {page: this.linkeditor.currentPage, type: axis, uid: uid};
@@ -219,6 +222,7 @@ LinkeditorRulers.prototype = {
             let dim = axis == 'x' ? 'left' : 'top';
             $(ruler).attr('fb-' + dim, pos);
         }
+
         $("#linkeditor-editor").append(ruler);
         this.moveRuler();
     },
index 6ef30f9cd52d293c852aad5e3391da4492d63f50..4e1f1cbd26a97823390f61a528769318d64e4301 100644 (file)
@@ -1,4 +1,3 @@
-
 function LinkeditorSave(linkeditor) {
     this.linkeditor = linkeditor;
     this.init();
@@ -44,7 +43,7 @@ LinkeditorSave.prototype = {
                 new Noty({
                     type: "success", text: TRANSLATIONS.success_save,
                 }).show();
-                clearTimeout(automaticSaveTimeout);
+                clearTimeout($this.automaticSaveTimeout);
                 $this.unsavedChanges = false;
                 $this.runningAutomaticSaveTimeout = false;
             },
index 268c3ac451385b651412368a920cb7800d227a7e..307ac6b404d18976052fb14f041cb0fd2c689258 100644 (file)
@@ -13,6 +13,9 @@
         'automatic_save_message'=>__('Sauvegarde automatique'),
         'warning_unsaved_changes'=>__('Des données n\'ont pas été sauvegardées'),
     ];
+
+    $rulers=!count($rulers)?'{}':json_encode($rulers);
+    $links=!count($links)?'{}':json_encode($links);
 @endphp
 @extends('layouts.empty')
 
 
 @push('after_scripts')
     <script>
-        var TRANSLATIONS =@json($translations);
+        var TRANSLATIONS = @json($translations);
         var FLUIDBOOK_DATA = @json($fbdata);
-        var LINKS =@json($links);
-        var RULERS =@json($rulers);
+        var LINKS = {!! $links !!};
+        var RULERS = {!! $rulers !!};
     </script>
     <script
         src="/packages/linkeditor/js/linkeditor.js?v={{filemtime(public_path('packages/linkeditor/js/linkeditor.js'))}}"></script>