]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5447 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Mar 2023 17:16:30 +0000 (18:16 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Mar 2023 17:16:30 +0000 (18:16 +0100)
resources/linkeditor/js/linkeditor.js
resources/linkeditor/js/linkeditor.links.js
resources/views/fluidbook_publication/link_editor.blade.php

index b95f3d8db3ed3990fcf12e673f0add5670fe2563..87f6643a33add19720c4f6e4ec8bea8ad7d1fbba 100644 (file)
@@ -236,9 +236,12 @@ LinkEditor.prototype = {
     },
 
     runAction: function (act, args) {
-        if (arguments === undefined) {
+        if (args === undefined) {
             args = [];
         }
+        if (typeof args === 'string') {
+            args = [args];
+        }
         var a = act.split('.');
         var o = this;
         let po = this;
index 5fbe87e3e3e94e4f1ad85e15a88d92fb48e163b5..99f784240688bbb744e9c9bed741e2b90a953139 100644 (file)
@@ -934,6 +934,46 @@ LinkeditorLinks.prototype = {
     clear: function () {
         $("#linkeditor-links").html('');
     },
+
+    alignSelection: function (align) {
+        if (align === 'left' || align === 'top') {
+            var min = 1000000;
+            $.each(this.getCurrentSelection(), function () {
+                min = Math.min(min, parseFloat($(this).attr('fb-' + align)));
+            });
+            $.each(this.getCurrentSelection(), function () {
+                $(this).attr('fb-' + align, min);
+            });
+        } else if (align === 'right' || align === 'bottom') {
+            var b = align === 'right' ? 'left' : 'top';
+            var l = align === 'right' ? 'width' : 'height';
+            var max = -10000000;
+            $.each(this.getCurrentSelection(), function () {
+                max = Math.max(max, parseFloat($(this).attr('fb-' + b)) + parseFloat($(this).attr('fb-' + l)));
+            });
+            $.each(this.getCurrentSelection(), function () {
+                $(this).attr('fb-' + b, max - parseFloat($(this).attr('fb-' + l)));
+            });
+        } else if (align === 'center' || align === 'middle') {
+            var b = align === 'center' ? 'left' : 'top';
+            var l = align === 'center' ? 'width' : 'height';
+            var max = -10000000;
+            var min = 1000000;
+            $.each(this.getCurrentSelection(), function () {
+                min = Math.min(min, parseFloat($(this).attr('fb-' + b)));
+                max = Math.max(max, parseFloat($(this).attr('fb-' + b)) + parseFloat($(this).attr('fb-' + l)));
+            });
+            var center = min + ((max - min) / 2);
+            $.each(this.getCurrentSelection(), function () {
+                $(this).attr('fb-' + b, center - parseFloat($(this).attr('fb-' + l)) / 2);
+            });
+        }
+
+        this.linkeditor.hasChanged();
+    },
+    distributeSelection: function (axis) {
+
+    },
 };
 
 module.exports = LinkeditorLinks;
index 6ddba340261c77bbf952040999d2115178393d6f..d03cb146abbce968ccd7e26ae04ca33190e20b89 100644 (file)
                 </nav>
                 <nav id="linkeditor-toolbar-right">
                     <div class="when-selection-3">
-                        <a href="#" data-action="distributeSelection.horizontally"
+                        <a href="#" data-action="links.distributeSelection" data-action-args="x"
                            data-tooltip="{{__('Distribuer la sélection horizontalement')}}"
                            data-icon="distribute-horizontally"></a>
-                        <a href="#" data-action="distributeSelection.vertically"
+                        <a href="#" data-action="links.distributeSelection" data-action-args="y"
                            data-tooltip="{{__('Distribuer la sélection verticalement')}}"
                            data-icon="distribute-vertically"></a>
                         <div class="separator"></div>
                     </div>
                     <div class="when-selection-2">
                         @foreach($alignments as $a=>$label)
-                            <a href="#" data-action="alignSelection.{{$a}}" data-tooltip="{{$label}}"
+                            <a href="#" data-action="links.alignSelection" data-action-args="{{$a}}"
+                               data-tooltip="{{$label}}"
                                data-icon="align-{{$a}}"></a>
                         @endforeach
                     </div>