]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5818 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Mar 2023 10:55:29 +0000 (11:55 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Mar 2023 10:55:29 +0000 (11:55 +0100)
resources/linkeditor/js/linkeditor.links.js
resources/linkeditor/style/inc/_links.sass

index 728f546dc7937cab1e8e82fe96d6ffacabe248e3..d7ed6fac4d96ac4b8acdecaf47c049b92fd57631 100644 (file)
@@ -12,6 +12,8 @@ var LinkeditorLinks = function (linkeditor) {
 
     this.contextMenuPosition = null;
 
+    this.dropTypes = [4, 7, 12, 15, 16, 17, 18, 25, 30, 31];
+
     this.init();
 }
 
@@ -133,6 +135,55 @@ LinkeditorLinks.prototype = {
             }
         });
 
+        var commonDragAndDropEvent = function (e) {
+            e.originalEvent.dataTransfer.dropEffect = "copy";
+            e.preventDefault();
+        }
+
+        $(document).on('dragententer dragover', '#linkeditor-main', function (e) {
+            $('#linkeditor-main').addClass('dropfile');
+            commonDragAndDropEvent(e);
+        }).on('dragleave', '#linkeditor-main', function (e) {
+            $('#linkeditor-main').removeClass('dropfile');
+            commonDragAndDropEvent(e);
+        });
+
+        $(document).on('dragenter dragover', '.link.dropfile', function (e) {
+            commonDragAndDropEvent(e);
+            $(this).addClass('dragging');
+        });
+        $(document).on('dragleave', '.link.dropfile', function (e) {
+            commonDragAndDropEvent(e);
+            $(this).removeClass('dragging');
+        });
+        $(document).on('drop', '.link.dropfile', function (e) {
+            let link = this;
+            $this.deselectAllLinks();
+
+            commonDragAndDropEvent(e);
+            let uid = $(this).attr('fb-uid');
+            var fd = new FormData();
+            fd.append('entity', 'App\\Models\\FluidbookPublication');
+            fd.append('entry_id', FLUIDBOOK_DATA.id);
+            fd.append('attribute', 'linksAssets');
+            fd.append('file', e.originalEvent.dataTransfer.files[0]);
+            $.ajax({
+                url: '/filesorurlupload',
+                type: 'post',
+                data: fd,
+                contentType: false,
+                processData: false,
+                dataType: 'json',
+                success: function (response) {
+                    $(link).attr('fb-to', response[0]);
+                    $this.selectLink(link);
+                }
+            });
+            $(this).removeClass('dragging');
+            $('#linkeditor-main').removeClass('dropfile');
+        });
+
+
         $.contextMenu({
             selector: '#linkeditor-canvas,.link,#linkeditor-panel-layers, #linkeditor-panel-layers label',
             events: {
@@ -810,8 +861,12 @@ LinkeditorLinks.prototype = {
         attrs['fb-ref'] = "editor";
         attrs['fb-update'] = "1";
 
+
         let e = $('<div class="link" fb-ref="editor" fb-update="1"></div>');
         $(e).attr(attrs);
+        if (this.dropTypes.indexOf(parseInt(link.type)) >= 0) {
+            $(e).addClass('dropfile');
+        }
         $("#linkeditor-links").append(e);
         if (triggerChange && change) {
             this.linkeditor.rulers.updateMagnetValues();
index a38cfc24a76ba2d23bcacd63e4beef0a8e3ec326..35ccca9666a8cf70c30b4a9a15db4cd849e97efd 100644 (file)
@@ -9,6 +9,14 @@
         border: currentColor solid 1px
         cursor: cell
 
+
+        #linkeditor-main.dropfile  &.dropfile
+            border-style: dashed
+
+        &.dropfile.dragging
+            border-width: 3px
+            border-style: dashed
+
         &.pendingCreate
             opacity: 0