|
|
@ -11,10 +11,12 @@ define([
|
|
|
|
'/common/hyperscript.js',
|
|
|
|
'/common/hyperscript.js',
|
|
|
|
'/customize/messages.js',
|
|
|
|
'/customize/messages.js',
|
|
|
|
'/customize/pages.js',
|
|
|
|
'/customize/pages.js',
|
|
|
|
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
|
|
|
|
'/common/media-tag.js',
|
|
|
|
|
|
|
|
|
|
|
|
'/bower_components/file-saver/FileSaver.min.js',
|
|
|
|
'/bower_components/file-saver/FileSaver.min.js',
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
|
|
|
], function ($, ApiConfig, FileCrypto, MakeBackup, Thumb, UI, UIElements, Util, Hash, h, Messages, Pages) {
|
|
|
|
], function ($, ApiConfig, FileCrypto, MakeBackup, Thumb, UI, UIElements, Util, Hash, h, Messages, Pages, nThen, MT) {
|
|
|
|
var Nacl = window.nacl;
|
|
|
|
var Nacl = window.nacl;
|
|
|
|
var module = {};
|
|
|
|
var module = {};
|
|
|
|
|
|
|
|
|
|
|
@ -312,7 +314,11 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return manualStore;
|
|
|
|
return manualStore;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var fileUploadModal = function (defaultFileName, cb) {
|
|
|
|
|
|
|
|
|
|
|
|
Messages.upload_modal_alt = "Alt text"; // XXX
|
|
|
|
|
|
|
|
Messages.upload_addOptionalAlt = "Add descriptive text (optional)"; // XXX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fileUploadModal = function (defaultFileName, cb, preview) {
|
|
|
|
var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(defaultFileName) || [];
|
|
|
|
var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(defaultFileName) || [];
|
|
|
|
var ext = parsedName[2] || "";
|
|
|
|
var ext = parsedName[2] || "";
|
|
|
|
|
|
|
|
|
|
|
@ -321,9 +327,15 @@ define([
|
|
|
|
// Ask for name, password and owner
|
|
|
|
// Ask for name, password and owner
|
|
|
|
var content = h('div', [
|
|
|
|
var content = h('div', [
|
|
|
|
h('h4', Messages.upload_modal_title),
|
|
|
|
h('h4', Messages.upload_modal_title),
|
|
|
|
|
|
|
|
(preview? h('div#cp-upload-preview-container', preview): undefined),
|
|
|
|
UIElements.setHTML(h('label', {for: 'cp-upload-name'}),
|
|
|
|
UIElements.setHTML(h('label', {for: 'cp-upload-name'}),
|
|
|
|
Messages._getKey('upload_modal_filename', [ext])),
|
|
|
|
Messages._getKey('upload_modal_filename', [ext])),
|
|
|
|
h('input#cp-upload-name', {type: 'text', placeholder: defaultFileName, value: defaultFileName}),
|
|
|
|
h('input#cp-upload-name', {type: 'text', placeholder: defaultFileName, value: defaultFileName}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h('label', {for: 'cp-upload-alt'}, Messages.upload_addOptionalAlt), // XXX alt text for uploads
|
|
|
|
|
|
|
|
h('input#cp-upload-alt', {type: 'text', placeholder: Messages.upload_modal_alt}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h('label', {for: 'cp-upload-password'}, Messages.addOptionalPassword),
|
|
|
|
h('label', {for: 'cp-upload-password'}, Messages.addOptionalPassword),
|
|
|
|
UI.passwordInput({id: 'cp-upload-password'}),
|
|
|
|
UI.passwordInput({id: 'cp-upload-password'}),
|
|
|
|
h('span', {
|
|
|
|
h('span', {
|
|
|
@ -335,7 +347,8 @@ define([
|
|
|
|
manualStore
|
|
|
|
manualStore
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$(content).find('#cp-upload-owned').on('change', function () {
|
|
|
|
var $content = $(content);
|
|
|
|
|
|
|
|
$content.find('#cp-upload-owned').on('change', function () {
|
|
|
|
var val = Util.isChecked($(content).find('#cp-upload-owned'));
|
|
|
|
var val = Util.isChecked($(content).find('#cp-upload-owned'));
|
|
|
|
if (val) {
|
|
|
|
if (val) {
|
|
|
|
$(content).find('#cp-upload-store').prop('checked', true).prop('disabled', true);
|
|
|
|
$(content).find('#cp-upload-store').prop('checked', true).prop('disabled', true);
|
|
|
@ -348,8 +361,9 @@ define([
|
|
|
|
if (!yes) { return void cb(); }
|
|
|
|
if (!yes) { return void cb(); }
|
|
|
|
|
|
|
|
|
|
|
|
// Get the values
|
|
|
|
// Get the values
|
|
|
|
var newName = $(content).find('#cp-upload-name').val();
|
|
|
|
var newName = $content.find('#cp-upload-name').val();
|
|
|
|
var password = $(content).find('#cp-upload-password').val() || undefined;
|
|
|
|
var password = $content.find('#cp-upload-password').val() || undefined;
|
|
|
|
|
|
|
|
var alt = $content.find('#cp-upload-alt').val() || undefined;
|
|
|
|
var owned = Util.isChecked($(content).find('#cp-upload-owned'));
|
|
|
|
var owned = Util.isChecked($(content).find('#cp-upload-owned'));
|
|
|
|
var forceSave = owned || Util.isChecked($(content).find('#cp-upload-store'));
|
|
|
|
var forceSave = owned || Util.isChecked($(content).find('#cp-upload-store'));
|
|
|
|
|
|
|
|
|
|
|
@ -366,7 +380,8 @@ define([
|
|
|
|
name: newName,
|
|
|
|
name: newName,
|
|
|
|
password: password,
|
|
|
|
password: password,
|
|
|
|
owned: owned,
|
|
|
|
owned: owned,
|
|
|
|
forceSave: forceSave
|
|
|
|
forceSave: forceSave,
|
|
|
|
|
|
|
|
alt: alt,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -437,6 +452,8 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var thumb;
|
|
|
|
var thumb;
|
|
|
|
|
|
|
|
var preview;
|
|
|
|
|
|
|
|
var alt;
|
|
|
|
var file_arraybuffer;
|
|
|
|
var file_arraybuffer;
|
|
|
|
var name = file.name;
|
|
|
|
var name = file.name;
|
|
|
|
var password;
|
|
|
|
var password;
|
|
|
@ -447,6 +464,7 @@ define([
|
|
|
|
var metadata = {
|
|
|
|
var metadata = {
|
|
|
|
name: name,
|
|
|
|
name: name,
|
|
|
|
type: type,
|
|
|
|
type: type,
|
|
|
|
|
|
|
|
alt: alt,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (thumb) { metadata.thumbnail = thumb; }
|
|
|
|
if (thumb) { metadata.thumbnail = thumb; }
|
|
|
|
queue.push({
|
|
|
|
queue.push({
|
|
|
@ -486,8 +504,9 @@ define([
|
|
|
|
password = obj.password;
|
|
|
|
password = obj.password;
|
|
|
|
owned = obj.owned;
|
|
|
|
owned = obj.owned;
|
|
|
|
forceSave = obj.forceSave;
|
|
|
|
forceSave = obj.forceSave;
|
|
|
|
|
|
|
|
alt = obj.alt;
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
});
|
|
|
|
}, preview);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -495,11 +514,20 @@ define([
|
|
|
|
if (e) { console.error(e); }
|
|
|
|
if (e) { console.error(e); }
|
|
|
|
file_arraybuffer = buffer;
|
|
|
|
file_arraybuffer = buffer;
|
|
|
|
if (!Thumb.isSupportedType(file)) { return getName(); }
|
|
|
|
if (!Thumb.isSupportedType(file)) { return getName(); }
|
|
|
|
// make a resized thumbnail from the image..
|
|
|
|
nThen(function (w) {
|
|
|
|
Thumb.fromBlob(file, function (e, thumb64) {
|
|
|
|
// make a resized thumbnail from the image..
|
|
|
|
if (e) { console.error(e); }
|
|
|
|
Thumb.fromBlob(file, w(function (e, thumb64) {
|
|
|
|
if (!thumb64) { return getName(); }
|
|
|
|
if (e) { console.error(e); }
|
|
|
|
thumb = thumb64;
|
|
|
|
if (!thumb64) { return; }
|
|
|
|
|
|
|
|
thumb = thumb64;
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
MT.preview(buffer, {
|
|
|
|
|
|
|
|
type: file.type,
|
|
|
|
|
|
|
|
}, void 0, w(function (err, el) {
|
|
|
|
|
|
|
|
if (err) { return void console.error(err); }
|
|
|
|
|
|
|
|
preview = el;
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}).nThen(function () {
|
|
|
|
getName();
|
|
|
|
getName();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|