]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5467 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Sep 2022 09:54:07 +0000 (11:54 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Sep 2022 09:54:07 +0000 (11:54 +0200)
resources/linkeditor/js/linkeditor.js
resources/linkeditor/js/linkeditor.links.js
resources/linkeditor/style/style.sass
resources/views/fluidbook_publication/link_editor.blade.php

index 37ec10f7f67a18238127810c99b08387f4a9fe41..c9d632db470dfe2f54a99a8076e5bfa73e890e8d 100644 (file)
@@ -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);
index 06bf9731391cab4185e92744e2f7cdb7218c5f87..f2c2e46f8d72032dd01407c83e063d868dd80f02 100644 (file)
@@ -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 = $('<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.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;
index 14f9f347cd44222ec677a936dc9f8af4dc5bc27f..26e8092add6dfc02cf5f0d5e7ac0bbcdbb6d051f 100644 (file)
@@ -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)
index 869b623d0c0342a409fdc6fb3cd957b9313df9e5..268c3ac451385b651412368a920cb7800d227a7e 100644 (file)
@@ -68,6 +68,7 @@
                     <div class="ruler-bar" id="linkeditor-ruler-x"></div>
                     <div class="ruler-bar" id="linkeditor-ruler-y"></div>
                 </div>
+                <div draggable="false" id="linkeditor-duplicatelink-overlay"></div>
                 <div draggable="false" id="linkeditor-canvas">
                     <div draggable="false" id="linkeditor-zoom">
                         <div draggable="false" id="linkeditor-fluidbook">
@@ -96,7 +97,7 @@
 @push('after_styles')
     <style>
         @foreach(\App\SubForms\Link\Base::types() as $type)
-            .link[data-type="{{$type['type']}}"] {
+            .link[fb-type="{{$type['type']}}"] {
             color: {{$type['color']}};
             background-color: {{\Cubist\Util\Graphics\Color::colorToCSS($type['color'],0.25)}};
         }