var LinkeditorLinks = function (linkeditor) {
this.linkeditor = linkeditor;
- this.currentSelection = [];
this.dragLinkPos = null;
this.resizeLinkPos = null;
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 () {
$(l).append('<div class="corners"><div class="nw"></div><div class="n"></div><div class="ne"></div><div class="e"></div><div class="se"></div><div class="s"></div><div class="sw"></div><div class="w"></div></div>')
}
$(l).addClass('selected');
- this.currentSelection.push(l);
+
this.linkeditor.form.updateLinkForm();
this.lastSelectedLink = l;
},
},
deselectAllLinks: function () {
- this.currentSelection = [];
- $(".link.selected").removeClass('selected');
+ this.linkeditor.form.saveFormDataInLink();
this.linkeditor.form.updateLinkForm();
+ $(".link.selected").removeClass('selected');
},
offsetSelectedLinks: function (dim, value) {
},
addLink: function (link) {
- let $this = this;
let change = false;
if (link.uid === undefined) {
link.uid = this.linkeditor.utils.generateUID();
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;