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

@ -124,7 +124,11 @@ define('forum/chats/messages', ['components', 'sounds', 'translator', 'benchpres
};
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) {
var self = parseInt(message.fromuid, 10) === parseInt(app.user.uid, 10);
message.self = self ? 1 : 0;
@ -136,8 +140,7 @@ define('forum/chats/messages', ['components', 'sounds', 'translator', 'benchpres
}
});
});
});
};
}
messages.delete = function (messageId, roomId) {
translator.translate('[[modules:chat.delete_message_confirm]]', function (translated) {

@ -1,7 +1,12 @@
'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();
Chat.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 () {
socket.emit('notifications.markAllRead', function (err) {
if (err) {

@ -8,12 +8,11 @@ define('forum/topic', [
'forum/topic/events',
'forum/topic/posts',
'forum/topic/images',
'forum/topic/replies',
'navigator',
'sort',
'components',
'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 currentUrl = '';
@ -49,7 +48,6 @@ define('forum/topic', [
postTools.init(tid);
threadTools.init(tid);
replies.init(tid);
events.init();
sort.handleSort('topicPostSort', 'user.setTopicSort', 'topic/' + ajaxify.data.slug);
@ -61,6 +59,7 @@ define('forum/topic', [
addBlockQuoteHandler();
addParentHandler();
addDropupHandler();
addRepliesHandler();
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() {
var span = components.get('navbar/title').find('span');
if ($(window).scrollTop() > 50 && span.hasClass('hidden')) {

@ -10,18 +10,9 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function (compo
DeletePosts.init = function () {
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() {
if (ajaxify.data.template.name !== 'topic' || ajaxify.data.tid !== tid) {
closeModal();
$(window).off('action:ajaxify.end', onAjaxifyEnd);
}
}
$(window).off('action:ajaxify.end', onAjaxifyEnd).on('action:ajaxify.end', onAjaxifyEnd);
function onDeletePostsClicked() {
if (modal) {
return;
}
@ -49,6 +40,13 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function (compo
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) {

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

@ -9,10 +9,6 @@ define('forum/topic/merge', function () {
var selectedTids = {};
Merge.init = function () {
$('.category').on('click', '[component="topic/merge"]', onMergeTopicsClicked);
};
function onMergeTopicsClicked() {
if (modal) {
return;
}
@ -33,7 +29,7 @@ define('forum/topic/merge', function () {
mergeTopics(mergeBtn);
});
});
}
};
function onTopicClicked(ev) {
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 moveCommit;
MovePost.init = function () {
$('.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) {
MovePost.init = function (postEl) {
if (moveModal) {
return;
}
@ -40,7 +16,7 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen
moveCommit = moveModal.find('#move_posts_confirm');
$(document.body).append(moveModal);
$('body').append(moveModal);
moveModal.find('.close,#move_posts_cancel').on('click', closeMoveModal);
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() {
checkMoveButtonEnable();
showPostsSelected();

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

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

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

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

@ -1,14 +1,14 @@
'use strict';
define('flags', ['benchpress'], function (Benchpress) {
define('flags', function () {
var Flag = {};
var flagModal;
var flagCommit;
var flagReason;
Flag.showFlagModal = function (data) {
parseModal(data, function (html) {
app.parseAndTranslate('partials/modals/flag_modal', data, function (html) {
flagModal = $(html);
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) {
if (!type || !id || !reason) {
return;

@ -6,31 +6,29 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
var unreadNotifs = {};
Notifications.prepareDOM = function () {
var notifContainer = components.get('notifications');
var notifTrigger = notifContainer.children('a');
var notifList = components.get('notifications/list');
var notifDropdownWrapper = notifTrigger.parents('.dropdown');
notifTrigger.on('click', function (e) {
e.preventDefault();
if (notifContainer.hasClass('open')) {
return;
Notifications.loadNotifications = function (notifList) {
socket.emit('notifications.get', null, function (err, data) {
if (err) {
return app.alertError(err.message);
}
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')) {
Notifications.loadNotifications(notifList);
translator.toggleTimeagoShorthand(function () {
for (var i = 0; i < notifs.length; i += 1) {
notifs[i].timeago = $.timeago(new Date(parseInt(notifs[i].datetime, 10)));
}
notifList.on('click', '[data-nid]', function (ev) {
translator.toggleTimeagoShorthand();
Benchpress.parse('partials/notifications_list', { notifications: notifs }, function (html) {
notifList.translateHtml(html);
notifList.off('click').on('click', '[data-nid]', function (ev) {
var notifEl = $(this);
if (scrollToPostIndexIfOnPage(notifEl)) {
ev.stopPropagation();
ev.preventDefault();
notifTrigger.dropdown('toggle');
components.get('notifications/list').dropdown('toggle');
}
var unread = notifEl.hasClass('unread');
@ -40,8 +38,7 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
var nid = notifEl.attr('data-nid');
markNotification(nid, true);
});
notifContainer.on('click', '.mark-all-read', Notifications.markAllRead);
components.get('notifications').on('click', '.mark-all-read', Notifications.markAllRead);
notifList.on('click', '.mark-read', function () {
var liEl = $(this).parent();
@ -52,8 +49,12 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
});
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
var payload = {
alert_id: 'new_notif',
@ -96,11 +97,6 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
sounds.play('notification', notifData.nid);
unreadNotifs[notifData.nid] = true;
}
});
socket.on('event:notifications.updateCount', function (count) {
Notifications.updateNotifCount(count);
});
};
function markNotification(nid, read, callback) {
@ -130,28 +126,6 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
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) {
var notifIcon = components.get('notifications/icon');
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
rjs: [
'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/pagination.js',
'public/src/client/recent.js',
'public/src/client/unread.js',
'public/src/client/topic.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/images.js',
'public/src/client/topic/votes.js',
'public/src/client/topic/postTools.js',
'public/src/client/topic/threadTools.js',
'public/src/client/categories.js',
@ -61,8 +60,6 @@ JS.scripts = {
'public/src/client/category/tools.js',
'public/src/modules/translator.js',
'public/src/modules/notifications.js',
'public/src/modules/chat.js',
'public/src/modules/components.js',
'public/src/modules/sort.js',
'public/src/modules/navigator.js',
@ -74,7 +71,6 @@ JS.scripts = {
'public/src/modules/alerts.js',
'public/src/modules/taskbar.js',
'public/src/modules/helpers.js',
'public/src/modules/flags.js',
'public/src/modules/storage.js',
'public/src/modules/handleBack.js',
],

Loading…
Cancel
Save