--- /dev/null
+function LinkeditorClipboard(linkeditor) {
+ this.linkeditor = linkeditor;
+ this.content = '';
+ this._isEmpty = true;
+
+ this.init();
+}
+
+LinkeditorClipboard.prototype = {
+ init: function () {
+
+ },
+
+ enabled: function () {
+ return !this.linkeditor.utils.isFirefox();
+ },
+
+ empty: function () {
+ this.set('');
+ },
+
+ get: function (callback) {
+ let $this = this;
+ if (this.enabled()) {
+ navigator.clipboard.read()
+ .then(items => {
+ items[0].getType('text/html').then(blob => {
+ blob.text().then(text => {
+ if (text.indexOf('<fluidbooklinks>') === 0) {
+ $this.content = text;
+ callback($this.content);
+ }
+ });
+ });
+ })
+ .catch(err => {
+ console.error('Failed to read clipboard contents: ', err);
+ });
+ } else {
+ callback(this.content);
+ }
+ },
+
+ isEmtpy: function () {
+ if (!this.enabled()) {
+ return this.content === '';
+ }
+ return this._isEmpty;
+ },
+
+ checkEmpty: function () {
+ if (!this.enabled()) {
+ return;
+ }
+ },
+
+ set: function (content) {
+ this.content = content;
+
+ if (this.enabled()) {
+ const type = "text/html";
+ const blob = new Blob(['<fluidbooklinks>' + this.content + '</fluidbooklinks>'], {type});
+ const data = [new ClipboardItem({[type]: blob})];
+
+ navigator.clipboard.write(data).then(
+ () => {
+ /* success */
+ },
+ () => {
+ /* failure */
+ }
+ );
+ }
+ },
+}
+
+module.exports = LinkeditorClipboard;
import LinkeditorPopup from './linkeditor.popup';
import LinkeditorLayers from "./linkeditor.layers";
import LinkeditorUndo from './linkeditor.undo';
+import LinkeditorClipboard from './linkeditor.clipboard';
window.$ = window.jQuery = require('jquery');
window.key = require('keymaster-reloaded');
init: function () {
var $this = this;
+ this.clipboard = new LinkeditorClipboard(this);
this.utils = new LinkeditorUtils(this);
this.toolbar = new LinkeditorToolbar(this);
this.resize = new LinkeditorResize(this);
var selection = $(".link.selected");
var multiple = selection.length > 1;
var hasSelection = selection.length > 0;
- var hasClipboard = $("#linkeditor-clipboard").find('.link').length > 0;
res.items = {
'select_all': {
},
paste: function (frommouse) {
- var linksInClipboard = $("#linkeditor-clipboard .link");
+ let $this = this;
+ this.linkeditor.clipboard.get(function (content) {
+ $this._paste(content, frommouse);
+ })
+ },
+
+ _paste: function (content, frommouse) {
+ var clipboard = $('<div />').html(content);
+
+ var linksInClipboard = clipboard.find(".link");
if (!linksInClipboard.length) {
return;
}
return;
}
var $this = this;
- this.emptyClipboard();
let nb = 0;
+ var clipboardContent = $('<div />');
$.each(selection, function () {
var item = $(this);
clone = $(item).clone();
if (cut) {
$this.deleteLink(item, false);
}
- $("#linkeditor-clipboard").append(clone);
+ clipboardContent.append(clone);
nb++;
});
+ this.linkeditor.clipboard.set(clipboardContent.html());
+
if (cut) {
this.linkeditor.form.emptyForm();
this.linkeditor.hasChanged();
this.linkeditor.notification(msg);
},
- emptyClipboard: function () {
- $("#linkeditor-clipboard").html('');
- },
fixDriftedLinks: function () {
var $this = this;
},
isfocusOnFormItem: function () {
return $(document.activeElement).is('input[type="text"],input[type="email"],input[type="number"],input[type="tel"],input[type="search"],textarea,select');
+ },
+
+ isFirefox: function () {
+ return navigator.userAgent.search("Firefox") >= 0;
}
};