Remove support for old media-tag

pull/1/head
yflory 7 years ago
parent eac7d38655
commit 574d99f9db

@ -18,8 +18,10 @@ define([
var UIElements = {}; var UIElements = {};
// Configure MediaTags to use our local viewer // Configure MediaTags to use our local viewer
if (MediaTag && MediaTag.PdfPlugin) { if (MediaTag) {
MediaTag.PdfPlugin.viewer = '/common/pdfjs/web/viewer.html'; MediaTag.setDefaultConfig('pdf', {
viewer: '/common/pdfjs/web/viewer.html'
});
} }
UIElements.updateTags = function (common, href) { UIElements.updateTags = function (common, href) {
@ -1034,52 +1036,6 @@ define([
// Avatars // Avatars
// Enable mediatags
$(window.document).on('decryption', function (e) {
var decrypted = e.originalEvent;
if (decrypted.callback) {
var cb = decrypted.callback;
cb(function (mediaObject) {
var root = mediaObject.element;
if (!root) { return; }
if (mediaObject.type === 'image') {
$(root).data('blob', decrypted.blob);
}
if (mediaObject.type !== 'download') { return; }
var metadata = decrypted.metadata;
var title = '';
var size = 0;
if (metadata && metadata.name) {
title = metadata.name;
}
if (decrypted.blob) {
size = decrypted.blob.size;
}
var sizeMb = Util.bytesToMegabytes(size);
var $btn = $(root).find('button');
$btn.addClass('btn btn-success')
.attr('type', 'download')
.html(function () {
var text = Messages.download_mt_button + '<br>';
if (title) {
text += '<b>' + Util.fixHTML(title) + '</b><br>';
}
if (size) {
text += '<em>' + Messages._getKey('formattedMB', [sizeMb]) + '</em>';
}
return text;
});
});
}
});
UIElements.displayMediatagImage = function (Common, $tag, cb) { UIElements.displayMediatagImage = function (Common, $tag, cb) {
if (!$tag.length || !$tag.is('media-tag')) { return void cb('NOT_MEDIATAG'); } if (!$tag.length || !$tag.is('media-tag')) { return void cb('NOT_MEDIATAG'); }
var observer = new MutationObserver(function(mutations) { var observer = new MutationObserver(function(mutations) {

@ -83,8 +83,9 @@
}, },
download: function (metadata, url, content, cfg, cb) { download: function (metadata, url, content, cfg, cb) {
var btn = document.createElement('button'); var btn = document.createElement('button');
btn.setAttribute('class', 'btn btn-success');
btn.innerHTML = cfg.download.text + '<br>' + btn.innerHTML = cfg.download.text + '<br>' +
metadata.name ? '<b>' + fixHTML(metadata.name) + '</b>' : ''; (metadata.name ? '<b>' + fixHTML(metadata.name) + '</b>' : '');
btn.addEventListener('click', function () { btn.addEventListener('click', function () {
saveFile(content, url, metadata.name); saveFile(content, url, metadata.name);
}); });
@ -317,11 +318,6 @@
addMissingConfig(cfg, config); addMissingConfig(cfg, config);
// Add support for old mediatag library
if (!cfg.pdf.viewer && init.PdfPlugin && init.PdfPlugin.viewer) {
cfg.pdf.viewer = init.PdfPlugin.viewer;
}
// Handle jQuery elements // Handle jQuery elements
if (typeof(el) === "object" && el.jQuery) { el = el[0]; } if (typeof(el) === "object" && el.jQuery) { el = el[0]; }
@ -424,7 +420,9 @@
// Add the cache as a property of MediaTag // Add the cache as a property of MediaTag
cache = init.__Cryptpad_Cache = {}; cache = init.__Cryptpad_Cache = {};
init.PdfPlugin = {}; init.setDefaultConfig = function (key, value) {
config[key] = value;
};
return init; return init;
})); }));

File diff suppressed because one or more lines are too long

@ -37,6 +37,9 @@ define([
var Nacl = window.nacl; var Nacl = window.nacl;
var APP = window.APP = {}; var APP = window.APP = {};
MediaTag.setDefaultConfig('download', {
text: Messages.download_mt_button
});
var andThen = function (common) { var andThen = function (common) {
var $appContainer = $('#cp-app-file-content'); var $appContainer = $('#cp-app-file-content');
@ -130,32 +133,17 @@ define([
$mt.attr('data-crypto-key', 'cryptpad:'+cryptKey); $mt.attr('data-crypto-key', 'cryptpad:'+cryptKey);
var rightsideDisplayed = false; var rightsideDisplayed = false;
$(window.document).on('decryption', function (e) {
/* FIXME
we're listening for decryption events and assuming that only
the main media-tag exists. In practice there is also your avatar
and there could be other things in the future, so we should
figure out a generic way target media-tag decryption events.
*/
var decrypted = e.originalEvent;
if (decrypted.callback) {
decrypted.callback();
}
MediaTag($mt[0]).on('complete', function (decrypted) {
$dlview.show(); $dlview.show();
$dlform.hide(); $dlform.hide();
var $dlButton = $dlview.find('media-tag button'); var $dlButton = $dlview.find('media-tag button');
if (ev) { $dlButton.click(); } if (ev) { $dlButton.click(); }
$dlButton.addClass('btn btn-success');
var text = Messages.download_mt_button + '<br>';
text += '<b>' + Util.fixHTML(title) + '</b><br>';
text += '<em>' + Messages._getKey('formattedMB', [sizeMb]) + '</em>';
$dlButton.html(text);
if (!rightsideDisplayed) { if (!rightsideDisplayed) {
toolbar.$rightside toolbar.$rightside
.append(common.createButton('export', true, {}, function () { .append(common.createButton('export', true, {}, function () {
saveAs(decrypted.blob, decrypted.metadata.name); saveAs(decrypted.content, decrypted.metadata.name);
})); }));
rightsideDisplayed = true; rightsideDisplayed = true;
} }
@ -178,42 +166,12 @@ define([
} else { } else {
cb(); cb();
} }
}) }).on('progress', function (data) {
.on('decryptionError', function (e) { var p = data.progress +'%';
var error = e.originalEvent;
//UI.alert(error.message);
cb(error.message);
})
.on('decryptionProgress', function (e) {
var progress = e.originalEvent;
var p = progress.percent +'%';
$progress.width(p); $progress.width(p);
}).on('error', function (err) {
console.error(err);
}); });
/**
* Allowed mime types that have to be set for a rendering after a decryption.
*
* @type {Array}
*/
var allowedMediaTypes = [
'image/png',
'image/jpeg',
'image/jpg',
'image/gif',
'audio/mp3',
'audio/ogg',
'audio/wav',
'audio/webm',
'video/mp4',
'video/ogg',
'video/webm',
'application/pdf',
'application/dash+xml',
'download'
];
MediaTag.CryptoFilter.setAllowedMediaTypes(allowedMediaTypes);
MediaTag($mt[0]);
}; };
var todoBigFile = function (sizeMb) { var todoBigFile = function (sizeMb) {

@ -43,16 +43,6 @@ define([
_onRefresh: [] _onRefresh: []
}; };
// Decryption event for avatar mediatag (TODO not needed anymore?)
$(window.document).on('decryption', function (e) {
var decrypted = e.originalEvent;
if (decrypted.callback) { decrypted.callback(); }
})
.on('decryptionError', function (e) {
var error = e.originalEvent;
UI.alert(error.message);
});
$(window).click(function () { $(window).click(function () {
$('.cp-dropdown-content').hide(); $('.cp-dropdown-content').hide();
}); });

Loading…
Cancel
Save