refactor: dont use module, explodes on latest webpack

This commit is contained in:
Barış Soner Uşaklı
2026-02-03 18:51:41 -05:00
parent f249699d0b
commit a4e3fe105f
11 changed files with 101 additions and 101 deletions

View File

@@ -8,9 +8,9 @@ define('admin/settings/activitypub', [
'alerts',
'translator',
], function (Benchpress, bootbox, categorySelector, api, alerts, translator) {
const Module = {};
const ActivityPub = {};
Module.init = function () {
ActivityPub.init = function () {
const rulesEl = document.getElementById('rules');
if (rulesEl) {
rulesEl.addEventListener('click', (e) => {
@@ -19,7 +19,7 @@ define('admin/settings/activitypub', [
const action = subselector.getAttribute('data-action');
switch (action) {
case 'rules.add': {
Module.throwRulesModal();
ActivityPub.throwRulesModal();
break;
}
@@ -46,7 +46,7 @@ define('admin/settings/activitypub', [
const action = subselector.getAttribute('data-action');
switch (action) {
case 'relays.add': {
Module.throwRelaysModal();
ActivityPub.throwRelaysModal();
break;
}
@@ -66,7 +66,7 @@ define('admin/settings/activitypub', [
}
};
Module.throwRulesModal = function () {
ActivityPub.throwRulesModal = function () {
Benchpress.render('admin/partials/activitypub/rules', {}).then(function (html) {
const submit = function () {
const formEl = modal.find('form').get(0);
@@ -123,7 +123,7 @@ define('admin/settings/activitypub', [
});
};
Module.throwRelaysModal = function () {
ActivityPub.throwRelaysModal = function () {
Benchpress.render('admin/partials/activitypub/relays', {}).then(function (html) {
const submit = function () {
const formEl = modal.find('form').get(0);
@@ -155,5 +155,5 @@ define('admin/settings/activitypub', [
});
};
return Module;
return ActivityPub;
});

View File

@@ -1,9 +1,9 @@
'use strict';
define('admin/settings/cookies', ['alerts'], function (alerts) {
const Module = {};
const Cookies = {};
Module.init = function () {
Cookies.init = function () {
$('#delete-all-sessions').on('click', function () {
socket.emit('admin.deleteAllSessions', function (err) {
if (err) {
@@ -15,5 +15,5 @@ define('admin/settings/cookies', ['alerts'], function (alerts) {
});
};
return Module;
return Cookies;
});

View File

@@ -2,10 +2,10 @@
define('admin/settings/email', ['ace/ace', 'alerts', 'admin/settings'], function (ace, alerts) {
const module = {};
const Email = {};
let emailEditor;
module.init = function () {
Email.init = function () {
configureSmtpTester();
configureEmailTester();
configureEmailEditor();
@@ -159,5 +159,5 @@ define('admin/settings/email', ['ace/ace', 'alerts', 'admin/settings'], function
});
}
return module;
return Email;
});

View File

@@ -2,9 +2,9 @@
define('admin/settings/general', ['admin/settings'], function () {
const Module = {};
const General = {};
Module.init = function () {
General.init = function () {
$('button[data-action="removeLogo"]').on('click', function () {
$('input[data-field="brand:logo"]').val('');
});
@@ -34,5 +34,5 @@ define('admin/settings/general', ['admin/settings'], function () {
}
}
return Module;
return General;
});

View File

@@ -6,9 +6,9 @@ define('forum/header', [
'forum/header/chat',
'alerts',
], function (unread, notifications, chat, alerts) {
const module = {};
const header = {};
module.prepareDOM = function () {
header.prepareDOM = function () {
if (app.user.uid > 0) {
unread.initUnreadTopics();
}
@@ -74,5 +74,5 @@ define('forum/header', [
});
}
return module;
return header;
});

View File

@@ -3,17 +3,17 @@
define('chat', [
'components', 'taskbar', 'translator', 'hooks', 'bootbox', 'alerts', 'api', 'scrollStop',
], function (components, taskbar, translator, hooks, bootbox, alerts, api, scrollStop) {
const module = {};
const Chat = {};
module.openChat = function (roomId, uid) {
Chat.openChat = function (roomId, uid) {
if (!app.user.uid) {
return alerts.error('[[error:not-logged-in]]');
}
function loadAndCenter(chatModal) {
module.load(chatModal.attr('data-uuid'));
module.center(chatModal);
module.focusInput(chatModal);
Chat.load(chatModal.attr('data-uuid'));
Chat.center(chatModal);
Chat.focusInput(chatModal);
}
hooks.fire('filter:chat.openChat', {
modal: true,
@@ -23,8 +23,8 @@ define('chat', [
if (!hookData.modal) {
return ajaxify.go(`/chats/${roomId}`);
}
if (module.modalExists(roomId)) {
loadAndCenter(module.getModal(roomId));
if (Chat.modalExists(roomId)) {
loadAndCenter(Chat.getModal(roomId));
} else {
api.get(`/chats/${roomId}`, {
uid: uid || app.user.uid,
@@ -34,19 +34,19 @@ define('chat', [
});
roomData.uid = uid || app.user.uid;
roomData.isSelf = true;
module.createModal(roomData, loadAndCenter);
Chat.createModal(roomData, loadAndCenter);
}).catch(alerts.error);
}
});
};
module.newChat = function (touid, callback) {
Chat.newChat = function (touid, callback) {
function createChat() {
api.post(`/chats`, {
uids: [touid],
}).then(({ roomId }) => {
if (!ajaxify.data.template.chats) {
module.openChat(roomId);
Chat.openChat(roomId);
} else {
ajaxify.go('chats/' + roomId);
}
@@ -82,7 +82,7 @@ define('chat', [
}).catch(alerts.error);
};
module.loadChatsDropdown = function (chatsListEl) {
Chat.loadChatsDropdown = function (chatsListEl) {
api.get('/chats', {
uid: app.user.uid,
after: 0,
@@ -114,7 +114,7 @@ define('chat', [
}
const roomId = $(this).attr('data-roomid');
if (!ajaxify.currentPage.match(/^chats\//)) {
module.openChat(roomId);
Chat.openChat(roomId);
} else {
ajaxify.go('user/' + app.user.userslug + '/chats/' + roomId);
}
@@ -129,7 +129,7 @@ define('chat', [
const roomId = el.getAttribute('data-roomid');
await api.del(`/chats/${roomId}/state`);
if (ajaxify.data.template.chats) {
module.markChatElUnread($(el), false);
Chat.markChatElUnread($(el), false);
}
}));
});
@@ -145,32 +145,32 @@ define('chat', [
e.stopPropagation();
const chatEl = e.target.closest('[data-roomid]');
module.toggleReadState(chatEl);
Chat.toggleReadState(chatEl);
}
module.toggleReadState = function (chatEl) {
Chat.toggleReadState = function (chatEl) {
const state = !chatEl.classList.contains('unread'); // this is the new state
const roomId = chatEl.getAttribute('data-roomid');
api[state ? 'put' : 'del'](`/chats/${roomId}/state`, {}).catch((err) => {
alerts.error(err);
// Revert on failure
module.markChatElUnread($(chatEl), !state);
Chat.markChatElUnread($(chatEl), !state);
});
// Immediate feedback
module.markChatElUnread($(chatEl), state);
Chat.markChatElUnread($(chatEl), state);
};
module.isFromBlockedUser = function (fromUid) {
Chat.isFromBlockedUser = function (fromUid) {
return app.user.blocks.includes(parseInt(fromUid, 10));
};
module.isLookingAtRoom = function (roomId) {
Chat.isLookingAtRoom = function (roomId) {
return ajaxify.data.template.chats && parseInt(ajaxify.data.roomId, 10) === parseInt(roomId, 10);
};
module.markChatElUnread = function (roomEl, unread) {
Chat.markChatElUnread = function (roomEl, unread) {
if (roomEl.length > 0) {
roomEl.toggleClass('unread', unread);
const markEl = roomEl.find('.mark-read');
@@ -181,12 +181,12 @@ define('chat', [
}
};
module.onChatMessageReceived = function (data) {
Chat.onChatMessageReceived = function (data) {
if (app.user.blocks.includes(parseInt(data.fromUid, 10))) {
return;
}
if (module.modalExists(data.roomId)) {
const modal = module.getModal(data.roomId);
if (Chat.modalExists(data.roomId)) {
const modal = Chat.getModal(data.roomId);
const newMessage = parseInt(modal.attr('new-message'), 10) === 1;
data.self = parseInt(app.user.uid, 10) === parseInt(data.fromUid, 10) ? 1 : 0;
if (!newMessage) {
@@ -200,7 +200,7 @@ define('chat', [
};
function addMessageToModal(data) {
const modal = module.getModal(data.roomId);
const modal = Chat.getModal(data.roomId);
const username = data.message.fromUser.username;
const isSelf = data.self === 1;
require(['forum/chats/messages'], function (ChatsMessages) {
@@ -215,7 +215,7 @@ define('chat', [
ChatsMessages.scrollToBottomAfterImageLoad(modal.find('[component="chat/message/content"]'));
}
} else if (!ajaxify.data.template.chats) {
module.toggleNew(modal.attr('data-uuid'), true, true);
Chat.toggleNew(modal.attr('data-uuid'), true, true);
}
if (!isSelf && (!modal.is(':visible') || !app.isFocused)) {
@@ -229,8 +229,8 @@ define('chat', [
});
}
module.onRoomRename = function (data) {
const modal = module.getModal(data.roomId);
Chat.onRoomRename = function (data) {
const modal = Chat.getModal(data.roomId);
const titleEl = modal.find('[component="chat/room/name"]');
const icon = titleEl.attr('data-icon');
if (titleEl.length) {
@@ -250,17 +250,17 @@ define('chat', [
}));
};
module.onUserTyping = function (data) {
if (data.uid === app.user.uid || module.isFromBlockedUser(data.uid)) {
Chat.onUserTyping = function (data) {
if (data.uid === app.user.uid || Chat.isFromBlockedUser(data.uid)) {
return;
}
const modal = module.getModal(data.roomId);
const modal = Chat.getModal(data.roomId);
if (modal.length) {
module.updateTypingUserList(modal, data);
Chat.updateTypingUserList(modal, data);
}
};
module.updateTypingUserList = async function (container, { uid, username, typing }) {
Chat.updateTypingUserList = async function (container, { uid, username, typing }) {
const typingEl = container.find(`[component="chat/composer/typing"]`);
const typingUsersList = typingEl.find('[component="chat/composer/typing/users"]');
const userEl = typingUsersList.find(`[data-uid="${uid}"]`);
@@ -288,15 +288,15 @@ define('chat', [
typingTextEl.toggleClass('hidden', !usernames.length);
};
module.getModal = function (roomId) {
Chat.getModal = function (roomId) {
return $('#chat-modal-' + roomId);
};
module.modalExists = function (roomId) {
Chat.modalExists = function (roomId) {
return $('#chat-modal-' + roomId).length !== 0;
};
module.initWidget = function (roomId, chatModal) {
Chat.initWidget = function (roomId, chatModal) {
require(['forum/chats', 'forum/chats/messages'], function (Chats, ChatsMessages) {
socket.emit('modules.chats.enter', roomId);
api.del(`/chats/${roomId}/state`, {});
@@ -345,15 +345,15 @@ define('chat', [
});
};
module.createModal = function (data, callback) {
Chat.createModal = function (data, callback) {
callback = callback || function () {};
require([
'forum/chats', 'forum/chats/messages', 'forum/chats/message-search',
], function (Chats, ChatsMessages, messageSearch) {
app.parseAndTranslate('chat', data, function (chatModal) {
const roomId = data.roomId;
if (module.modalExists(roomId)) {
return callback(module.getModal(data.roomId));
if (Chat.modalExists(roomId)) {
return callback(Chat.getModal(data.roomId));
}
const uuid = utils.generateUUID();
let dragged = false;
@@ -369,12 +369,12 @@ define('chat', [
scrollStop.apply(chatModal.find('[component="chat/messages"] .chat-content'));
module.center(chatModal);
Chat.center(chatModal);
makeModalResizeableDraggable(chatModal, uuid);
chatModal.find('#chat-close-btn').on('click', function () {
module.close(uuid);
Chat.close(uuid);
});
function gotoChats() {
@@ -384,14 +384,14 @@ define('chat', [
});
ajaxify.go(`user/${app.user.userslug}/chats/${roomId}`);
module.close(uuid);
Chat.close(uuid);
}
chatModal.find('.modal-header').on('dblclick', gotoChats);
chatModal.find('button[data-action="maximize"]').on('click', gotoChats);
chatModal.find('button[data-action="minimize"]').on('click', function () {
const uuid = chatModal.attr('data-uuid');
module.minimize(uuid);
Chat.minimize(uuid);
});
chatModal.on('mouseup', function () {
@@ -475,7 +475,7 @@ define('chat', [
return;
}
chatModal.find('.modal-body').css('height', module.calculateChatListHeight(chatModal));
chatModal.find('.modal-body').css('height', Chat.calculateChatListHeight(chatModal));
});
chatModal.draggable({
@@ -484,7 +484,7 @@ define('chat', [
chatModal.css({ bottom: 'auto', right: 'auto' });
},
stop: function () {
module.focusInput(chatModal);
Chat.focusInput(chatModal);
},
distance: 10,
handle: '.modal-header',
@@ -492,20 +492,20 @@ define('chat', [
});
}
module.focusInput = function (chatModal) {
Chat.focusInput = function (chatModal) {
setTimeout(function () {
chatModal.find('[component="chat/input"]').focus();
}, 20);
};
module.close = function (uuid) {
Chat.close = function (uuid) {
const chatModal = $('.chat-modal[data-uuid="' + uuid + '"]');
chatModal.remove();
chatModal.data('modal', null);
taskbar.discard('chat', uuid);
if (chatModal.attr('data-mobile')) {
module.disableMobileBehaviour(chatModal);
Chat.disableMobileBehaviour(chatModal);
}
const roomId = chatModal.attr('data-roomid');
require(['forum/chats'], function (chats) {
@@ -518,7 +518,7 @@ define('chat', [
});
};
module.center = function (chatModal) {
Chat.center = function (chatModal) {
const center = chatModal.attr('data-center');
if (!center || center === 'false') {
return;
@@ -537,30 +537,30 @@ define('chat', [
return chatModal;
};
module.load = function (uuid) {
Chat.load = function (uuid) {
require(['forum/chats/messages'], function (ChatsMessages) {
const chatModal = $('.chat-modal[data-uuid="' + uuid + '"]');
chatModal.removeClass('hide');
taskbar.updateActive(uuid);
ChatsMessages.scrollToBottomAfterImageLoad(chatModal.find('.chat-content'));
module.focusInput(chatModal);
Chat.focusInput(chatModal);
const roomId = chatModal.attr('data-roomid');
api.del(`/chats/${roomId}/state`, {});
socket.emit('modules.chats.enter', roomId);
const env = utils.findBootstrapEnvironment();
if (env === 'xs' || env === 'sm') {
module.enableMobileBehaviour(chatModal);
Chat.enableMobileBehaviour(chatModal);
}
});
};
module.enableMobileBehaviour = function (modalEl) {
Chat.enableMobileBehaviour = function (modalEl) {
app.toggleNavbar(false);
modalEl.attr('data-mobile', '1');
const messagesEl = modalEl.find('.modal-body');
messagesEl.css('height', module.calculateChatListHeight(modalEl));
messagesEl.css('height', Chat.calculateChatListHeight(modalEl));
function resize() {
messagesEl.css('height', module.calculateChatListHeight(modalEl));
messagesEl.css('height', Chat.calculateChatListHeight(modalEl));
require(['forum/chats/messages'], function (ChatsMessages) {
ChatsMessages.scrollToBottom(modalEl.find('.chat-content'));
});
@@ -568,21 +568,21 @@ define('chat', [
$(window).on('resize', resize);
$(window).one('action:ajaxify.start', function () {
module.close(modalEl.attr('data-uuid'));
Chat.close(modalEl.attr('data-uuid'));
$(window).off('resize', resize);
});
};
module.disableMobileBehaviour = function () {
Chat.disableMobileBehaviour = function () {
app.toggleNavbar(true);
};
module.calculateChatListHeight = function (modalEl) {
Chat.calculateChatListHeight = function (modalEl) {
// Formula: modal height minus header height. Simple(tm).
return modalEl.find('.modal-content').outerHeight() - modalEl.find('.modal-header').outerHeight();
};
module.minimize = function (uuid) {
Chat.minimize = function (uuid) {
const chatModal = $('.chat-modal[data-uuid="' + uuid + '"]');
chatModal.addClass('hide');
taskbar.minimize('chat', uuid);
@@ -592,7 +592,7 @@ define('chat', [
});
};
module.toggleNew = taskbar.toggleNew;
Chat.toggleNew = taskbar.toggleNew;
return module;
return Chat;
});

View File

@@ -1,9 +1,9 @@
'use strict';
define('pictureCropper', ['alerts'], function (alerts) {
const module = {};
const PictureCropper = {};
module.show = function (data, callback) {
PictureCropper.show = function (data, callback) {
const fileSize = data.hasOwnProperty('fileSize') && data.fileSize !== undefined ? parseInt(data.fileSize, 10) : false;
app.parseAndTranslate('modals/upload-file', {
showHelp: data.hasOwnProperty('showHelp') && data.showHelp !== undefined ? data.showHelp : true,
@@ -32,7 +32,7 @@ define('pictureCropper', ['alerts'], function (alerts) {
});
};
module.handleImageCrop = function (data, callback) {
PictureCropper.handleImageCrop = function (data, callback) {
$('#crop-picture-modal').remove();
app.parseAndTranslate('modals/crop_picture', {
url: utils.escapeHTML(data.url),
@@ -227,7 +227,7 @@ define('pictureCropper', ['alerts'], function (alerts) {
data.uploadModal.modal('hide');
module.handleImageCrop({
PictureCropper.handleImageCrop({
url: imageUrl,
imageType: file.type,
socketMethod: data.socketMethod,
@@ -245,5 +245,5 @@ define('pictureCropper', ['alerts'], function (alerts) {
}
}
return module;
return PictureCropper;
});

View File

@@ -10,9 +10,9 @@
*/
define('scrollStop', function () {
const Module = {};
const ScrollStop = {};
Module.apply = function (element) {
ScrollStop.apply = function (element) {
$(element).on('mousewheel', function (e) {
const scrollTop = this.scrollTop;
const scrollHeight = this.scrollHeight;
@@ -27,5 +27,5 @@ define('scrollStop', function () {
});
};
return Module;
return ScrollStop;
});

View File

@@ -2,10 +2,10 @@
define('share', ['hooks'], function (hooks) {
const module = {};
const share = {};
const baseUrl = window.location.protocol + '//' + window.location.host;
module.addShareHandlers = function (name) {
share.addShareHandlers = function (name) {
function openShare(url, urlToPost, width, height) {
window.open(url, '_blank', 'width=' + width + ',height=' + height + ',scrollbars=no,status=no');
hooks.fire('action:share.open', {
@@ -76,5 +76,5 @@ define('share', ['hooks'], function (hooks) {
return baseUrl + config.relative_path + path;
}
return module;
return share;
});

View File

@@ -2,9 +2,9 @@
define('sort', ['components'], function (components) {
const module = {};
const Sort = {};
module.handleSort = function (field, gotoOnSave) {
Sort.handleSort = function (field, gotoOnSave) {
const threadSort = components.get('thread/sort');
threadSort.find('i').removeClass('fa-check');
const currentSort = utils.params().sort || config[field];
@@ -22,5 +22,5 @@ define('sort', ['components'], function (components) {
});
};
return module;
return Sort;
});

View File

@@ -2,9 +2,9 @@
define('uploader', ['jquery-form'], function () {
const module = {};
const Uploader = {};
module.show = function (data, callback) {
Uploader.show = function (data, callback) {
const fileSize = data.hasOwnProperty('fileSize') && data.fileSize !== undefined ? parseInt(data.fileSize, 10) : false;
app.parseAndTranslate('modals/upload-file', {
showHelp: data.hasOwnProperty('showHelp') && data.showHelp !== undefined ? data.showHelp : true,
@@ -35,7 +35,7 @@ define('uploader', ['jquery-form'], function () {
});
};
module.hideAlerts = function (modal) {
Uploader.hideAlerts = function (modal) {
$(modal).find('#alert-status, #alert-success, #alert-error, #upload-progress-box').addClass('hide');
};
@@ -53,11 +53,11 @@ define('uploader', ['jquery-form'], function () {
return showAlert(uploadModal, 'error', '[[error:file-too-big, ' + fileSize + ']]');
}
module.ajaxSubmit(uploadModal, callback);
Uploader.ajaxSubmit(uploadModal, callback);
}
function showAlert(uploadModal, type, message) {
module.hideAlerts(uploadModal);
Uploader.hideAlerts(uploadModal);
if (type === 'error') {
uploadModal.find('#fileUploadSubmitBtn').removeClass('disabled');
}
@@ -65,7 +65,7 @@ define('uploader', ['jquery-form'], function () {
uploadModal.find('#alert-' + type).translateText(message).removeClass('hide');
}
module.ajaxSubmit = function (uploadModal, callback) {
Uploader.ajaxSubmit = function (uploadModal, callback) {
const uploadForm = uploadModal.find('#uploadForm');
uploadForm.ajaxSubmit({
headers: {
@@ -96,7 +96,7 @@ define('uploader', ['jquery-form'], function () {
showAlert(uploadModal, 'success', '[[uploads:upload-success]]');
setTimeout(function () {
module.hideAlerts(uploadModal);
Uploader.hideAlerts(uploadModal);
uploadModal.modal('hide');
}, 750);
},
@@ -122,5 +122,5 @@ define('uploader', ['jquery-form'], function () {
return true;
}
return module;
return Uploader;
});