From 8733a1a8b78bda2d318f5a0dff11e08bfa97268f Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 23 Sep 2022 11:54:07 +0200 Subject: [PATCH] wip #5467 @1 --- resources/linkeditor/js/linkeditor.js | 31 ++++++++++ resources/linkeditor/js/linkeditor.links.js | 59 ++++++++++++++++--- resources/linkeditor/style/style.sass | 16 +++++ .../link_editor.blade.php | 3 +- 4 files changed, 100 insertions(+), 9 deletions(-) diff --git a/resources/linkeditor/js/linkeditor.js b/resources/linkeditor/js/linkeditor.js index 37ec10f7f..c9d632db4 100644 --- a/resources/linkeditor/js/linkeditor.js +++ b/resources/linkeditor/js/linkeditor.js @@ -13,6 +13,7 @@ window.$ = window.jQuery = require('jquery'); window.key = require('keymaster'); window.tippy = tippy; require('jquery.scrollto'); +require('jquery-contextmenu'); function LinkEditor() { this.single = ['mobilefirst', 'portrait'].indexOf(FLUIDBOOK_DATA.settings.mobileNavigationType) >= 0; @@ -59,17 +60,27 @@ LinkEditor.prototype = { if (e.keyCode == 32) { $("#linkeditor-main").addClass('grab'); return false; + } else if (e.keyCode == 18) { + $("#linkeditor-main").addClass('duplicate'); + return false; } $this.rulers.moveRuler(); }); $(window).on('keyup', function (e) { if (e.keyCode == 32) { $this.zoom.resetZoomDrag(); + }else if(e.keyCode==18){ + $("#linkeditor-main").removeClass('duplicate'); + return false; } $this.rulers.moveRuler(); }); $(document).on('mousedown', "#linkeditor-main", function (e) { + if (key.alt) { + $this.links.duplicateLinkClick(); + return; + } if ($(this).hasClass('grab') && $this.zoom.zoom > 1) { $this.zoomdragging = { x: e.pageX, @@ -148,6 +159,7 @@ LinkEditor.prototype = { hasChanged: function () { this.save.hasChanged(); + this.updateFBElements(true); }, updateFBElements: function (force) { @@ -158,6 +170,7 @@ LinkEditor.prototype = { }, _updateFBElements: function (force) { + console.log('_updateFBElements'); let $this = this; let selector = '[fb-ref]'; if (force !== true) { @@ -290,4 +303,22 @@ $(function () { }); +(function (old) { + $.fn.attr = function () { + if (arguments.length === 0) { + if (this.length === 0) { + return null; + } + + var obj = {}; + $.each(this[0].attributes, function () { + if (this.specified) { + obj[this.name] = this.value; + } + }); + return obj; + } + return old.apply(this, arguments); + }; +})($.fn.attr); diff --git a/resources/linkeditor/js/linkeditor.links.js b/resources/linkeditor/js/linkeditor.links.js index 06bf97313..f2c2e46f8 100644 --- a/resources/linkeditor/js/linkeditor.links.js +++ b/resources/linkeditor/js/linkeditor.links.js @@ -8,6 +8,9 @@ var LinkeditorLinks = function (linkeditor) { this.magnetValuesX = []; this.magnetValuesY = []; + this.lastSelectedLink = null; + this.lastSelectedLinkData = {'width': 100, 'height': 100, 'to': '', type: '2', target: '_blank'}; + this.init(); } @@ -66,6 +69,10 @@ LinkeditorLinks.prototype = { key('ctrl+down', function () { $this.offsetSelectedLinks('top', 10); }); + + setInterval(function () { + $this.checkLastSelectedLink(); + }, 250); }, mouseUp: function () { @@ -239,8 +246,28 @@ LinkeditorLinks.prototype = { } $(l).addClass('selected'); this.currentSelection.push(l); + this.lastSelectedLink = l; + }, + + checkLastSelectedLink: function () { + if (this.lastSelectedLink === null || $(this.lastSelectedLink).length === 0) { + return; + } + this.lastSelectedLinkData = this.getLinkData(this.lastSelectedLink); }, + getLinkData: function (l) { + var res = {}; + var attributes = $(l).attr(); + var skip = ['fb-ref', 'fb-update']; + for (var key in attributes) { + if (key.indexOf('fb-') !== 0 || skip.indexOf(key) >= 0) { + continue; + } + res[key.substring(3)] = attributes[key]; + } + return res; + }, deselectAllLinks: function () { this.currentSelection = []; @@ -290,25 +317,28 @@ LinkeditorLinks.prototype = { addLink: function (link) { let $this = this; + let change = false; if (link.uid === undefined) { - link.uid = generateUID(); + link.uid = this.linkeditor.utils.generateUID(); LINKS[link.uid] = link; - this.linkeditor.rulers.updateRulersMagnetValues(); - this.linkeditor.hasChanged(); + change = true; } let attrs = {}; $.each(link, function (k, v) { - if ($this.linkeditor.dimensionProperties.indexOf(k) >= 0) { - attrs['fb-' + k] = v; - } else { - attrs['data-' + k] = v; - } + attrs['fb-' + k] = v; }); + attrs['fb-ref']="editor"; + attrs['fb-update']="1"; let e = $(''); $(e).attr(attrs); $("#linkeditor-links").append(e); + if (change) { + this.linkeditor.rulers.updateRulersMagnetValues(); + this.linkeditor.hasChanged(); + } + return e; }, updateMagnetValues: function () { @@ -324,6 +354,18 @@ LinkeditorLinks.prototype = { }); }, + duplicateLinkClick: function () { + 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; + delete data.uid; + let link = this.addLink(data); + this.deselectAllLinks(); + this.selectLink($(link)); + }, + deleteSelection: function () { $(".link.selected").each(function () { delete LINKS[$(this).data('uid')]; @@ -343,4 +385,5 @@ LinkeditorLinks.prototype = { $("#linkeditor-links").html(''); }, }; + module.exports = LinkeditorLinks; diff --git a/resources/linkeditor/style/style.sass b/resources/linkeditor/style/style.sass index 14f9f347c..26e8092ad 100644 --- a/resources/linkeditor/style/style.sass +++ b/resources/linkeditor/style/style.sass @@ -45,6 +45,22 @@ body, #linkeditor, html &.grabbing cursor: grabbing + #linkeditor-duplicatelink-overlay + display: none + position: absolute + z-index: 700 + top: $rulers-size + left: $rulers-size + height: calc(100% - $rulers-size) + max-height: calc(100% - $rulers-size) + width: calc(100% - $rulers-size) + max-width: calc(100% - $rulers-size) + cursor: copy + + &.duplicate + #linkeditor-duplicatelink-overlay + display: block + #linkeditor-editor position: relative height: calc(100% - $toolbar-height) diff --git a/resources/views/fluidbook_publication/link_editor.blade.php b/resources/views/fluidbook_publication/link_editor.blade.php index 869b623d0..268c3ac45 100644 --- a/resources/views/fluidbook_publication/link_editor.blade.php +++ b/resources/views/fluidbook_publication/link_editor.blade.php @@ -68,6 +68,7 @@
+
@@ -96,7 +97,7 @@ @push('after_styles')