feat: #8734, jquery-ui, jquery-form, timeago (#8748)

* feat: #8734, jquery-ui, jquery-form, timeago

get rid of forum/footer.js move that code to app.js & wait for app to load before calling ajaxify.end
make sockets.js a requirejs module
move jquery-ui to node_modules and load via requirejs
move jquery-form to node_modules and load via requirejs
move timeago to node_modules and load via requirejs
only include the css for needed jquery-ui widgets

* feat: keep socket/io global for backwards compat

* refactor: move socket listener to chat
This commit is contained in:
Barış Soner Uşaklı
2020-10-10 21:47:27 -04:00
committed by GitHub
parent 666064bf46
commit fda2aedfd8
100 changed files with 98 additions and 2702 deletions

View File

@@ -10,6 +10,7 @@ app.flags = {};
app.cacheBuster = null;
(function () {
var appLoaded = false;
var params = utils.params();
var showWelcomeMessage = !!params.loggedin;
var registerMessage = params.register;
@@ -26,6 +27,16 @@ app.cacheBuster = null;
app.load();
});
app.coldLoad = function () {
if (appLoaded) {
ajaxify.coldLoad();
} else {
$(window).on('action:app.load', function () {
ajaxify.coldLoad();
});
}
};
app.handleEarlyClicks = function () {
/**
* Occasionally, a button or anchor (not meant to be ajaxified) is clicked before
@@ -61,8 +72,6 @@ app.cacheBuster = null;
app.handleEarlyClicks();
app.load = function () {
overrides.overrideTimeago();
handleStatusChange();
if (config.searchEnabled) {
@@ -88,14 +97,38 @@ app.cacheBuster = null;
app.showCookieWarning();
registerServiceWorker();
require(['taskbar', 'helpers', 'forum/pagination'], function (taskbar, helpers, pagination) {
require([
'taskbar',
'helpers',
'forum/pagination',
'translator',
'forum/unread',
'forum/header/notifications',
'forum/header/chat',
'timeago/jquery.timeago',
'jquery-form',
], function (taskbar, helpers, pagination, translator, unread, notifications, chat) {
notifications.prepareDOM();
chat.prepareDOM();
translator.prepareDOM();
taskbar.init();
helpers.register();
pagination.init();
$(window).trigger('action:app.load');
if (app.user.uid > 0) {
unread.initUnreadTopics();
}
overrides.overrideTimeago();
if (app.user.timeagoCode && app.user.timeagoCode !== 'en') {
require(['timeago/locales/jquery.timeago.' + app.user.timeagoCode], function () {
$(window).trigger('action:app.load');
appLoaded = true;
});
} else {
$(window).trigger('action:app.load');
appLoaded = true;
}
});
};
@@ -657,12 +690,15 @@ app.cacheBuster = null;
if (typeof $().autocomplete === 'function') {
return callback();
}
var scriptEl = document.createElement('script');
scriptEl.type = 'text/javascript';
scriptEl.src = config.relative_path + '/assets/vendor/jquery/js/jquery-ui.js?' + config['cache-buster'];
scriptEl.onload = callback;
document.head.appendChild(scriptEl);
require([
'jquery-ui/widgets/datepicker',
'jquery-ui/widgets/autocomplete',
'jquery-ui/widgets/sortable',
'jquery-ui/widgets/resizable',
'jquery-ui/widgets/draggable',
], function () {
callback();
});
};
app.showEmailConfirmWarning = function (err) {

View File

@@ -91,7 +91,11 @@ define('forum/account/settings', ['forum/account/header', 'components', 'transla
htmlEl.attr('data-dir', translated);
htmlEl.css('direction', translated);
});
$.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + utils.userLangToTimeagoCode(config.userLang) + '.js', function () {
var stringsModule = 'timeago/locales/jquery.timeago.' + utils.userLangToTimeagoCode(config.userLang);
// without undef, requirejs won't load the strings a second time
require.undef(stringsModule);
require([stringsModule], function () {
overrides.overrideTimeago();
ajaxify.refresh();
});

View File

@@ -1,24 +0,0 @@
'use strict';
define('forum/footer', [
'components',
'translator',
'forum/unread',
'forum/header/notifications',
'forum/header/chat',
], function (components, translator, Unread, Notifications, Chat) {
Notifications.prepareDOM();
Chat.prepareDOM();
translator.prepareDOM();
socket.on('event:unread.updateChatCount', function (count) {
components.get('chat/icon')
.toggleClass('unread-count', count > 0)
.attr('data-content', count > 99 ? '99+' : count);
});
if (app.user.uid > 0) {
Unread.initUnreadTopics();
}
});

View File

@@ -26,6 +26,12 @@ define('forum/header/chat', ['components'], function (components) {
socket.removeListener('event:chats.roomRename', onRoomRename);
socket.on('event:chats.roomRename', onRoomRename);
socket.on('event:unread.updateChatCount', function (count) {
components.get('chat/icon')
.toggleClass('unread-count', count > 0)
.attr('data-content', count > 99 ? '99+' : count);
});
};
function onChatMessageReceived(data) {