From 84520a9f0e9a79ab634ae57f1ccae1f867c34c25 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 22 Mar 2023 11:55:29 +0100 Subject: [PATCH] wip #5818 @1.5 --- resources/linkeditor/js/linkeditor.links.js | 55 +++++++++++++++++++++ resources/linkeditor/style/inc/_links.sass | 8 +++ 2 files changed, 63 insertions(+) diff --git a/resources/linkeditor/js/linkeditor.links.js b/resources/linkeditor/js/linkeditor.links.js index 728f546dc..d7ed6fac4 100644 --- a/resources/linkeditor/js/linkeditor.links.js +++ b/resources/linkeditor/js/linkeditor.links.js @@ -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 = $(''); $(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(); diff --git a/resources/linkeditor/style/inc/_links.sass b/resources/linkeditor/style/inc/_links.sass index a38cfc24a..35ccca966 100644 --- a/resources/linkeditor/style/inc/_links.sass +++ b/resources/linkeditor/style/inc/_links.sass @@ -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 -- 2.39.5