From: Vincent Vanwaelscappel Date: Tue, 10 Jun 2025 10:48:38 +0000 (+0200) Subject: wip #7467 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ec3e30d9ebaac572d4578ef7a148ac0418aea025;p=fluidbook-toolbox.git wip #7467 @3 --- diff --git a/resources/linkeditor-stable/js/linkeditor.accessibility.js b/resources/linkeditor-stable/js/linkeditor.accessibility.js index e8f8ad5c7..bc8db99e6 100644 --- a/resources/linkeditor-stable/js/linkeditor.accessibility.js +++ b/resources/linkeditor-stable/js/linkeditor.accessibility.js @@ -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 = '' + TRANSLATIONS.empty + ''; @@ -149,12 +213,14 @@ LinkeditorAccessibility.prototype = { l += ' '; l += ''; l += ''; - 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')), diff --git a/resources/linkeditor-stable/js/linkeditor.links.js b/resources/linkeditor-stable/js/linkeditor.links.js index dbcd0bd61..057302d9e 100644 --- a/resources/linkeditor-stable/js/linkeditor.links.js +++ b/resources/linkeditor-stable/js/linkeditor.links.js @@ -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) { diff --git a/resources/views/fluidbook_publication/link_editor.blade.php b/resources/views/fluidbook_publication/link_editor.blade.php index a1e22ccf7..4844b1816 100644 --- a/resources/views/fluidbook_publication/link_editor.blade.php +++ b/resources/views/fluidbook_publication/link_editor.blade.php @@ -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'),