]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5646 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 20 Feb 2023 19:02:15 +0000 (20:02 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 20 Feb 2023 19:02:15 +0000 (20:02 +0100)
resources/linkeditor/js/linkeditor.links.js
resources/linkeditor/style/inc/_contextmenu.sass
resources/linkeditor/style/style.sass
resources/views/fluidbook_publication/link_editor.blade.php

index fc535b2c8ec2db3655660f4101a367c2f8bef42a..fcc70c1ed81589753e6bf1dd99f169e0d7f8f38b 100644 (file)
@@ -75,6 +75,19 @@ LinkeditorLinks.prototype = {
             $this.selectAll();
             return false;
         });
+
+        this.key('ctrl+c', function () {
+            $this.copy();
+            return false;
+        });
+        this.key('ctrl+x', function () {
+            $this.cut();
+            return false;
+        });
+        this.key('ctrl+v', function () {
+            $this.pasteInPlace();
+            return false;
+        });
         this.key('del', function () {
             $this.deleteSelection();
         });
@@ -145,6 +158,7 @@ LinkeditorLinks.prototype = {
                 var selection = $(".link.selected");
                 var multiple = selection.length > 1;
                 var hasSelection = selection.length > 0;
+                var hasClipboard = $("#linkeditor-clipboard").find('.link').length > 0;
 
                 res.items = {
                     'select_all': {
@@ -175,6 +189,41 @@ LinkeditorLinks.prototype = {
                         };
                     }
                 }
+                if (hasSelection || hasClipboard) {
+                    res.items.sep_clipboard = '---------';
+                    if (hasSelection) {
+                        res.items.copy_to_clipboad = {
+                            isHtmlName: true,
+                            name: TRANSLATIONS.copy + ' <kbd>Ctrl+C</kbd>',
+                            callback: function () {
+                                $this.copy();
+                            },
+                        };
+                        res.items.cut_to_clipboad = {
+                            isHtmlName: true,
+                            name: TRANSLATIONS.cut + ' <kbd>Ctrl+X</kbd>',
+                            callback: function () {
+                                $this.cut();
+                            },
+                        };
+                    }
+                    if (hasClipboard) {
+                        res.items.paste_here = {
+                            isHtmlName: true,
+                            name: TRANSLATIONS.paste_here,
+                            callback: function () {
+                                $this.pasteHere();
+                            },
+                        };
+                        res.items.paste_in_place = {
+                            isHtmlName: true,
+                            name: TRANSLATIONS.paste_in_place + ' <kbd>Ctrl+V</kbd>',
+                            callback: function () {
+                                $this.pasteInPlace();
+                            },
+                        };
+                    }
+                }
                 if (hasSelection) {
                     res.items = $.extend(res.items, {
                         'sep0': '---------',
@@ -205,6 +254,57 @@ LinkeditorLinks.prototype = {
         })
     },
 
+    copy: function () {
+        this.copySelectionToClipboard(true);
+    },
+
+    cut: function () {
+        this.copySelectionToClipboard(false);
+    },
+
+    pasteInPlace: function () {
+        var linksInClipboard = $("#linkeditor-clipboard .link");
+        if (!linksInClipboard.length) {
+            return;
+        }
+        var $this = this;
+
+        $(linksInClipboard).each(function () {
+            var item = $(this).clone();
+            if ($this.hasUIDLink($(item).attr('fb-uid'))) {
+                var uid = $this.linkeditor.utils.generateUID();
+                $(item).attr('fb-uid', uid);
+            }
+            $("#linkeditor-links").append(item);
+        });
+    },
+
+    pasteHere: function () {
+        this.pasteInPlace();
+    },
+
+    hasUIDLink: function (uid) {
+        return true;
+    },
+
+    copySelectionToClipboard: function (clone) {
+        var selection = this.getCurrentSelection();
+        if (selection.length === 0) {
+            return;
+        }
+        this.emptyClipboard();
+        $.each(selection, function () {
+            var item = $(this);
+            if (clone) {
+                item = $(item).clone();
+            }
+            $("#linkeditor-clipboard").append(item);
+        });
+    },
+
+    emptyClipboard: function () {
+        $("#linkeditor-clipboard").html('');
+    },
 
     fixDriftedLinks: function () {
         var $this = this;
index 6194be854efef48370f676c3ca95fd303a0fc44c..30c658236f0b8ac0213ad3ab591a442ef6a4cbc9 100644 (file)
@@ -1,5 +1,5 @@
 .context-menu-list
-    z-index: 100000 !important
+    z-index: 1000001 !important
 
 .context-menu-item
     kbd
index be8d891535678ac1d49edd76a102cc486fb29089..ffbdf7152fabda3abbb45d660934a58e2aee977e 100644 (file)
@@ -130,7 +130,7 @@ body, #linkeditor, html
         #linkeditor-page-right
             display: none
 
-#linkeditor-preload
+#linkeditor-preload, #linkeditor-clipboard
     display: none
 
 @import "inc/_panels"
index 9fd7f4299f031127c08364f6252e0abadefca292..c2804b6eb8dca4c53e39e07308fc2df9364736c4 100644 (file)
         'copy_link_id'=>__('Copier l\'identifiant unique'),
         'level'=>__('Niveau'),
         'before_fix_drifted'=>__('Sauvegarde avant la correction de la dérive des liens'),
+        'copy'=>__('Copier'),
+        'cut'=>__('Couper'),
+        'paste_here'=>__('Coller ici'),
+        'paste_in_place'=>__('Coller en place'),
     ];
 
     $rulers=!count($rulers)?'{}':json_encode($rulers);
             <div class="handle"></div>
         </aside>
     </div>
+    <div id="linkeditor-clipboard"></div>
     <div id="linkeditor-preload"></div>
     <div id="linkeditor-form-templates">
         @foreach(\App\SubForms\Link\Base::types() as $f)