|
|
@ -354,13 +354,40 @@ define([
|
|
|
|
var onLocal = config.onLocal = function () {
|
|
|
|
var onLocal = config.onLocal = function () {
|
|
|
|
if (initializing) { return; }
|
|
|
|
if (initializing) { return; }
|
|
|
|
if (readOnly) { return; }
|
|
|
|
if (readOnly) { return; }
|
|
|
|
console.error('local');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var content = stringifyInner(canvas.toDatalessJSON());
|
|
|
|
var content = stringifyInner(canvas.toDatalessJSON());
|
|
|
|
|
|
|
|
|
|
|
|
APP.patchText(content);
|
|
|
|
APP.patchText(content);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var blobURLToImage = function (url, cb) {
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
xhr.onload = function() {
|
|
|
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
|
|
|
reader.onloadend = function() {
|
|
|
|
|
|
|
|
cb(reader.result);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
reader.readAsDataURL(xhr.response);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
xhr.open('GET', url);
|
|
|
|
|
|
|
|
xhr.responseType = 'blob';
|
|
|
|
|
|
|
|
xhr.send();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var addImageToCanvas = function (img) {
|
|
|
|
|
|
|
|
var w = img.width;
|
|
|
|
|
|
|
|
var h = img.height;
|
|
|
|
|
|
|
|
if (w<h) {
|
|
|
|
|
|
|
|
img.width = img.width * (300/img.height);
|
|
|
|
|
|
|
|
img.height = 300;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
img.height = img.height * (300/img.width);
|
|
|
|
|
|
|
|
img.width = 300;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var cImg = new Fabric.Image(img, { left:0, top:0, angle:0, });
|
|
|
|
|
|
|
|
APP.canvas.add(cImg);
|
|
|
|
|
|
|
|
onLocal();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config.onInit = function (info) {
|
|
|
|
config.onInit = function (info) {
|
|
|
|
updateLocalPalette(palette);
|
|
|
|
updateLocalPalette(palette);
|
|
|
|
readOnly = metadataMgr.getPrivateData().readOnly;
|
|
|
|
readOnly = metadataMgr.getPrivateData().readOnly;
|
|
|
@ -397,14 +424,16 @@ define([
|
|
|
|
var $export = common.createButton('export', true, {}, saveImage);
|
|
|
|
var $export = common.createButton('export', true, {}, saveImage);
|
|
|
|
$rightside.append($export);
|
|
|
|
$rightside.append($export);
|
|
|
|
|
|
|
|
|
|
|
|
common.createButton('savetodrive', true, {}, function () {})
|
|
|
|
if (common.isLoggedIn()) {
|
|
|
|
.click(function () {
|
|
|
|
common.createButton('savetodrive', true, {}, function () {})
|
|
|
|
Cryptpad.prompt(Messages.exportPrompt, document.title + '.png',
|
|
|
|
.click(function () {
|
|
|
|
function (name) {
|
|
|
|
Cryptpad.prompt(Messages.exportPrompt, document.title + '.png',
|
|
|
|
if (name === null || !name.trim()) { return; }
|
|
|
|
function (name) {
|
|
|
|
APP.upload(name);
|
|
|
|
if (name === null || !name.trim()) { return; }
|
|
|
|
});
|
|
|
|
APP.upload(name);
|
|
|
|
}).appendTo($rightside);
|
|
|
|
});
|
|
|
|
|
|
|
|
}).appendTo($rightside);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var $forget = common.createButton('forget', true, {}, function (err) {
|
|
|
|
var $forget = common.createButton('forget', true, {}, function (err) {
|
|
|
|
if (err) { return; }
|
|
|
|
if (err) { return; }
|
|
|
@ -423,34 +452,29 @@ define([
|
|
|
|
reader.onload = function () {
|
|
|
|
reader.onload = function () {
|
|
|
|
var img = new Image();
|
|
|
|
var img = new Image();
|
|
|
|
img.onload = function () {
|
|
|
|
img.onload = function () {
|
|
|
|
var w = img.width;
|
|
|
|
addImageToCanvas(img);
|
|
|
|
var h = img.height;
|
|
|
|
|
|
|
|
if (w<h) {
|
|
|
|
|
|
|
|
img.width = img.width * (300/img.height);
|
|
|
|
|
|
|
|
img.height = 300;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
img.height = img.height * (300/img.width);
|
|
|
|
|
|
|
|
img.width = 300;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var cImg = new Fabric.Image(img, { left:0, top:0, angle:0, });
|
|
|
|
|
|
|
|
APP.canvas.add(cImg);
|
|
|
|
|
|
|
|
onLocal();
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
img.src = reader.result;
|
|
|
|
img.src = reader.result;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
common.createButton('', true)
|
|
|
|
common.createButton('', true)
|
|
|
|
.attr('title', 'Embed an image')
|
|
|
|
.attr('title', Messages.canvas_imageEmbed)
|
|
|
|
|
|
|
|
.removeClass('fa-question').addClass('fa-file-image-o')
|
|
|
|
.click(function () {
|
|
|
|
.click(function () {
|
|
|
|
$('<input>', {type:'file'}).on('change', onUpload).click();
|
|
|
|
$('<input>', {type:'file'}).on('change', onUpload).click();
|
|
|
|
}).appendTo($rightside);
|
|
|
|
}).appendTo($rightside);
|
|
|
|
var fileDialogCfg = {
|
|
|
|
var fileDialogCfg = {
|
|
|
|
onSelect: function (data) {
|
|
|
|
onSelect: function (data) {
|
|
|
|
if (data.type === 'file') {
|
|
|
|
if (data.type === 'file') {
|
|
|
|
var $block = $('#cp-app-whiteboard-media-hidden');
|
|
|
|
|
|
|
|
var mt = '<media-tag src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '"></media-tag>';
|
|
|
|
var mt = '<media-tag src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '"></media-tag>';
|
|
|
|
$block.append(mt);
|
|
|
|
common.displayMediatagImage($(mt), function (err, $image) {
|
|
|
|
|
|
|
|
blobURLToImage($image.attr('src'), function (imgSrc) {
|
|
|
|
|
|
|
|
var img = new Image();
|
|
|
|
|
|
|
|
img.onload = function () { addImageToCanvas(img); };
|
|
|
|
|
|
|
|
img.src = imgSrc;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -463,7 +487,10 @@ define([
|
|
|
|
}).click(function () {
|
|
|
|
}).click(function () {
|
|
|
|
var pickerCfg = {
|
|
|
|
var pickerCfg = {
|
|
|
|
types: ['file'],
|
|
|
|
types: ['file'],
|
|
|
|
where: ['root']
|
|
|
|
where: ['root'],
|
|
|
|
|
|
|
|
filter: {
|
|
|
|
|
|
|
|
fileType: ['image/']
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
common.openFilePicker(pickerCfg);
|
|
|
|
common.openFilePicker(pickerCfg);
|
|
|
|
}).appendTo($rightside);
|
|
|
|
}).appendTo($rightside);
|
|
|
@ -509,7 +536,6 @@ define([
|
|
|
|
Title.updateTitle(Cryptpad.initialName || Title.defaultTitle);
|
|
|
|
Title.updateTitle(Cryptpad.initialName || Title.defaultTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
if (newDoc) {
|
|
|
|
if (newDoc) {
|
|
|
|
canvas.loadFromJSON(newDoc, waitFor(function () {
|
|
|
|
canvas.loadFromJSON(newDoc, waitFor(function () {
|
|
|
|