reduce initial js payload/requests

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 0fd5210d37
commit c02d584b53

@ -3,12 +3,10 @@
define('forum/category/tools', [ define('forum/category/tools', [
'forum/topic/move',
'forum/topic/merge',
'topicSelect', 'topicSelect',
'components', 'components',
'translator', 'translator',
], function (move, merge, topicSelect, components, translator) { ], function (topicSelect, components, translator) {
var CategoryTools = {}; var CategoryTools = {};
CategoryTools.init = function (cid) { CategoryTools.init = function (cid) {
@ -88,16 +86,20 @@ define('forum/category/tools', [
}); });
components.get('topic/move').on('click', function () { components.get('topic/move').on('click', function () {
require(['forum/topic/move'], function (move) {
var tids = topicSelect.getSelectedTids(); var tids = topicSelect.getSelectedTids();
if (!tids.length) { if (!tids.length) {
return app.alertError('[[error:no-topics-selected]]'); return app.alertError('[[error:no-topics-selected]]');
} }
move.init(tids, cid, onCommandComplete); move.init(tids, cid, onCommandComplete);
});
return false; return false;
}); });
components.get('topic/move-all').on('click', function () { components.get('topic/move-all').on('click', function () {
require(['forum/topic/move'], function (move) {
move.init(null, cid, function (err) { move.init(null, cid, function (err) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
@ -106,8 +108,13 @@ define('forum/category/tools', [
ajaxify.refresh(); ajaxify.refresh();
}); });
}); });
});
$('.category').on('click', '[component="topic/merge"]', function () {
require(['forum/topic/merge'], function (merge) {
merge.init(); merge.init();
});
});
CategoryTools.removeListeners(); CategoryTools.removeListeners();
socket.on('event:topic_deleted', setDeleteState); socket.on('event:topic_deleted', setDeleteState);

@ -124,7 +124,11 @@ define('forum/chats/messages', ['components', 'sounds', 'translator', 'benchpres
}; };
messages.onChatMessageEdit = function () { messages.onChatMessageEdit = function () {
socket.on('event:chats.edit', function (data) { socket.removeListener('event:chats.edit', onChatMessageEdited);
socket.on('event:chats.edit', onChatMessageEdited);
};
function onChatMessageEdited(data) {
data.messages.forEach(function (message) { data.messages.forEach(function (message) {
var self = parseInt(message.fromuid, 10) === parseInt(app.user.uid, 10); var self = parseInt(message.fromuid, 10) === parseInt(app.user.uid, 10);
message.self = self ? 1 : 0; message.self = self ? 1 : 0;
@ -136,8 +140,7 @@ define('forum/chats/messages', ['components', 'sounds', 'translator', 'benchpres
} }
}); });
}); });
}); }
};
messages.delete = function (messageId, roomId) { messages.delete = function (messageId, roomId) {
translator.translate('[[modules:chat.delete_message_confirm]]', function (translated) { translator.translate('[[modules:chat.delete_message_confirm]]', function (translated) {

@ -1,7 +1,12 @@
'use strict'; 'use strict';
define('forum/footer', ['notifications', 'chat', 'components', 'translator'], function (Notifications, Chat, components, translator) { define('forum/footer', [
'components',
'translator',
'forum/header/notifications',
'forum/header/chat',
], function (components, translator, Notifications, Chat) {
Notifications.prepareDOM(); Notifications.prepareDOM();
Chat.prepareDOM(); Chat.prepareDOM();
translator.prepareDOM(); translator.prepareDOM();

@ -0,0 +1,41 @@
'use strict';
define('forum/header/chat', ['components'], function (components) {
var chat = {};
chat.prepareDOM = function () {
var chatsToggleEl = components.get('chat/dropdown');
var chatsListEl = components.get('chat/list');
chatsToggleEl.on('click', function () {
if (chatsToggleEl.parent().hasClass('open')) {
return;
}
requireAndCall('loadChatsDropdown', chatsListEl);
});
if (chatsToggleEl.parents('.dropdown').hasClass('open')) {
requireAndCall('loadChatsDropdown', chatsListEl);
}
socket.on('event:chats.receive', function (data) {
requireAndCall('onChatMessageReceived', data);
});
socket.on('event:user_status_change', function (data) {
requireAndCall('onUserStatusChange', data);
});
socket.on('event:chats.roomRename', function (data) {
requireAndCall('onRoomRename', data);
});
};
function requireAndCall(method, param) {
require(['chat'], function (chat) {
chat[method](param);
});
}
return chat;
});

@ -0,0 +1,40 @@
'use strict';
define('forum/header/notifications', ['components'], function (components) {
var notifications = {};
notifications.prepareDOM = function () {
var notifContainer = components.get('notifications');
var notifTrigger = notifContainer.children('a');
var notifList = components.get('notifications/list');
notifTrigger.on('click', function (e) {
e.preventDefault();
if (notifContainer.hasClass('open')) {
return;
}
requireAndCall('loadNotifications', notifList);
});
if (notifTrigger.parents('.dropdown').hasClass('open')) {
requireAndCall('loadNotifications', notifList);
}
socket.on('event:new_notification', function (data) {
requireAndCall('onNewNotification', data);
});
socket.on('event:notifications.updateCount', function (data) {
requireAndCall('updateNotifCount', data);
});
};
function requireAndCall(method, param) {
require(['notifications'], function (notifications) {
notifications[method](param);
});
}
return notifications;
});

@ -15,8 +15,6 @@ define('forum/notifications', ['components'], function (components) {
}); });
}); });
$('.timeago').timeago();
components.get('notifications/mark_all').on('click', function () { components.get('notifications/mark_all').on('click', function () {
socket.emit('notifications.markAllRead', function (err) { socket.emit('notifications.markAllRead', function (err) {
if (err) { if (err) {

@ -8,12 +8,11 @@ define('forum/topic', [
'forum/topic/events', 'forum/topic/events',
'forum/topic/posts', 'forum/topic/posts',
'forum/topic/images', 'forum/topic/images',
'forum/topic/replies',
'navigator', 'navigator',
'sort', 'sort',
'components', 'components',
'storage', 'storage',
], function (infinitescroll, threadTools, postTools, events, posts, images, replies, navigator, sort, components, storage) { ], function (infinitescroll, threadTools, postTools, events, posts, images, navigator, sort, components, storage) {
var Topic = {}; var Topic = {};
var currentUrl = ''; var currentUrl = '';
@ -49,7 +48,6 @@ define('forum/topic', [
postTools.init(tid); postTools.init(tid);
threadTools.init(tid); threadTools.init(tid);
replies.init(tid);
events.init(); events.init();
sort.handleSort('topicPostSort', 'user.setTopicSort', 'topic/' + ajaxify.data.slug); sort.handleSort('topicPostSort', 'user.setTopicSort', 'topic/' + ajaxify.data.slug);
@ -61,6 +59,7 @@ define('forum/topic', [
addBlockQuoteHandler(); addBlockQuoteHandler();
addParentHandler(); addParentHandler();
addDropupHandler(); addDropupHandler();
addRepliesHandler();
navigator.init('[component="post"]', ajaxify.data.postcount, Topic.toTop, Topic.toBottom, Topic.navigatorCallback, Topic.calculateIndex); navigator.init('[component="post"]', ajaxify.data.postcount, Topic.toTop, Topic.toBottom, Topic.navigatorCallback, Topic.calculateIndex);
@ -177,6 +176,15 @@ define('forum/topic', [
}); });
} }
function addRepliesHandler() {
$('[component="topic"]').on('click', '[component="post/reply-count"]', function () {
var btn = $(this);
require(['forum/topic/replies'], function (replies) {
replies.init(btn);
});
});
}
function updateTopicTitle() { function updateTopicTitle() {
var span = components.get('navbar/title').find('span'); var span = components.get('navbar/title').find('span');
if ($(window).scrollTop() > 50 && span.hasClass('hidden')) { if ($(window).scrollTop() > 50 && span.hasClass('hidden')) {

@ -10,18 +10,9 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function (compo
DeletePosts.init = function () { DeletePosts.init = function () {
tid = ajaxify.data.tid; tid = ajaxify.data.tid;
$('.topic').on('click', '[component="topic/delete/posts"]', onDeletePostsClicked);
$(window).off('action:ajaxify.end', onAjaxifyEnd).on('action:ajaxify.end', onAjaxifyEnd);
};
function onAjaxifyEnd() { $(window).off('action:ajaxify.end', onAjaxifyEnd).on('action:ajaxify.end', onAjaxifyEnd);
if (ajaxify.data.template.name !== 'topic' || ajaxify.data.tid !== tid) {
closeModal();
$(window).off('action:ajaxify.end', onAjaxifyEnd);
}
}
function onDeletePostsClicked() {
if (modal) { if (modal) {
return; return;
} }
@ -49,6 +40,13 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function (compo
deletePosts(purgeBtn, 'posts.purgePosts'); deletePosts(purgeBtn, 'posts.purgePosts');
}); });
}); });
};
function onAjaxifyEnd() {
if (ajaxify.data.template.name !== 'topic' || ajaxify.data.tid !== tid) {
closeModal();
$(window).off('action:ajaxify.end', onAjaxifyEnd);
}
} }
function deletePosts(btn, command) { function deletePosts(btn, command) {

@ -6,20 +6,12 @@ define('forum/topic/fork', ['components', 'postSelect'], function (components, p
var forkModal; var forkModal;
var forkCommit; var forkCommit;
var fromTid; var fromTid;
Fork.init = function () { Fork.init = function () {
fromTid = ajaxify.data.tid; fromTid = ajaxify.data.tid;
$('.topic').on('click', '[component="topic/fork"]', onForkThreadClicked);
$(window).off('action:ajaxify.end', onAjaxifyEnd).on('action:ajaxify.end', onAjaxifyEnd);
};
function onAjaxifyEnd() { $(window).off('action:ajaxify.end', onAjaxifyEnd).on('action:ajaxify.end', onAjaxifyEnd);
if (ajaxify.data.template.name !== 'topic' || ajaxify.data.tid !== fromTid) {
closeForkModal();
$(window).off('action:ajaxify.end', onAjaxifyEnd);
}
}
function onForkThreadClicked() {
if (forkModal) { if (forkModal) {
return; return;
} }
@ -29,7 +21,7 @@ define('forum/topic/fork', ['components', 'postSelect'], function (components, p
forkCommit = forkModal.find('#fork_thread_commit'); forkCommit = forkModal.find('#fork_thread_commit');
$(document.body).append(forkModal); $('body').append(forkModal);
forkModal.find('.close,#fork_thread_cancel').on('click', closeForkModal); forkModal.find('.close,#fork_thread_cancel').on('click', closeForkModal);
forkModal.find('#fork-title').on('keyup', checkForkButtonEnable); forkModal.find('#fork-title').on('keyup', checkForkButtonEnable);
@ -42,6 +34,13 @@ define('forum/topic/fork', ['components', 'postSelect'], function (components, p
forkCommit.on('click', createTopicFromPosts); forkCommit.on('click', createTopicFromPosts);
}); });
};
function onAjaxifyEnd() {
if (ajaxify.data.template.name !== 'topic' || ajaxify.data.tid !== fromTid) {
closeForkModal();
$(window).off('action:ajaxify.end', onAjaxifyEnd);
}
} }
function createTopicFromPosts() { function createTopicFromPosts() {

@ -9,10 +9,6 @@ define('forum/topic/merge', function () {
var selectedTids = {}; var selectedTids = {};
Merge.init = function () { Merge.init = function () {
$('.category').on('click', '[component="topic/merge"]', onMergeTopicsClicked);
};
function onMergeTopicsClicked() {
if (modal) { if (modal) {
return; return;
} }
@ -33,7 +29,7 @@ define('forum/topic/merge', function () {
mergeTopics(mergeBtn); mergeTopics(mergeBtn);
}); });
}); });
} };
function onTopicClicked(ev) { function onTopicClicked(ev) {
var tid = $(this).parents('[component="category/topic"]').attr('data-tid'); var tid = $(this).parents('[component="category/topic"]').attr('data-tid');

@ -7,31 +7,7 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen
var moveModal; var moveModal;
var moveCommit; var moveCommit;
MovePost.init = function () { MovePost.init = function (postEl) {
$('.topic').on('click', '[component="topic/move-posts"]', onMovePostsClicked);
};
function onMovePostsClicked() {
MovePost.openMovePostModal();
}
function showPostsSelected() {
if (postSelect.pids.length) {
moveModal.find('#pids').translateHtml('[[topic:fork_pid_count, ' + postSelect.pids.length + ']]');
} else {
moveModal.find('#pids').translateHtml('[[topic:fork_no_pids]]');
}
}
function checkMoveButtonEnable() {
if (moveModal.find('#topicId').val().length && postSelect.pids.length) {
moveCommit.removeAttr('disabled');
} else {
moveCommit.attr('disabled', true);
}
}
MovePost.openMovePostModal = function (postEl) {
if (moveModal) { if (moveModal) {
return; return;
} }
@ -40,7 +16,7 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen
moveCommit = moveModal.find('#move_posts_confirm'); moveCommit = moveModal.find('#move_posts_confirm');
$(document.body).append(moveModal); $('body').append(moveModal);
moveModal.find('.close,#move_posts_cancel').on('click', closeMoveModal); moveModal.find('.close,#move_posts_cancel').on('click', closeMoveModal);
moveModal.find('#topicId').on('keyup', checkMoveButtonEnable); moveModal.find('#topicId').on('keyup', checkMoveButtonEnable);
@ -57,6 +33,22 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen
}); });
}; };
function showPostsSelected() {
if (postSelect.pids.length) {
moveModal.find('#pids').translateHtml('[[topic:fork_pid_count, ' + postSelect.pids.length + ']]');
} else {
moveModal.find('#pids').translateHtml('[[topic:fork_no_pids]]');
}
}
function checkMoveButtonEnable() {
if (moveModal.find('#topicId').val().length && postSelect.pids.length) {
moveCommit.removeAttr('disabled');
} else {
moveCommit.attr('disabled', true);
}
}
function onPostToggled() { function onPostToggled() {
checkMoveButtonEnable(); checkMoveButtonEnable();
showPostsSelected(); showPostsSelected();

@ -7,9 +7,7 @@ define('forum/topic/postTools', [
'components', 'components',
'translator', 'translator',
'forum/topic/votes', 'forum/topic/votes',
'forum/topic/move-post', ], function (share, navigator, components, translator, votes) {
'forum/topic/diffs',
], function (share, navigator, components, translator, votes, movePost, diffs) {
var PostTools = {}; var PostTools = {};
var staleReplyAnyway = false; var staleReplyAnyway = false;
@ -147,8 +145,10 @@ define('forum/topic/postTools', [
if (config.enablePostHistory && ajaxify.data.privileges['posts:history']) { if (config.enablePostHistory && ajaxify.data.privileges['posts:history']) {
postContainer.on('click', '[component="post/view-history"], [component="post/edit-indicator"]', function () { postContainer.on('click', '[component="post/view-history"], [component="post/edit-indicator"]', function () {
var btn = $(this); var btn = $(this);
require(['forum/topic/diffs'], function (diffs) {
diffs.open(getData(btn, 'data-pid')); diffs.open(getData(btn, 'data-pid'));
}); });
});
} }
postContainer.on('click', '[component="post/delete"]', function () { postContainer.on('click', '[component="post/delete"]', function () {
@ -201,7 +201,10 @@ define('forum/topic/postTools', [
}); });
postContainer.on('click', '[component="post/move"]', function () { postContainer.on('click', '[component="post/move"]', function () {
movePost.openMovePostModal($(this).parents('[data-pid]')); var btn = $(this);
require(['forum/topic/move-post'], function (movePost) {
movePost.init(btn.parents('[data-pid]'));
});
}); });
postContainer.on('click', '[component="post/ban-ip"]', function () { postContainer.on('click', '[component="post/ban-ip"]', function () {

@ -4,19 +4,7 @@
define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'], function (navigator, components, posts) { define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'], function (navigator, components, posts) {
var Replies = {}; var Replies = {};
Replies.init = function (tid) { Replies.init = function (button) {
addPostHandlers(tid);
};
function addPostHandlers(tid) {
var postContainer = components.get('topic');
postContainer.on('click', '[component="post/reply-count"]', function () {
onRepliesClicked($(this), tid);
});
}
function onRepliesClicked(button) {
var post = button.closest('[data-pid]'); var post = button.closest('[data-pid]');
var pid = post.data('pid'); var pid = post.data('pid');
var open = button.find('[component="post/replies/open"]'); var open = button.find('[component="post/replies/open"]');
@ -60,7 +48,7 @@ define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'],
$(this).remove(); $(this).remove();
}); });
} }
} };
Replies.onNewPost = function (data) { Replies.onNewPost = function (data) {
var post = data.posts[0]; var post = data.posts[0];

@ -2,14 +2,9 @@
define('forum/topic/threadTools', [ define('forum/topic/threadTools', [
'forum/topic/fork',
'forum/topic/move',
'forum/topic/delete-posts',
'forum/topic/move-post',
'components', 'components',
'translator', 'translator',
'benchpress', ], function (components, translator) {
], function (fork, move, deletePosts, movePosts, components, translator, Benchpress) {
var ThreadTools = {}; var ThreadTools = {};
ThreadTools.init = function (tid) { ThreadTools.init = function (tid) {
@ -75,21 +70,37 @@ define('forum/topic/threadTools', [
}); });
topicContainer.on('click', '[component="topic/move"]', function () { topicContainer.on('click', '[component="topic/move"]', function () {
require(['forum/topic/move'], function (move) {
move.init([tid], ajaxify.data.cid); move.init([tid], ajaxify.data.cid);
});
return false; return false;
}); });
topicContainer.on('click', '[component="topic/delete/posts"]', function () {
require(['forum/topic/delete-posts'], function (deletePosts) {
deletePosts.init(); deletePosts.init();
});
});
topicContainer.on('click', '[component="topic/fork"]', function () {
require(['forum/topic/fork'], function (fork) {
fork.init(); fork.init();
});
});
topicContainer.on('click', '[component="topic/move-posts"]', function () {
require(['forum/topic/move-post'], function (movePosts) {
movePosts.init(); movePosts.init();
});
});
$('.topic').on('click', '[component="topic/following"]', function () { topicContainer.on('click', '[component="topic/following"]', function () {
changeWatching('follow'); changeWatching('follow');
}); });
$('.topic').on('click', '[component="topic/not-following"]', function () { topicContainer.on('click', '[component="topic/not-following"]', function () {
changeWatching('unfollow'); changeWatching('unfollow');
}); });
$('.topic').on('click', '[component="topic/ignoring"]', function () { topicContainer.on('click', '[component="topic/ignoring"]', function () {
changeWatching('ignore'); changeWatching('ignore');
}); });
@ -140,15 +151,12 @@ define('forum/topic/threadTools', [
if (err) { if (err) {
return app.alertError(err); return app.alertError(err);
} }
app.parseAndTranslate('partials/topic/topic-menu-list', data, function (html) {
Benchpress.parse('partials/topic/topic-menu-list', data, function (html) {
translator.translate(html, function (html) {
dropdownMenu.html(html); dropdownMenu.html(html);
$(window).trigger('action:topic.tools.load'); $(window).trigger('action:topic.tools.load');
}); });
}); });
}); });
});
} }
function topicCommand(command, tid) { function topicCommand(command, tid) {

@ -1,38 +1,30 @@
'use strict'; 'use strict';
define('chat', [ define('chat', [
'components', 'components',
'taskbar', 'taskbar',
'string', ], function (components, taskbar) {
'sounds',
'forum/chats',
'forum/chats/messages',
'translator',
'scrollStop',
'benchpress',
], function (components, taskbar, S, sounds, Chats, ChatsMessages, translator, scrollStop, Benchpress) {
var module = {}; var module = {};
var newMessage = false; var newMessage = false;
module.prepareDOM = function () { module.loadChatsDropdown = function (chatsListEl) {
var chatsToggleEl = components.get('chat/dropdown'); socket.emit('modules.chats.getRecentChats', {
var chatsListEl = components.get('chat/list'); uid: app.user.uid,
var chatsDropdownWrapper = chatsToggleEl.parents('.dropdown'); after: 0,
}, function (err, data) {
chatsToggleEl.on('click', function () { if (err) {
if (chatsToggleEl.parent().hasClass('open')) { return app.alertError(err.message);
return;
} }
module.loadChatsDropdown(chatsListEl); var rooms = data.rooms.filter(function (room) {
return room.teaser;
}); });
if (chatsDropdownWrapper.hasClass('open')) { app.parseAndTranslate('partials/chats/dropdown', { rooms: rooms }, function (html) {
module.loadChatsDropdown(chatsListEl); chatsListEl.find('*').not('.navigation-link').remove();
} chatsListEl.prepend(html);
app.createUserTooltips(chatsListEl, 'right');
chatsListEl.on('click', '[data-roomid]', function (ev) { chatsListEl.off('click').on('click', '[data-roomid]', function (ev) {
if ($(ev.target).parents('.user-link').length) { if ($(ev.target).parents('.user-link').length) {
return; return;
} }
@ -44,21 +36,26 @@ define('chat', [
} }
}); });
$('[component="chats/mark-all-read"]').on('click', function () { $('[component="chats/mark-all-read"]').off('click').on('click', function () {
socket.emit('modules.chats.markAllRead', function (err) { socket.emit('modules.chats.markAllRead', function (err) {
if (err) { if (err) {
return app.alertError(err); return app.alertError(err);
} }
}); });
}); });
});
});
};
socket.on('event:chats.receive', function (data) {
module.onChatMessageReceived = function (data) {
var username = data.message.fromUser.username; var username = data.message.fromUser.username;
var isSelf = data.self === 1; var isSelf = data.self === 1;
data.message.self = data.self; data.message.self = data.self;
newMessage = data.self === 0; newMessage = data.self === 0;
if (module.modalExists(data.roomId)) { if (module.modalExists(data.roomId)) {
require(['forum/chats/messages'], function (ChatsMessages) {
var modal = module.getModal(data.roomId); var modal = module.getModal(data.roomId);
ChatsMessages.appendChatMessage(modal.find('.chat-content'), data.message); ChatsMessages.appendChatMessage(modal.find('.chat-content'), data.message);
@ -71,15 +68,14 @@ define('chat', [
} }
if (!isSelf && (!modal.is(':visible') || !app.isFocused)) { if (!isSelf && (!modal.is(':visible') || !app.isFocused)) {
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]'); updateTitleAndPlaySound(data.message.mid, username);
sounds.play('chat-incoming', 'chat.incoming:' + data.message.mid);
taskbar.push('chat', modal.attr('data-uuid'), { taskbar.push('chat', modal.attr('data-uuid'), {
title: '[[modules:chat.chatting_with]] ' + (data.roomName || username), title: '[[modules:chat.chatting_with]] ' + (data.roomName || username),
touid: data.message.fromUser.uid, touid: data.message.fromUser.uid,
roomId: data.roomId, roomId: data.roomId,
}); });
} }
});
} else if (!ajaxify.data.template.chats) { } else if (!ajaxify.data.template.chats) {
socket.emit('modules.chats.loadRoom', { socket.emit('modules.chats.loadRoom', {
roomId: data.roomId, roomId: data.roomId,
@ -96,52 +92,30 @@ define('chat', [
module.createModal(roomData, function (modal) { module.createModal(roomData, function (modal) {
module.toggleNew(modal.attr('data-uuid'), !isSelf, true); module.toggleNew(modal.attr('data-uuid'), !isSelf, true);
if (!isSelf) { if (!isSelf) {
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]'); updateTitleAndPlaySound(data.message.mid, username);
sounds.play('chat-incoming', 'chat.incoming:' + data.message.mid);
} }
}); });
}); });
} }
};
function updateTitleAndPlaySound(mid, username) {
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
require(['sounds'], function (sounds) {
sounds.play('chat-incoming', 'chat.incoming:' + mid);
}); });
}
socket.on('event:user_status_change', function (data) { module.onUserStatusChange = function (data) {
var modal = module.getModal(data.uid); var modal = module.getModal(data.uid);
app.updateUserStatus(modal.find('[component="user/status"]'), data.status); app.updateUserStatus(modal.find('[component="user/status"]'), data.status);
}); };
socket.on('event:chats.roomRename', function (data) { module.onRoomRename = function (data) {
var newTitle = $('<div/>').html(data.newName).text(); var newTitle = $('<div/>').html(data.newName).text();
var modal = module.getModal(data.roomId); var modal = module.getModal(data.roomId);
modal.find('[component="chat/room/name"]').text(newTitle); modal.find('[component="chat/room/name"]').text(newTitle);
taskbar.updateTitle('chat', modal.attr('data-uuid'), newTitle); taskbar.updateTitle('chat', modal.attr('data-uuid'), newTitle);
});
ChatsMessages.onChatMessageEdit();
};
module.loadChatsDropdown = function (chatsListEl) {
socket.emit('modules.chats.getRecentChats', {
uid: app.user.uid,
after: 0,
}, function (err, data) {
if (err) {
return app.alertError(err.message);
}
var rooms = data.rooms.filter(function (room) {
return room.teaser;
});
Benchpress.parse('partials/chats/dropdown', {
rooms: rooms,
}, function (html) {
translator.translate(html, function (translated) {
chatsListEl.find('*').not('.navigation-link').remove();
chatsListEl.prepend(translated);
app.createUserTooltips(chatsListEl, 'right');
});
});
});
}; };
module.getModal = function (roomId) { module.getModal = function (roomId) {
@ -153,6 +127,7 @@ define('chat', [
}; };
module.createModal = function (data, callback) { module.createModal = function (data, callback) {
require(['scrollStop', 'forum/chats', 'forum/chats/messages'], function (scrollStop, Chats, ChatsMessages) {
app.parseAndTranslate('chat', data, function (chatModal) { app.parseAndTranslate('chat', data, function (chatModal) {
var uuid = utils.generateUUID(); var uuid = utils.generateUUID();
var dragged = false; var dragged = false;
@ -249,6 +224,7 @@ define('chat', [
Chats.addCharactersLeftHandler(chatModal); Chats.addCharactersLeftHandler(chatModal);
Chats.addIPHandler(chatModal); Chats.addIPHandler(chatModal);
ChatsMessages.onChatMessageEdit();
taskbar.push('chat', chatModal.attr('data-uuid'), { taskbar.push('chat', chatModal.attr('data-uuid'), {
title: '[[modules:chat.chatting_with]] ' + (data.roomName || (data.users.length ? data.users[0].username : '')), title: '[[modules:chat.chatting_with]] ' + (data.roomName || (data.users.length ? data.users[0].username : '')),
@ -263,6 +239,7 @@ define('chat', [
callback(chatModal); callback(chatModal);
} }
}); });
});
}; };
module.focusInput = function (chatModal) { module.focusInput = function (chatModal) {
@ -297,6 +274,7 @@ define('chat', [
}; };
module.load = function (uuid) { module.load = function (uuid) {
require(['forum/chats/messages'], function (ChatsMessages) {
var chatModal = $('.chat-modal[data-uuid="' + uuid + '"]'); var chatModal = $('.chat-modal[data-uuid="' + uuid + '"]');
chatModal.removeClass('hide'); chatModal.removeClass('hide');
taskbar.updateActive(uuid); taskbar.updateActive(uuid);
@ -308,6 +286,7 @@ define('chat', [
if (env === 'xs' || env === 'sm') { if (env === 'xs' || env === 'sm') {
module.enableMobileBehaviour(chatModal); module.enableMobileBehaviour(chatModal);
} }
});
}; };
module.enableMobileBehaviour = function (modalEl) { module.enableMobileBehaviour = function (modalEl) {
@ -340,6 +319,5 @@ define('chat', [
module.toggleNew = taskbar.toggleNew; module.toggleNew = taskbar.toggleNew;
return module; return module;
}); });

@ -1,14 +1,14 @@
'use strict'; 'use strict';
define('flags', ['benchpress'], function (Benchpress) { define('flags', function () {
var Flag = {}; var Flag = {};
var flagModal; var flagModal;
var flagCommit; var flagCommit;
var flagReason; var flagReason;
Flag.showFlagModal = function (data) { Flag.showFlagModal = function (data) {
parseModal(data, function (html) { app.parseAndTranslate('partials/modals/flag_modal', data, function (html) {
flagModal = $(html); flagModal = $(html);
flagModal.on('hidden.bs.modal', function () { flagModal.on('hidden.bs.modal', function () {
@ -54,14 +54,6 @@ define('flags', ['benchpress'], function (Benchpress) {
}); });
}; };
function parseModal(tplData, callback) {
Benchpress.parse('partials/modals/flag_modal', tplData, function (html) {
require(['translator'], function (translator) {
translator.translate(html, callback);
});
});
}
function createFlag(type, id, reason) { function createFlag(type, id, reason) {
if (!type || !id || !reason) { if (!type || !id || !reason) {
return; return;

@ -6,31 +6,29 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
var unreadNotifs = {}; var unreadNotifs = {};
Notifications.prepareDOM = function () { Notifications.loadNotifications = function (notifList) {
var notifContainer = components.get('notifications'); socket.emit('notifications.get', null, function (err, data) {
var notifTrigger = notifContainer.children('a'); if (err) {
var notifList = components.get('notifications/list'); return app.alertError(err.message);
var notifDropdownWrapper = notifTrigger.parents('.dropdown');
notifTrigger.on('click', function (e) {
e.preventDefault();
if (notifContainer.hasClass('open')) {
return;
} }
Notifications.loadNotifications(notifList); var notifs = data.unread.concat(data.read).sort(function (a, b) {
return parseInt(a.datetime, 10) > parseInt(b.datetime, 10) ? -1 : 1;
}); });
if (notifDropdownWrapper.hasClass('open')) { translator.toggleTimeagoShorthand(function () {
Notifications.loadNotifications(notifList); for (var i = 0; i < notifs.length; i += 1) {
notifs[i].timeago = $.timeago(new Date(parseInt(notifs[i].datetime, 10)));
} }
translator.toggleTimeagoShorthand();
notifList.on('click', '[data-nid]', function (ev) { Benchpress.parse('partials/notifications_list', { notifications: notifs }, function (html) {
notifList.translateHtml(html);
notifList.off('click').on('click', '[data-nid]', function (ev) {
var notifEl = $(this); var notifEl = $(this);
if (scrollToPostIndexIfOnPage(notifEl)) { if (scrollToPostIndexIfOnPage(notifEl)) {
ev.stopPropagation(); ev.stopPropagation();
ev.preventDefault(); ev.preventDefault();
notifTrigger.dropdown('toggle'); components.get('notifications/list').dropdown('toggle');
} }
var unread = notifEl.hasClass('unread'); var unread = notifEl.hasClass('unread');
@ -40,8 +38,7 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
var nid = notifEl.attr('data-nid'); var nid = notifEl.attr('data-nid');
markNotification(nid, true); markNotification(nid, true);
}); });
components.get('notifications').on('click', '.mark-all-read', Notifications.markAllRead);
notifContainer.on('click', '.mark-all-read', Notifications.markAllRead);
notifList.on('click', '.mark-read', function () { notifList.on('click', '.mark-read', function () {
var liEl = $(this).parent(); var liEl = $(this).parent();
@ -52,8 +49,12 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
}); });
return false; return false;
}); });
});
});
});
};
socket.on('event:new_notification', function (notifData) { Notifications.onNewNotification = function (notifData) {
// If a path is defined, show notif data, otherwise show generic data // If a path is defined, show notif data, otherwise show generic data
var payload = { var payload = {
alert_id: 'new_notif', alert_id: 'new_notif',
@ -96,11 +97,6 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
sounds.play('notification', notifData.nid); sounds.play('notification', notifData.nid);
unreadNotifs[notifData.nid] = true; unreadNotifs[notifData.nid] = true;
} }
});
socket.on('event:notifications.updateCount', function (count) {
Notifications.updateNotifCount(count);
});
}; };
function markNotification(nid, read, callback) { function markNotification(nid, read, callback) {
@ -130,28 +126,6 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
return false; return false;
} }
Notifications.loadNotifications = function (notifList) {
socket.emit('notifications.get', null, function (err, data) {
if (err) {
return app.alertError(err.message);
}
var notifs = data.unread.concat(data.read).sort(function (a, b) {
return parseInt(a.datetime, 10) > parseInt(b.datetime, 10) ? -1 : 1;
});
translator.toggleTimeagoShorthand(function () {
for (var i = 0; i < notifs.length; i += 1) {
notifs[i].timeago = $.timeago(new Date(parseInt(notifs[i].datetime, 10)));
}
translator.toggleTimeagoShorthand();
Benchpress.parse('partials/notifications_list', { notifications: notifs }, function (html) {
notifList.translateHtml(html);
});
});
});
};
Notifications.updateNotifCount = function (count) { Notifications.updateNotifCount = function (count) {
var notifIcon = components.get('notifications/icon'); var notifIcon = components.get('notifications/icon');
count = Math.max(0, count); count = Math.max(0, count);

@ -42,18 +42,17 @@ JS.scripts = {
// files listed below are only available client-side, or are bundled in to reduce # of network requests on cold load // files listed below are only available client-side, or are bundled in to reduce # of network requests on cold load
rjs: [ rjs: [
'public/src/client/footer.js', 'public/src/client/footer.js',
'public/src/client/chats.js', 'public/src/client/header/chat.js',
'public/src/client/header/notifications.js',
'public/src/client/infinitescroll.js', 'public/src/client/infinitescroll.js',
'public/src/client/pagination.js', 'public/src/client/pagination.js',
'public/src/client/recent.js', 'public/src/client/recent.js',
'public/src/client/unread.js', 'public/src/client/unread.js',
'public/src/client/topic.js', 'public/src/client/topic.js',
'public/src/client/topic/events.js', 'public/src/client/topic/events.js',
'public/src/client/topic/merge.js',
'public/src/client/topic/fork.js',
'public/src/client/topic/move.js',
'public/src/client/topic/posts.js', 'public/src/client/topic/posts.js',
'public/src/client/topic/images.js', 'public/src/client/topic/images.js',
'public/src/client/topic/votes.js',
'public/src/client/topic/postTools.js', 'public/src/client/topic/postTools.js',
'public/src/client/topic/threadTools.js', 'public/src/client/topic/threadTools.js',
'public/src/client/categories.js', 'public/src/client/categories.js',
@ -61,8 +60,6 @@ JS.scripts = {
'public/src/client/category/tools.js', 'public/src/client/category/tools.js',
'public/src/modules/translator.js', 'public/src/modules/translator.js',
'public/src/modules/notifications.js',
'public/src/modules/chat.js',
'public/src/modules/components.js', 'public/src/modules/components.js',
'public/src/modules/sort.js', 'public/src/modules/sort.js',
'public/src/modules/navigator.js', 'public/src/modules/navigator.js',
@ -74,7 +71,6 @@ JS.scripts = {
'public/src/modules/alerts.js', 'public/src/modules/alerts.js',
'public/src/modules/taskbar.js', 'public/src/modules/taskbar.js',
'public/src/modules/helpers.js', 'public/src/modules/helpers.js',
'public/src/modules/flags.js',
'public/src/modules/storage.js', 'public/src/modules/storage.js',
'public/src/modules/handleBack.js', 'public/src/modules/handleBack.js',
], ],

Loading…
Cancel
Save