]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5467 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 11 Oct 2022 10:43:46 +0000 (12:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 11 Oct 2022 10:43:46 +0000 (12:43 +0200)
resources/linkeditor/js/linkeditor.js
resources/linkeditor/js/linkeditor.links.js
resources/linkeditor/style/links.sass

index 85fde75fb10055d45d46aed4e758afeac4ec9411..e74b5aed3e9b3fd6d411b38d2507cce580474a74 100644 (file)
@@ -85,6 +85,7 @@ LinkEditor.prototype = {
         });
 
         $(document).on('mousedown', "#linkeditor-main", function (e) {
+            var deselectAll=true;
             $this.setMouseCoordinates(e);
             if ($(this).hasClass('duplicate')) {
                 $this.links.duplicateLinkClick();
@@ -99,8 +100,12 @@ LinkEditor.prototype = {
                 $(this).addClass('grabbing');
             } else {
                 $this.zoom.resetZoomDrag();
+                $this.links.createLinkDrag();
+                deselectAll=false;
+            }
+            if(deselectAll) {
+                $this.links.deselectAllLinks();
             }
-            $this.links.deselectAllLinks();
         });
 
         $(window).on('mousemove', function (e) {
index 92eff378016ff440d1335440da5c3575f2b3fdb0..42e429af17018dd40fc7858fdc2fb3e392009fe7 100644 (file)
@@ -80,18 +80,23 @@ LinkeditorLinks.prototype = {
         this.stopResizeLink();
     },
 
+    createLinkDrag: function () {
+        var link = this.duplicateLinkClick({width: 0, height: 0});
+        $(link).addClass('pendingCreate');
+        this.startResizeLink('se');
+    },
+
     startResizeLink: function (corner) {
         this.resizeLinkPos = {x: this.linkeditor.mx, y: this.linkeditor.my, corner: corner};
-        $(".link.selected").each(function () {
-            $(this).data('drag-orig-left', parseFloat($(this).attr('fb-left')));
-            $(this).data('drag-orig-top', parseFloat($(this).attr('fb-top')));
-            $(this).data('drag-orig-width', parseFloat($(this).attr('fb-width')));
-            $(this).data('drag-orig-height', parseFloat($(this).attr('fb-height')));
-        });
+        this.setDragOrigValues();
     },
 
     stopResizeLink: function () {
+        var $this = this;
         this.moveResizeLink();
+        $('.pendingCreate').each(function () {
+            $this.deleteLink($(this), true);
+        });
         this.resizeLinkPos = null;
     },
 
@@ -187,12 +192,25 @@ LinkeditorLinks.prototype = {
                 }
             }
 
+            if (newWidth < 0) {
+                newWidth *= -1;
+                newLeft -= newWidth;
+            }
+            if (newHeight < 0) {
+                newHeight *= -1;
+                newTop -= newHeight;
+            }
+
             $(this).attr('fb-left', newLeft)
                 .attr('fb-top', newTop)
                 .attr('fb-width', newWidth)
                 .attr('fb-height', newHeight)
                 .attr('fb-update', '1');
 
+            if ($(this).hasClass('pendingCreate') && newWidth > 2 && newHeight > 2) {
+                $(this).removeClass('pendingCreate');
+            }
+
             $this.updateLinkData($(this).attr('fb-uid'), {
                 top: newTop, left: newLeft, width: newWidth, height: newHeight
             });
@@ -209,6 +227,10 @@ LinkeditorLinks.prototype = {
 
     startDragLink: function () {
         this.dragLinkPos = {x: this.linkeditor.mx, y: this.linkeditor.my};
+        this.setDragOrigValues();
+    },
+
+    setDragOrigValues: function () {
         $(".link.selected").each(function () {
             $(this).data('drag-orig-left', parseFloat($(this).attr('fb-left')));
             $(this).data('drag-orig-top', parseFloat($(this).attr('fb-top')));
@@ -290,9 +312,14 @@ LinkeditorLinks.prototype = {
     },
 
     offsetSelectedLinks: function (dim, value) {
+        var $this = this;
         $('.link.selected').each(function () {
             let v = parseFloat($(this).attr('fb-' + dim));
-            $(this).attr('fb-' + dim, v + value).attr('fb-update', '1');
+            let newValue = v + value;
+            let data = {};
+            data[dim] = newValue;
+            $(this).attr('fb-' + dim, newValue).attr('fb-update', '1');
+            $this.updateLinkData($(this).attr('fb-uid'), data);
         });
         this.linkeditor.updateFBElements();
     },
@@ -369,26 +396,41 @@ LinkeditorLinks.prototype = {
         });
     },
 
-    duplicateLinkClick: function () {
+    duplicateLinkClick: function (overwriteData) {
         var data = this.lastSelectedLinkData;
         var pos = this.linkeditor.globalToFluidbook(this.linkeditor.mx, this.linkeditor.my, this.linkeditor.single);
         data.left = pos.x;
         data.top = pos.y;
         data.page = this.linkeditor.currentPage;
+        if (overwriteData !== undefined) {
+            $.extend(data, overwriteData);
+        }
         delete data.uid;
         let link = this.addLink(data);
         this.deselectAllLinks();
         this.selectLink($(link));
+        return $(link);
     },
 
     deleteSelection: function () {
+        var $this = this;
         $(".link.selected").each(function () {
-            delete LINKS[$(this).attr('fb-uid')];
-            $(this).remove();
+            $this.deleteLink(this, false);
         });
         this.linkeditor.hasChanged();
     },
 
+    deleteLink: function (link, triggerChange) {
+        if (triggerChange === undefined) {
+            triggerChange = true;
+        }
+        delete LINKS[$(link).attr('fb-uid')];
+        $(link).remove();
+        if (triggerChange === true) {
+            this.linkeditor.hasChanged();
+        }
+    },
+
     selectAll: function () {
         let $this = this;
         $('.link').each(function () {
index 1ebef6f2c79770e49901b99d4cdee8336cd2ecf0..f1c08920c17a735a9608a3a71d048dc7ce0b6b5f 100644 (file)
@@ -3,11 +3,15 @@
 #linkeditor-links
     .link
         position: absolute
-        outline: 1px solid currentColor
+        border: 1px solid currentColor
         cursor: cell
 
+        &.pendingCreate
+            opacity: 0
+
         &.selected
             cursor: move
+
             .corners
                 visibility: visible
 
@@ -21,7 +25,7 @@
 
             > div
                 position: absolute
-                outline: 1px solid currentColor
+                border: 1px solid currentColor
                 background-color: #fff
                 width: 8px
                 height: 8px