Merge branch 'master' into develop

isekai-main
Barış Soner Uşaklı 2 years ago
commit de2f76bbd3

@ -55,7 +55,7 @@ define('forum/chats', [
Chats.initialised = true; Chats.initialised = true;
messages.scrollToBottom($('.expanded-chat ul.chat-content')); messages.scrollToBottom($('.expanded-chat ul.chat-content'));
messages.wrapImagesInLinks($('.expanded-chat ul.chat-content'));
search.init(); search.init();
}; };
@ -69,6 +69,7 @@ define('forum/chats', [
Chats.addScrollHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.chat-content')); Chats.addScrollHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.chat-content'));
Chats.addScrollBottomHandler($('.chat-content')); Chats.addScrollBottomHandler($('.chat-content'));
Chats.addCharactersLeftHandler($('[component="chat/main-wrapper"]')); Chats.addCharactersLeftHandler($('[component="chat/main-wrapper"]'));
Chats.addTextareaResizeHandler($('[component="chat/main-wrapper"]'));
Chats.addIPHandler($('[component="chat/main-wrapper"]')); Chats.addIPHandler($('[component="chat/main-wrapper"]'));
Chats.createAutoComplete(ajaxify.data.roomId, $('[component="chat/input"]')); Chats.createAutoComplete(ajaxify.data.roomId, $('[component="chat/input"]'));
Chats.addUploadHandler({ Chats.addUploadHandler({
@ -169,10 +170,8 @@ define('forum/chats', [
messages.parseMessage(data, function (html) { messages.parseMessage(data, function (html) {
const currentScrollTop = el.scrollTop(); const currentScrollTop = el.scrollTop();
const previousHeight = el[0].scrollHeight; const previousHeight = el[0].scrollHeight;
html = $(html);
el.prepend(html); el.prepend(html);
html.find('.timeago').timeago(); messages.onMessagesAddedToDom(html);
html.find('img:not(.not-responsive)').addClass('img-fluid');
el.scrollTop((el[0].scrollHeight - previousHeight) + currentScrollTop); el.scrollTop((el[0].scrollHeight - previousHeight) + currentScrollTop);
loading = false; loading = false;
}); });
@ -195,6 +194,19 @@ define('forum/chats', [
}); });
}; };
Chats.addTextareaResizeHandler = function (parent) {
// https://stackoverflow.com/questions/454202/creating-a-textarea-with-auto-resize
const textarea = parent.find('[component="chat/input"]');
textarea.on('input', function () {
const isAtBottom = messages.isAtBottom(parent.find('.chat-content'));
textarea.css({ height: 0 });
textarea.css({ height: textarea.prop('scrollHeight') + 'px' });
if (isAtBottom) {
messages.scrollToBottom(parent.find('.chat-content'));
}
});
};
Chats.addActionHandlers = function (element, roomId) { Chats.addActionHandlers = function (element, roomId) {
element.on('click', '[data-action]', function () { element.on('click', '[data-action]', function () {
const messageId = $(this).parents('[data-mid]').attr('data-mid'); const messageId = $(this).parents('[data-mid]').attr('data-mid');

@ -3,8 +3,11 @@
define('forum/chats/messages', [ define('forum/chats/messages', [
'components', 'translator', 'benchpress', 'hooks', 'components', 'translator', 'benchpress', 'hooks',
'bootbox', 'alerts', 'messages', 'api', 'bootbox', 'alerts', 'messages', 'api', 'forum/topic/images',
], function (components, translator, Benchpress, hooks, bootbox, alerts, messagesModule, api) { ], function (
components, translator, Benchpress, hooks,
bootbox, alerts, messagesModule, api, images
) {
const messages = {}; const messages = {};
messages.sendMessage = async function (roomId, inputEl) { messages.sendMessage = async function (roomId, inputEl) {
@ -49,18 +52,9 @@ define('forum/chats/messages', [
}; };
messages.updateTextAreaHeight = function (chatContentEl) { messages.updateTextAreaHeight = function (chatContentEl) {
// https://stackoverflow.com/questions/454202/creating-a-textarea-with-auto-resize
const textarea = chatContentEl.find('[component="chat/input"]'); const textarea = chatContentEl.find('[component="chat/input"]');
const scrollHeight = textarea.prop('scrollHeight'); const scrollHeight = textarea.prop('scrollHeight');
textarea.css({ height: scrollHeight + 'px' }); textarea.css({ height: scrollHeight + 'px' });
textarea.on('input', function () {
const isAtBottom = messages.isAtBottom(chatContentEl.find('.chat-content'));
textarea.css({ height: 0 });
textarea.css({ height: textarea.prop('scrollHeight') + 'px' });
if (isAtBottom) {
messages.scrollToBottom(chatContentEl.find('.chat-content'));
}
});
}; };
function autoresizeTextArea(textarea) { function autoresizeTextArea(textarea) {
@ -89,8 +83,7 @@ define('forum/chats/messages', [
const newMessage = $(html); const newMessage = $(html);
const isAtBottom = messages.isAtBottom(chatContentEl); const isAtBottom = messages.isAtBottom(chatContentEl);
newMessage.appendTo(chatContentEl); newMessage.appendTo(chatContentEl);
newMessage.find('.timeago').timeago(); messages.onMessagesAddedToDom(newMessage);
newMessage.find('img:not(.not-responsive)').addClass('img-fluid');
if (isAtBottom) { if (isAtBottom) {
messages.scrollToBottom(chatContentEl); messages.scrollToBottom(chatContentEl);
} }
@ -100,10 +93,15 @@ define('forum/chats/messages', [
}); });
} }
messages.onMessagesAddedToDom = function (messageEls) {
messageEls.find('.timeago').timeago();
messageEls.find('img:not(.not-responsive)').addClass('img-fluid');
messages.wrapImagesInLinks(messageEls.first().parent());
};
messages.parseMessage = function (data, callback) { messages.parseMessage = function (data, callback) {
function done(html) { function done(html) {
translator.translate(html, callback); translator.translate(html, translated => callback($(translated)));
} }
const tplData = { const tplData = {
messages: data, messages: data,
@ -134,6 +132,12 @@ define('forum/chats/messages', [
} }
}; };
messages.wrapImagesInLinks = function (containerEl) {
containerEl.find('[component="chat/message/body"] img:not(.emoji)').each(function () {
images.wrapImageInLink($(this));
});
};
messages.toggleScrollUpAlert = function (containerEl) { messages.toggleScrollUpAlert = function (containerEl) {
const isAtBottom = messages.isAtBottom(containerEl, 300); const isAtBottom = messages.isAtBottom(containerEl, 300);
containerEl.parent() containerEl.parent()
@ -225,7 +229,7 @@ define('forum/chats/messages', [
const body = components.get('chat/message', message.messageId); const body = components.get('chat/message', message.messageId);
if (body.length) { if (body.length) {
body.replaceWith(html); body.replaceWith(html);
components.get('chat/message', message.messageId).find('.timeago').timeago(); messages.onMessagesAddedToDom(html);
} }
}); });
}); });
@ -234,13 +238,15 @@ define('forum/chats/messages', [
function onChatMessageDeleted(messageId) { function onChatMessageDeleted(messageId) {
components.get('chat/message', messageId) components.get('chat/message', messageId)
.toggleClass('deleted', true) .toggleClass('deleted', true)
.find('[component="chat/message/body"]').translateHtml('[[modules:chat.message-deleted]]'); .find('[component="chat/message/body"]')
.translateHtml('[[modules:chat.message-deleted]]');
} }
function onChatMessageRestored(message) { function onChatMessageRestored(message) {
components.get('chat/message', message.messageId) components.get('chat/message', message.messageId)
.toggleClass('deleted', false) .toggleClass('deleted', false)
.find('[component="chat/message/body"]').html(message.content); .find('[component="chat/message/body"]')
.html(message.content);
} }
messages.delete = function (messageId, roomId) { messages.delete = function (messageId, roomId) {

@ -9,9 +9,8 @@ define('forum/topic/events', [
'forum/topic/images', 'forum/topic/images',
'components', 'components',
'translator', 'translator',
'benchpress',
'hooks', 'hooks',
], function (postTools, threadTools, posts, images, components, translator, Benchpress, hooks) { ], function (postTools, threadTools, posts, images, components, translator, hooks) {
const Events = {}; const Events = {};
const events = { const events = {

@ -4,30 +4,32 @@
define('forum/topic/images', [], function () { define('forum/topic/images', [], function () {
const Images = {}; const Images = {};
const suffixRegex = /-resized(\.[\w]+)?$/;
Images.wrapImagesInLinks = function (posts) { Images.wrapImagesInLinks = function (posts) {
posts.find('[component="post/content"] img:not(.emoji)').each(function () { posts.find('[component="post/content"] img:not(.emoji)').each(function () {
const $this = $(this); Images.wrapImageInLink($(this));
let src = $this.attr('src') || ''; });
const alt = $this.attr('alt') || ''; };
const suffixRegex = /-resized(\.[\w]+)?$/;
Images.wrapImageInLink = function (imageEl) {
let src = imageEl.attr('src') || '';
if (src === 'about:blank') { if (src === 'about:blank') {
return; return;
} }
if (!imageEl.parent().is('a')) {
if (utils.isRelativeUrl(src) && suffixRegex.test(src)) { if (utils.isRelativeUrl(src) && suffixRegex.test(src)) {
src = src.replace(suffixRegex, '$1'); src = src.replace(suffixRegex, '$1');
} }
const alt = imageEl.attr('alt') || '';
const srcExt = src.split('.').slice(1).pop(); const srcExt = src.split('.').slice(1).pop();
const altFilename = alt.split('/').pop(); const altFilename = alt.split('/').pop();
const altExt = altFilename.split('.').slice(1).pop(); const altExt = altFilename.split('.').slice(1).pop();
imageEl.wrap('<a href="' + src + '" ' +
if (!$this.parent().is('a')) {
$this.wrap('<a href="' + src + '" ' +
(!srcExt && altExt ? ' download="' + altFilename + '" ' : '') + (!srcExt && altExt ? ' download="' + altFilename + '" ' : '') +
' target="_blank" rel="noopener">'); ' target="_blank" rel="noopener">');
} }
});
}; };
return Images; return Images;

@ -246,6 +246,7 @@ define('chat', [
chatModal.css('position', 'fixed'); chatModal.css('position', 'fixed');
chatModal.appendTo($('body')); chatModal.appendTo($('body'));
chatModal.find('.timeago').timeago(); chatModal.find('.timeago').timeago();
ChatsMessages.wrapImagesInLinks(chatModal.find('[component="chat/messages"] .chat-content'));
module.center(chatModal); module.center(chatModal);
app.loadJQueryUI(function () { app.loadJQueryUI(function () {
@ -332,6 +333,7 @@ define('chat', [
Chats.addScrollBottomHandler(chatModal.find('.chat-content')); Chats.addScrollBottomHandler(chatModal.find('.chat-content'));
Chats.addCharactersLeftHandler(chatModal); Chats.addCharactersLeftHandler(chatModal);
Chats.addTextareaResizeHandler(chatModal);
Chats.addIPHandler(chatModal); Chats.addIPHandler(chatModal);
Chats.addUploadHandler({ Chats.addUploadHandler({

Loading…
Cancel
Save