reduce initial js payload/requests
parent
0fd5210d37
commit
c02d584b53
@ -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;
|
||||
});
|
Loading…
Reference in New Issue