fix race condition
This commit is contained in:
@@ -1289,41 +1289,11 @@ define([
|
|||||||
return isEmoji(emojis[0])? emojis[0]: str[0];
|
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) {
|
$(window.document).on('decryption', function (e) {
|
||||||
var decrypted = e.originalEvent;
|
var decrypted = e.originalEvent;
|
||||||
if (decrypted.callback) {
|
if (decrypted.callback) {
|
||||||
var cb = decrypted.callback;
|
var cb = decrypted.callback;
|
||||||
cb(function (mediaObject) {
|
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; }
|
if (mediaObject.type !== 'download') { return; }
|
||||||
var root = mediaObject.rootElement;
|
var root = mediaObject.rootElement;
|
||||||
if (!root) { return; }
|
if (!root) { return; }
|
||||||
@@ -1390,7 +1360,6 @@ define([
|
|||||||
var $img = $('<media-tag>').appendTo($container);
|
var $img = $('<media-tag>').appendTo($container);
|
||||||
$img.attr('src', src);
|
$img.attr('src', src);
|
||||||
$img.attr('data-crypto-key', 'cryptpad:' + cryptKey);
|
$img.attr('data-crypto-key', 'cryptpad:' + cryptKey);
|
||||||
MediaTag($img[0]);
|
|
||||||
var observer = new MutationObserver(function(mutations) {
|
var observer = new MutationObserver(function(mutations) {
|
||||||
mutations.forEach(function(mutation) {
|
mutations.forEach(function(mutation) {
|
||||||
if (mutation.type === 'childList' && mutation.addedNodes.length) {
|
if (mutation.type === 'childList' && mutation.addedNodes.length) {
|
||||||
@@ -1402,7 +1371,6 @@ define([
|
|||||||
var $image = $img.find('img');
|
var $image = $img.find('img');
|
||||||
var onLoad = function () {
|
var onLoad = function () {
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.src = $image.attr('src');
|
|
||||||
img.onload = function () {
|
img.onload = function () {
|
||||||
var w = img.width;
|
var w = img.width;
|
||||||
var h = img.height;
|
var h = img.height;
|
||||||
@@ -1416,6 +1384,7 @@ define([
|
|||||||
$img.css('flex-direction', 'row');
|
$img.css('flex-direction', 'row');
|
||||||
if (cb) { cb($img); }
|
if (cb) { cb($img); }
|
||||||
};
|
};
|
||||||
|
img.src = $image.attr('src');
|
||||||
};
|
};
|
||||||
if ($image[0].complete) { onLoad(); }
|
if ($image[0].complete) { onLoad(); }
|
||||||
$image.on('load', onLoad);
|
$image.on('load', onLoad);
|
||||||
@@ -1427,6 +1396,7 @@ define([
|
|||||||
childList: true,
|
childList: true,
|
||||||
characterData: false
|
characterData: false
|
||||||
});
|
});
|
||||||
|
MediaTag($img[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user