mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 07:25:46 +01:00
some fixes to composer image upload
This commit is contained in:
@@ -7,18 +7,24 @@ define(['taskbar'], function(taskbar) {
|
|||||||
postContainer: undefined,
|
postContainer: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
var uploadsInProgress = [];
|
|
||||||
|
|
||||||
function createImagePlaceholder(img) {
|
function createImagePlaceholder(img) {
|
||||||
var text = $('.post-window textarea').val(),
|
var text = $('.post-window textarea').val(),
|
||||||
textarea = $('.post-window textarea'),
|
textarea = $('.post-window textarea'),
|
||||||
imgText = "";
|
imgText = "",
|
||||||
|
uuid = $('.post-window .imagedrop').parents('[data-uuid]').attr('data-uuid');
|
||||||
|
|
||||||
text += imgText;
|
text += imgText;
|
||||||
textarea.val(text + " ");
|
textarea.val(text + " ");
|
||||||
uploadsInProgress.push(1);
|
if(!composer.posts[uuid].uploadsInProgress) {
|
||||||
socket.emit("api:posts.uploadImage", img, function(err, data) {
|
composer.posts[uuid].uploadsInProgress = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
composer.posts[uuid].uploadsInProgress.push(1);
|
||||||
|
|
||||||
|
socket.emit("api:posts.uploadImage", img, function(err, data) {
|
||||||
|
if(err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
var currentText = textarea.val();
|
var currentText = textarea.val();
|
||||||
imgText = "";
|
imgText = "";
|
||||||
|
|
||||||
@@ -26,14 +32,13 @@ define(['taskbar'], function(taskbar) {
|
|||||||
textarea.val(currentText.replace(imgText, ""));
|
textarea.val(currentText.replace(imgText, ""));
|
||||||
else
|
else
|
||||||
textarea.val(currentText.replace(imgText, ""));
|
textarea.val(currentText.replace(imgText, ""));
|
||||||
uploadsInProgress.pop();
|
composer.posts[uuid].uploadsInProgress.pop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFile(file) {
|
function loadFile(file) {
|
||||||
var reader = new FileReader(),
|
var reader = new FileReader(),
|
||||||
dropDiv = $('.post-window .imagedrop'),
|
dropDiv = $('.post-window .imagedrop');
|
||||||
uuid = dropDiv.parents('[data-uuid]').attr('data-uuid');
|
|
||||||
|
|
||||||
$(reader).on('loadend', function(e) {
|
$(reader).on('loadend', function(e) {
|
||||||
var bin = this.result;
|
var bin = this.result;
|
||||||
@@ -68,8 +73,9 @@ define(['taskbar'], function(taskbar) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
textarea.on('dragenter', function(e) {
|
textarea.on('dragenter', function(e) {
|
||||||
if(draggingDocument)
|
if(draggingDocument) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
drop.css('top', textarea.position().top + 'px');
|
drop.css('top', textarea.position().top + 'px');
|
||||||
drop.show();
|
drop.show();
|
||||||
|
|
||||||
@@ -133,8 +139,9 @@ define(['taskbar'], function(taskbar) {
|
|||||||
|
|
||||||
document.body.insertBefore(composer.postContainer, taskbar);
|
document.body.insertBefore(composer.postContainer, taskbar);
|
||||||
|
|
||||||
if(config.imgurClientIDSet)
|
if(config.imgurClientIDSet) {
|
||||||
initializeFileReader();
|
initializeFileReader();
|
||||||
|
}
|
||||||
|
|
||||||
socket.on('api:composer.push', function(threadData) {
|
socket.on('api:composer.push', function(threadData) {
|
||||||
if (!threadData.error) {
|
if (!threadData.error) {
|
||||||
@@ -330,7 +337,7 @@ define(['taskbar'], function(taskbar) {
|
|||||||
titleEl.value = titleEl.value.trim();
|
titleEl.value = titleEl.value.trim();
|
||||||
bodyEl.value = bodyEl.value.trim();
|
bodyEl.value = bodyEl.value.trim();
|
||||||
|
|
||||||
if(uploadsInProgress.length) {
|
if(postData.uploadsInProgress && postData.uploadsInProgress.length) {
|
||||||
return app.alert({
|
return app.alert({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
timeout: 2000,
|
timeout: 2000,
|
||||||
@@ -387,7 +394,6 @@ define(['taskbar'], function(taskbar) {
|
|||||||
if (composer.posts[post_uuid]) {
|
if (composer.posts[post_uuid]) {
|
||||||
$(composer.postContainer).find('.imagedrop').hide();
|
$(composer.postContainer).find('.imagedrop').hide();
|
||||||
delete composer.posts[post_uuid];
|
delete composer.posts[post_uuid];
|
||||||
uploadsInProgress.length = 0;
|
|
||||||
composer.minimize();
|
composer.minimize();
|
||||||
taskbar.discard('composer', post_uuid);
|
taskbar.discard('composer', post_uuid);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user