From 04a28433ae2ceb753513a7c6a9acc6987cf17fd1 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 4 Jul 2017 10:21:29 +0200 Subject: [PATCH] replace inner content of media tag download buttons --- www/common/cryptpad-common.js | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index b0d6ea424..f511b5c5e 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1198,8 +1198,39 @@ define([ var decrypted = e.originalEvent; if (decrypted.callback) { var cb = decrypted.callback; - decrypted.callback = undefined; - cb(); + cb(function (mediaObject) { + if (mediaObject.type !== 'download') { return; } + var root = mediaObject.rootElement; + if (!root) { 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 = Cryptpad.bytesToMegabytes(size); + + var $btn = $(root).find('button'); + $btn.addClass('btn btn-primary btn-success') + .attr('type', 'download') + .html(function (i, html) { + var text = Messages.download_mt_button + '
'; + if (title) { + text += '' + Cryptpad.fixHTML(title) + '
'; + } + if (size) { + text += '' + Messages._getKey('formattedMB', [sizeMb]) + ''; + } + return text; + }); + }); } }); common.avatarAllowedTypes = [