From bb3142f3e81e4076f320dcd3a3e269bc5f2caee0 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 5 Jun 2025 18:09:01 +0200 Subject: [PATCH] wip #7467 @6 --- app/Fluidbook/Link/LinksData.php | 4 +- .../js/linkeditor.accessibility.js | 137 +++++++++++------- resources/linkeditor-stable/js/linkeditor.js | 2 +- .../linkeditor-stable/js/linkeditor.layers.js | 55 +------ .../linkeditor-stable/js/linkeditor.links.js | 70 ++++----- .../linkeditor-stable/js/linkeditor.panels.js | 111 +++++++++++--- .../linkeditor-stable/style/inc/_layers.sass | 40 +++-- .../link_editor.blade.php | 8 +- 8 files changed, 244 insertions(+), 183 deletions(-) diff --git a/app/Fluidbook/Link/LinksData.php b/app/Fluidbook/Link/LinksData.php index dde655d9e..d8dc67403 100644 --- a/app/Fluidbook/Link/LinksData.php +++ b/app/Fluidbook/Link/LinksData.php @@ -38,7 +38,9 @@ class LinksData $cols = array( 'uid' => __('Identifiant unique'), - 'page' => __('Page de la publication'), 'left' => __('x'), 'top' => __('y'), 'width' => __('Largeur'), 'height' => __('Hauteur'), 'rot' => __('Rotation'), + 'page' => __('Page de la publication'), + 'order' => __('Ordre'), + 'left' => __('x'), 'top' => __('y'), 'width' => __('Largeur'), 'height' => __('Hauteur'), 'rot' => __('Rotation'), 'type' => __('Type'), 'to' => __('Destination'), 'target' => __('Cible'), 'tooltip' => __('Infobulle'), 'numerotation' => __('Numérotation'), 'display_area' => __('Activer la surbrillance'), diff --git a/resources/linkeditor-stable/js/linkeditor.accessibility.js b/resources/linkeditor-stable/js/linkeditor.accessibility.js index bdaa92d17..16ec258f5 100644 --- a/resources/linkeditor-stable/js/linkeditor.accessibility.js +++ b/resources/linkeditor-stable/js/linkeditor.accessibility.js @@ -7,38 +7,8 @@ LinkeditorAccessibility.prototype = { var $this = this; this.container = $("#linkeditor-panel-accessibility"); - console.log(this.container); this.maskCheckEvents = false; - $(document).on('click', '#linkeditor-panel-accessibility a.lock', function () { - let uid = $(this).closest('.layer').find('input').attr('name'); - $this.linkeditor.links.locks.toggleLock(uid); - return false; - }); - - $(document).on('click', "#linkeditor-panel-accessibility label", function (e) { - if ($this.maskCheckEvents) { - return false; - } - let uid = $(this).find('input').attr('name'); - let checked = $(this).find('input').prop('checked'); - var link = $('#linkeditor-links [fb-uid="' + uid + '"]'); - - if (!e.ctrlKey) { - $this.linkeditor.links.deselectAllLinks(); - $this.linkeditor.links.selectLink(link); - } else { - if (checked) { - $this.linkeditor.links.deselectLink(link); - } else { - $this.linkeditor.links.selectLink(link); - } - } - - $this.linkeditor.form.updateLinkForm(); - return false; - }); - $(document).on('click', '#linkeditor-panel-accessibility label span.uid', function () { navigator.clipboard.writeText($(this).attr('fb-uid')); let tippy = $(this).data('tippyinstance'); @@ -50,7 +20,77 @@ LinkeditorAccessibility.prototype = { this.update(); }, - normalizeLinksOrder: function () { + moveSelectionOrder: function (way) { + let start; + let selection = this.getCurrentOrderableSelection(); + let num = selection.length; + if (num <= 0) { + return; + } + let firstSelected = $(selection).get(0); + let firstSelectedOrder = parseInt($(firstSelected).attr('fb-order')); + let max = this.getOrderableLinksOnPage().length + 1; + + let step = 1 / (num + 1); + + switch (way) { + case'start': + start = -num; + step = -1; + break; + case'end': + start = max; + step = 1; + break; + case'up': + start = firstSelectedOrder - 1 - step; + step *= -1; + break; + case'down': + start = firstSelectedOrder + 1 + step; + break; + } + + let selectedOrder = start; + + $(selection).each(function () { + $(this).attr('fb-order', selectedOrder); + selectedOrder += step; + }); + + this.normalizeLinksOrder(); + }, + + getOrderableLinksOnPage: function () { + return this.filterOrderableLinks(this.linkeditor.links.getLinksOfCurrentPage()); + }, + + filterOrderableLinks: function (links) { + let res = []; + $.each(links, function () { + if ($(this).attr('fb-calc-depth') < 50) { + return; + } + res.push(this); + }); + + return this.orderLinks(res); + }, + + orderLinks: function (links) { + return $(links).toArray().sort(function (a, b) { + return parseInt($(a).attr('fb-order')) - parseInt($(b).attr('fb-order')); + }); + }, + + getCurrentOrderableSelection: function () { + return this.filterOrderableLinks(this.linkeditor.links.getCurrentSelection()); + }, + + normalizeLinksOrder: function (refresh) { + if (refresh === undefined) { + refresh = true; + } let $this = this; let links = []; $('#linkeditor-links .link:not(.pendingCreate)').each(function () { @@ -60,7 +100,6 @@ LinkeditorAccessibility.prototype = { links.sort(function (a, b) { if (a.interactive === b.interactive) { - console.log(a.order, b.order); return a.order - b.order } return b.interactive - a.interactive; @@ -70,7 +109,9 @@ LinkeditorAccessibility.prototype = { $(links).each(function (k, v) { $(v.link).attr('fb-order', i++); }); - this.linkeditor.hasChanged(); + if (refresh) { + this.linkeditor.hasChanged(); + } this.linkeditor.links.pageMaxOrderIndex = i; }, @@ -93,21 +134,21 @@ LinkeditorAccessibility.prototype = { var $this = this; this.container.html(''); var accessibility = []; - this.normalizeLinksOrder(); - $('#linkeditor-links .link:not(.pendingCreate)').each(function () { + this.normalizeLinksOrder(false); + $(this.orderLinks(this.linkeditor.links.getLinksOfCurrentPage())).each(function () { let type = $(this).attr('fb-type'); let dest = $(this).attr('fb-to'); + let uid = $(this).attr('fb-uid'); if (dest === '') { dest = '' + TRANSLATIONS.empty + ''; } - var l = '
'; - l += '