From c3ba7cd792663bef571a0f94bee4fbd15963a631 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 13 Jul 2017 12:55:08 +0200 Subject: [PATCH] fix race condition --- www/common/cryptpad-common.js | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 26d5b6699..b2e1ceeff 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1289,41 +1289,11 @@ define([ return isEmoji(emojis[0])? emojis[0]: str[0]; }; - var cropImageToSquare = function (container, cb) { - var $container = $(container); - var $image = $(container).find('img'); - - var onLoad = function () { - var img = new Image(); - img.src = $image.attr('src'); - img.onload = function () { - if (img.width > img.height) { - $image.css('max-height', '100%'); - $container.css('flex-direction', 'column'); - if (cb) { cb($image); } - return; - } - $image.css('max-width', '100%'); - $container.css('flex-direction', 'row'); - if (cb) { cb($container); } - }; - }; - - if ($image[0].complete) { return void onLoad(); } - $image.on('load', onLoad); - }; - $(window.document).on('decryption', function (e) { var decrypted = e.originalEvent; if (decrypted.callback) { var cb = decrypted.callback; cb(function (mediaObject) { - if (mediaObject.type === 'image') { - var $parent = $(mediaObject.element).parent(); - if ($parent.hasClass('avatar')) { - return cropImageToSquare(mediaObject.element); - } - } if (mediaObject.type !== 'download') { return; } var root = mediaObject.rootElement; if (!root) { return; } @@ -1390,7 +1360,6 @@ define([ var $img = $('').appendTo($container); $img.attr('src', src); $img.attr('data-crypto-key', 'cryptpad:' + cryptKey); - MediaTag($img[0]); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === 'childList' && mutation.addedNodes.length) { @@ -1402,7 +1371,6 @@ define([ var $image = $img.find('img'); var onLoad = function () { var img = new Image(); - img.src = $image.attr('src'); img.onload = function () { var w = img.width; var h = img.height; @@ -1416,6 +1384,7 @@ define([ $img.css('flex-direction', 'row'); if (cb) { cb($img); } }; + img.src = $image.attr('src'); }; if ($image[0].complete) { onLoad(); } $image.on('load', onLoad); @@ -1427,6 +1396,7 @@ define([ childList: true, characterData: false }); + MediaTag($img[0]); }); } };