From: Vincent Vanwaelscappel Date: Wed, 30 Nov 2022 13:31:26 +0000 (+0100) Subject: wait #5619 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=fbf214e3aaf9cdc029b6f9e573bef551db4d1cf4;p=fluidbook-toolbox.git wait #5619 @1.5 --- diff --git a/resources/linkeditor/js/linkeditor.form.js b/resources/linkeditor/js/linkeditor.form.js index c37bd8eee..6672fcbcf 100644 --- a/resources/linkeditor/js/linkeditor.form.js +++ b/resources/linkeditor/js/linkeditor.form.js @@ -55,6 +55,15 @@ LinkeditorForm.prototype = { this.unmaskChangeEvent(); }, + focusAndSelectDestinationField: function () { + var f = $('#linkeditor-panel-form [name="to"]').get(0); + f.focus(); + f.select(); + setTimeout(function () { + f.select(); + }, 1); + }, + emptyForm: function () { $('#linkeditor-panel-form .select2_from_array').each(function () { $(this).select2('close'); @@ -81,7 +90,6 @@ LinkeditorForm.prototype = { this.updateFormData(form); container.append(form); - this.initSelect2(); }, diff --git a/resources/linkeditor/js/linkeditor.js b/resources/linkeditor/js/linkeditor.js index ef6918d0c..229b8f78e 100644 --- a/resources/linkeditor/js/linkeditor.js +++ b/resources/linkeditor/js/linkeditor.js @@ -18,10 +18,19 @@ import LinkeditorPanels from './linkeditor.panels'; import LinkeditorForm from './linkeditor.form'; window.$ = window.jQuery = require('jquery'); -window.key = require('keymaster'); +window.key = require('keymaster-reloaded'); window.tippy = tippy; window.Noty = Noty; +window.key.filter = function (event) { + let tagName = (event.target || event.srcElement).tagName; + //let field=tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA'; + if (tagName === 'TEXTAREA' && event.keyCode === 13) { + return false; + } + return true; +}; + require('jquery.scrollto'); require('jquery-contextmenu'); diff --git a/resources/linkeditor/js/linkeditor.links.js b/resources/linkeditor/js/linkeditor.links.js index f5f41992e..6bdcb4780 100644 --- a/resources/linkeditor/js/linkeditor.links.js +++ b/resources/linkeditor/js/linkeditor.links.js @@ -1,7 +1,6 @@ var LinkeditorLinks = function (linkeditor) { this.linkeditor = linkeditor; - this.currentSelection = []; this.dragLinkPos = null; this.resizeLinkPos = null; @@ -69,15 +68,71 @@ LinkeditorLinks.prototype = { key('ctrl+down', function () { $this.offsetSelectedLinks('top', 10); }); + key('pageup', function () { + $this.selectPreviousLink(); + }); + key('pagedown', function () { + $this.selectNextLink(); + }); + key('enter', function () { + if ($(document.activeElement).is('input[name="to"]')) { + $this.selectNextLink(); + return false; + } + }); setInterval(function () { $this.checkLastSelectedLink(); }, 250); }, + selectLinkAndSelectToField(link) { + if ($(link).length === 0) { + return; + } + this.deselectAllLinks(); + this.selectLink($(link)); + this.linkeditor.form.focusAndSelectDestinationField(); + }, + + selectFirstLink: function () { + this.selectLinkAndSelectToField($('#linkeditor-links .link:eq(0)')); + }, + + selectLastLink: function () { + this.selectLinkAndSelectToField($('#linkeditor-links .link:last')); + }, + + selectPreviousLink: function () { + if (this.getCurrentSelection().length === 0) { + return this.selectLastLink(); + } + return this.selectLinkAndSelectToField(this._getLinkByIndexOffset(-1)); + }, + + selectNextLink: function () { + if (this.getCurrentSelection().length === 0) { + return this.selectFirstLink(); + } + return this.selectLinkAndSelectToField(this._getLinkByIndexOffset(1)); + }, + + _getLinkByIndexOffset(way) { + let allLinks = this.getCurrentLinksOnPage(); + let index = this.getFirstLinkInSelection().index(); + let nb = allLinks.length; + let n = (nb + index + way) % nb; + return allLinks.eq(n); + }, + mouseUp: function () { this.stopDragLink(); this.stopResizeLink(); + this.cleanPendingCreateLink(); + }, + + cleanPendingCreateLink() { + $('.pendingCreate').remove(); }, createLinkDrag: function () { @@ -290,7 +345,7 @@ LinkeditorLinks.prototype = { $(l).append('
') } $(l).addClass('selected'); - this.currentSelection.push(l); + this.linkeditor.form.updateLinkForm(); this.lastSelectedLink = l; }, @@ -316,9 +371,9 @@ LinkeditorLinks.prototype = { }, deselectAllLinks: function () { - this.currentSelection = []; - $(".link.selected").removeClass('selected'); + this.linkeditor.form.saveFormDataInLink(); this.linkeditor.form.updateLinkForm(); + $(".link.selected").removeClass('selected'); }, offsetSelectedLinks: function (dim, value) { @@ -369,7 +424,6 @@ LinkeditorLinks.prototype = { }, addLink: function (link) { - let $this = this; let change = false; if (link.uid === undefined) { link.uid = this.linkeditor.utils.generateUID(); @@ -434,6 +488,18 @@ LinkeditorLinks.prototype = { this.linkeditor.hasChanged(); }, + getCurrentSelection: function () { + return $('.link.selected:not(.pendingCreate)'); + }, + + getFirstLinkInSelection: function () { + return this.getCurrentSelection().eq(0); + }, + + getCurrentLinksOnPage() { + return $('.link:not(.pendingCreate)'); + }, + deleteLink: function (link, triggerChange) { if (triggerChange === undefined) { triggerChange = true;