]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5466 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 10 Feb 2023 18:29:40 +0000 (19:29 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 10 Feb 2023 18:29:40 +0000 (19:29 +0100)
resources/linkeditor/js/linkeditor.js
resources/linkeditor/js/linkeditor.links.js

index 34009a6099ac553de28095a39f8d0fa173bfa9a1..c91656931a823b3a5f8380af72bcd8793a4b910a 100644 (file)
@@ -154,7 +154,7 @@ LinkEditor.prototype = {
             return true;
         });
 
-        // Disable scroll by spacebar
+
         $(window).on('keydown', function (e) {
             if (e.keyCode == 32) {
                 if (!$this.mobileFirst) {
@@ -168,6 +168,7 @@ LinkEditor.prototype = {
             $this.rulers.moveRuler();
         });
 
+        // Disable scroll by spacebar
         $(window).on('keyup', function (e) {
             if (e.keyCode == 32) {
                 $this.zoom.resetZoomDrag();
@@ -184,10 +185,11 @@ LinkEditor.prototype = {
                 return true;
             }
             var deselectAll = true;
-            if ($(this).hasClass('duplicate')) {
+
+            if ($('#linkeditor-main').hasClass('duplicate')) {
                 $this.links.duplicateLinkClick();
-                return;
-            } else if ($(this).hasClass('grab')) {
+                return false;
+            } else if ($('#linkeditor-main').hasClass('grab')) {
                 $this.zoom.zoomdragging = {
                     x: $this.mx,
                     y: $this.my,
index 0132f4c276927bcede47dee4cbdfda8f272de306..2a7d20b5614363c176e409c6f301e2e13d352e1c 100644 (file)
@@ -48,48 +48,49 @@ LinkeditorLinks.prototype = {
             return false;
         });
 
-        key('ctrl+a', function () {
+        this.key('ctrl+a', function () {
+
             $this.selectAll();
             return false;
         });
-        key('del', function () {
+        this.key('del', function () {
             $this.deleteSelection();
         });
-        key('left', function () {
+        this.key('left', function () {
             $this.offsetSelectedLinks('left', -1);
         });
-        key('ctrl+left', function () {
+        this.key('ctrl+left', function () {
             $this.offsetSelectedLinks('left', -10);
         });
-        key('right', function () {
+        this.key('right', function () {
             $this.offsetSelectedLinks('left', 1);
         });
-        key('ctrl+right', function () {
+        this.key('ctrl+right', function () {
             $this.offsetSelectedLinks('left', 10);
         });
-        key('up', function () {
+        this.key('up', function () {
             $this.offsetSelectedLinks('top', -1);
         });
-        key('ctrl+up', function () {
+        this.key('ctrl+up', function () {
             $this.offsetSelectedLinks('top', -10);
         });
-        key('down', function () {
+        this.key('down', function () {
             $this.offsetSelectedLinks('top', 1);
         });
-        key('ctrl+down', function () {
+        this.key('ctrl+down', function () {
             $this.offsetSelectedLinks('top', 10);
         });
-        key('pageup', function () {
+        this.key('pageup', function () {
             $this.selectPreviousLink();
         });
-        key('pagedown', function () {
+        this.key('pagedown', function () {
             $this.selectNextLink();
         });
-        key('ctrl+l', function () {
+        this.key('ctrl+l', function () {
             $this.openImageLink();
             return false;
         });
-        key('enter', function () {
+        this.key('enter', function () {
             if ($(document.activeElement).is('input[name="to"]')) {
                 $this.selectNextLink();
                 return false;
@@ -173,6 +174,22 @@ LinkeditorLinks.prototype = {
         }, 250);
     },
 
+    key: function (shortcut, scope) {
+        var $this = this;
+        key(shortcut, function (event, handler) {
+            if ($this.allowsKeyboardShortcut(shortcut)) {
+                scope(event, handler);
+            }
+        })
+    },
+
+    allowsKeyboardShortcut: function (shortcut) {
+        if (shortcut === 'pageup' || shortcut === 'pagedown' || shortcut === 'enter') {
+            return true;
+        }
+        return !$(document.activeElement).is('input,textarea,select');
+    },
+
     openImageLink: function () {
         let selection = $(".link[fb-type=6].selected");
         if (selection.length !== 1 || selection.attr('fb-alternative') == '') {
@@ -233,7 +250,7 @@ LinkeditorLinks.prototype = {
     },
 
     createLinkDrag: function () {
-        var link = this.duplicateLinkClick({width: 0, height: 0});
+        var link = this.duplicateLinkDrag({width: 0, height: 0});
         $(link).addClass('pendingCreate');
         this.startResizeLink('se');
         this.linkeditor.form.updateLinkForm();
@@ -579,17 +596,35 @@ LinkeditorLinks.prototype = {
         });
     },
 
-    duplicateLinkClick: function (overwriteData) {
+    _duplicateLink: function () {
         var data = this.lastSelectedLinkData;
+        data.page = this.linkeditor.currentPage;
         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;
+        return data;
+    },
+
+    duplicateLinkClick: function () {
+        var data = this._duplicateLink();
+
+        let link = this.addLink(data);
+
+        this.deselectAllLinks();
+        this.selectLink($(link));
+        this.linkeditor.form.updateFormData();
+
+        return $(link);
+    },
+
+    duplicateLinkDrag(overwriteData) {
+        var data = this._duplicateLink();
         if (overwriteData !== undefined) {
             $.extend(data, overwriteData);
         }
-        delete data.uid;
         let link = this.addLink(data);
+
         this.deselectAllLinks();
         this.selectLink($(link));
         this.linkeditor.form.updateFormData();