]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7467 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 10 Jun 2025 10:48:38 +0000 (12:48 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 10 Jun 2025 10:48:38 +0000 (12:48 +0200)
resources/linkeditor-stable/js/linkeditor.accessibility.js
resources/linkeditor-stable/js/linkeditor.links.js
resources/views/fluidbook_publication/link_editor.blade.php

index e8f8ad5c71d4ceffdb81e7a6d1ea7938bd7c191a..bc8db99e68c8c888a50d0d906ab6e301fb11c221 100644 (file)
@@ -20,6 +20,16 @@ LinkeditorAccessibility.prototype = {
         this.update();
     },
 
+    reorderSelection: function (way) {
+        let selection = this.getCurrentOrderableSelection();
+        let selectedOrder = parseInt($(selection).eq(0).attr('fb-order'));
+        selection = this.orderLinksByPosition(selection, way);
+        $(selection).each(function () {
+            $(this).attr('fb-order', selectedOrder++);
+        });
+        this.normalizeLinksOrder();
+    },
+
     moveSelectionOrder: function (way) {
         let start;
         let selection = this.getCurrentOrderableSelection();
@@ -83,6 +93,57 @@ LinkeditorAccessibility.prototype = {
         });
     },
 
+    orderLinksByPosition: function (links, way) {
+        let doublePage = !this.linkeditor.single && !this.linkeditor.utils.isSpecialPage(this.linkeditor.currentPage);
+        let pw = this.linkeditor.pw;
+
+        return $(links).toArray().sort(function (a, b) {
+            let pa = 0;
+            let pb = 0;
+            let xa = parseFloat($(a).attr('fb-left'));
+            let xb = parseFloat($(b).attr('fb-left'));
+            if (doublePage) {
+                if (xa >= pw) {
+                    xa -= pw;
+                    pa++;
+                }
+                if (xb >= pw) {
+                    xb -= pw;
+                    pb++;
+                }
+                if (pa !== pb) {
+                    return pa - pb;
+                }
+            }
+
+
+            let wa = parseFloat($(a).attr('fb-width'));
+            let wb = parseFloat($(b).attr('fb-width'));
+
+            let xTolerance = Math.min(wa, wb) / 2;
+
+            let ha = parseFloat($(a).attr('fb-height'));
+            let hb = parseFloat($(b).attr('fb-height'));
+
+            let yTolerance = Math.min(ha, hb) / 2;
+
+            xa += wa / 2;
+            xb += wb / 2;
+
+            let ya = parseFloat($(a).attr('fb-top')) + ha / 2;
+            let yb = parseFloat($(b).attr('fb-top')) + hb / 2;
+
+            let xdiff = xa - xb;
+            let ydiff = ya - yb;
+
+            if (way === 'horizontal') {
+                return Math.abs(xdiff) > xTolerance ? xdiff : ydiff;
+            } else if (way === 'vertical') {
+                return Math.abs(ydiff) > yTolerance ? ydiff : xdiff;
+            }
+        });
+    },
+
     getCurrentOrderableSelection: function () {
         return this.filterOrderableLinks(this.linkeditor.links.getCurrentSelection());
     },
@@ -108,6 +169,7 @@ LinkeditorAccessibility.prototype = {
         let i = 0;
         $(links).each(function (k, v) {
             $(v.link).attr('fb-order', i++);
+            $(v.link).attr('fb-orderable', v.interactive ? '1' : '0');
         });
 
         if (refresh) {
@@ -141,6 +203,8 @@ LinkeditorAccessibility.prototype = {
             let type = $(this).attr('fb-type');
             let dest = $(this).attr('fb-to');
             let uid = $(this).attr('fb-uid');
+            let level = $this.getLinkLevel($(this));
+            let interactive = level >= 5;
 
             if (dest === '') {
                 dest = '<em>' + TRANSLATIONS.empty + '</em>';
@@ -149,12 +213,14 @@ LinkeditorAccessibility.prototype = {
             l += '<input name="' + uid + '" type="checkbox"> ';
             l += '<label class="layer" data-uid="' + uid + '">';
             l += dest;
-            l += '<span class="order">#' + $(this).attr('fb-order') + '</span>';
+            if (interactive) {
+                l += '<span class="order">#' + $(this).attr('fb-order') + '</span>';
+            }
             l += '</label>';
             l += '</div>';
-            let level = $this.getLinkLevel($(this));
+
             accessibility.push({
-                interactive: level >= 5,
+                interactive: interactive,
                 zindex: parseInt($(this).attr('fb-calc-zindex')),
                 html: l,
                 order: parseInt($(this).attr('fb-order')),
index dbcd0bd618202ab748d6624925251c05ccc555ae..057302d9ed32ddfa5f6abc5c8f8840edd02ea21f 100644 (file)
@@ -235,8 +235,11 @@ LinkeditorLinks.prototype = {
                     }
                 };
                 var selection = $(".link.selected");
+                var orderableSelection = $('.link[fb-orderable="1"].selected');
                 var multiple = selection.length > 1;
                 var hasSelection = selection.length > 0;
+                var hasOrderableSelection = orderableSelection.length > 0;
+                var hasMultipleOrderableSelection = orderableSelection.length > 1;
                 var hasClipboard = !$this.linkeditor.clipboard.isEmpty();
 
                 res.items = {
@@ -345,7 +348,7 @@ LinkeditorLinks.prototype = {
                         }
                     });
                 }
-                if (hasSelection) {
+                if (hasOrderableSelection) {
                     res.items = $.extend(res.items, {
                         'sep_order': '---------', "order": {
                             name: (TRANSLATIONS.edit_link_order) + '', items: {
@@ -369,6 +372,23 @@ LinkeditorLinks.prototype = {
                             }
                         },
                     });
+                    if (hasMultipleOrderableSelection) {
+                        res.items = $.extend(res.items, {
+                            "order_selection": {
+                                name: (TRANSLATIONS.reorder_selection) + '', items: {
+                                    'reorder_horizontal': {
+                                        name: TRANSLATIONS.reorder_horizontal, callback: function () {
+                                            $this.reorderSelection('horizontal');
+                                        }
+                                    }, 'reorder_vertical': {
+                                        name: TRANSLATIONS.reorder_vertical, callback: function () {
+                                            $this.reorderSelection('vertical');
+                                        }
+                                    },
+                                }
+                            },
+                        });
+                    }
                 }
                 if (hasSelection) {
                     res.items = $.extend(res.items, {
@@ -395,6 +415,10 @@ LinkeditorLinks.prototype = {
         return this.linkeditor.accessibility.moveSelectionOrder(way);
     },
 
+    reorderSelection: function (way) {
+        return this.linkeditor.accessibility.reorderSelection(way);
+    },
+
     key: function (shortcut, scope) {
         var $this = this;
         key(shortcut, function (event, handler) {
index a1e22ccf7c7050a5c8a7827952d0d1bf14431c42..4844b1816e7e1887843e73a98b1dc0dfaf4d4d6e 100644 (file)
@@ -85,6 +85,9 @@
         'edit_image_link'=>__('Editer les liens de l\'image'),
         'delete_selection'=>__('Supprimer la sélection'),
         'edit_link_order'=>__('Modifier l\'ordre'),
+        'reorder_selection'=>__('Réordonner la sélection'),
+        'reorder_horizontal'=>__('Horizontal puis vertical'),
+        'reorder_vertical'=>__('Vertical puis horizontal'),
         'move_up'=>__('Avant'),
         'move_down'=>__('Après'),
         'move_beginning'=>__('Au début'),