this.lastSelectedLink = null;
this.lastSelectedLinkData = {'width': 100, 'height': 100, 'to': '', type: '2', target: '_blank'};
+ this.contextMenuPosition = null;
+
this.init();
}
return false;
});
this.key('ctrl+v', function () {
- $this.pasteInPlace();
+ $this.paste();
return false;
});
this.key('del', function () {
$.contextMenu({
selector: '#linkeditor-canvas,.link,#linkeditor-panel-layers, #linkeditor-panel-layers label',
events: {
+ show: function (e) {
+ $this.contextMenuPosition = {x: $this.linkeditor.mx, y: $this.linkeditor.my};
+ },
preShow: function (e) {
if ($(e).is('.link:not(.selected)')) {
$this.deselectAllLinks();
isHtmlName: true,
name: TRANSLATIONS.paste_here,
callback: function () {
- $this.pasteHere();
+ $this.paste($this.contextMenuPosition);
},
};
res.items.paste_in_place = {
isHtmlName: true,
name: TRANSLATIONS.paste_in_place + ' <kbd>Ctrl+V</kbd>',
callback: function () {
- $this.pasteInPlace();
+ $this.paste();
},
};
}
var $this = this;
key(shortcut, function (event, handler) {
if ($this.allowsKeyboardShortcut(shortcut)) {
- scope(event, handler);
+ var res = scope(event, handler);
+ return res;
}
- })
+ });
},
copy: function () {
- this.copySelectionToClipboard(true);
+ this.copySelectionToClipboard(false);
},
cut: function () {
- this.copySelectionToClipboard(false);
+ this.copySelectionToClipboard(true);
},
- pasteInPlace: function () {
+ paste: function (frommouse) {
var linksInClipboard = $("#linkeditor-clipboard .link");
if (!linksInClipboard.length) {
return;
}
var $this = this;
+ let offset = {x: 0, y: 0};
+ if (frommouse !== undefined) {
+ // Base mouse position should be the start of context menu (and not the mouse position when we click on the Paste in place item menu)
+ offset = this.linkeditor.globalToFluidbook(frommouse.x, frommouse.y, this.linkeditor.single);
+
+ var top = 1000000;
+ var left = 1000000;
+ // Get the coordinates of the top left corner of the links in clipboard
+ $(linksInClipboard).each(function () {
+ top = Math.min(parseFloat($(this).attr('fb-top')), top);
+ left = Math.min(parseFloat($(this).attr('fb-left')), left);
+ });
+ // The links will be pasted in order the links will be disposed as initially but starting from the mouse current position
+ offset.x -= left;
+ offset.y -= top;
+ }
+
$(linksInClipboard).each(function () {
- var item = $(this).clone();
- if ($this.hasUIDLink($(item).attr('fb-uid'))) {
- var uid = $this.linkeditor.utils.generateUID();
- $(item).attr('fb-uid', uid);
- }
- $("#linkeditor-links").append(item);
+ let data = $this._duplicateLink($(this), false);
+
+ data.top += offset.y;
+ data.left += offset.x;
+
+ $this.addLink(data);
});
- },
- pasteHere: function () {
- this.pasteInPlace();
+ this.linkeditor.hasChanged();
+ this.updateLayers();
},
hasUIDLink: function (uid) {
- return true;
+ return LINKS[uid] !== undefined && LINKS[uid] !== null;
},
- copySelectionToClipboard: function (clone) {
+ copySelectionToClipboard: function (cut) {
+
var selection = this.getCurrentSelection();
if (selection.length === 0) {
return;
}
+ var $this = this;
this.emptyClipboard();
$.each(selection, function () {
var item = $(this);
- if (clone) {
- item = $(item).clone();
+ clone = $(item).clone();
+ if (cut) {
+ $this.deleteLink(item, false);
}
- $("#linkeditor-clipboard").append(item);
+ $("#linkeditor-clipboard").append(clone);
});
+
+ if (cut) {
+ this.linkeditor.form.emptyForm();
+ this.linkeditor.hasChanged();
+ this.updateLayers();
+ }
},
emptyClipboard: function () {
});
},
-
allowsKeyboardShortcut: function (shortcut) {
if (shortcut === 'pageup' || shortcut === 'pagedown' || shortcut === 'enter') {
return true;
loadLinks: function (page, side) {
let $this = this;
$.each(LINKS, function (uid, link) {
+ if ($('#linkeditor-links [fb-uid="' + uid + '"]').length > 0) {
+ return;
+ }
if (!$this.linkeditor.single && page % 2 === 1 && link.page % 2 === 0 && link.left > $this.linkeditor.pw) {
link.page++;
link.left -= $this.linkeditor.pw;
link.page--;
link.left = parseInt(link.left) + $this.linkeditor.pw;
}
- $this.addLink(link, side);
+ $this.addLink(link);
});
this.updateLayers();
},
let change = false;
if (link.uid === undefined) {
link.uid = this.linkeditor.utils.generateUID();
- LINKS[link.uid] = link;
change = true;
+ } else if (!this.hasUIDLink(link.uid)) {
+ console.log('::)', link);
+ change = true;
+ }
+ if (change) {
+ LINKS[link.uid] = link;
}
link.origuid = link.uid;
});
},
- _duplicateLink: function () {
- var data = this.lastSelectedLinkData;
+ _duplicateLink: function (link, pos) {
+ var data;
+ if (link === undefined) {
+ data = this.lastSelectedLinkData;
+ } else {
+ data = this.getLinkData(link);
+ }
data.page = this.linkeditor.currentPage;
- var pos = this.linkeditor.globalToFluidbook(this.linkeditor.mx, this.linkeditor.my, this.linkeditor.single);
- data.left = pos.x;
- data.top = pos.y;
- delete data.uid;
+ if (pos === undefined) {
+ pos = this.linkeditor.globalToFluidbook(this.linkeditor.mx, this.linkeditor.my, this.linkeditor.single);
+ }
+ if (pos !== false) {
+ data.left = pos.x;
+ data.top = pos.y;
+ } else {
+ data.left = parseFloat(data.left);
+ data.top = parseFloat(data.top);
+ }
+ if (this.hasUIDLink(data.uid)) {
+ delete data.uid;
+ }
return data;
},
duplicateLinkClick: function () {
- var data = this._duplicateLink();
-
- let link = this.addLink(data);
+ let link = this.addLink(this._duplicateLink());
this.deselectAllLinks();
this.selectLink($(link));