mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-26 16:41:21 +01:00
feat: load timeago strings client-side
9adaccd036 introduced the ability to
configure an assetBaseUrl, but the timeago strings were still
calling a hardcoded value as it was handled server-side. There's
no need for the strings to be loaded until timeago is initialised.
This commit is contained in:
@@ -252,7 +252,11 @@ app.cacheBuster = null;
|
|||||||
app.processPage = function () {
|
app.processPage = function () {
|
||||||
highlightNavigationLink();
|
highlightNavigationLink();
|
||||||
|
|
||||||
$('.timeago').timeago();
|
app.initTimeago().then(function () {
|
||||||
|
$('.timeago').timeago();
|
||||||
|
}, function () {
|
||||||
|
console.warn('[timeago] Unable to retrieve ' + config.userLang + ' strings, falling back to English');
|
||||||
|
});
|
||||||
|
|
||||||
utils.makeNumbersHumanReadable($('.human-readable-number'));
|
utils.makeNumbersHumanReadable($('.human-readable-number'));
|
||||||
|
|
||||||
@@ -268,6 +272,21 @@ app.cacheBuster = null;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.initTimeago = function () {
|
||||||
|
// Loads strings based on user language, if not already loaded
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
if (app.flags._timeago) {
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
var pathToLocaleFile = '/vendor/jquery/timeago/locales/jquery.timeago.' + utils.userLangToTimeagoCode(config.userLang) + '.js';
|
||||||
|
$.getScript(config.assetBaseUrl + pathToLocaleFile).done(function () {
|
||||||
|
app.flags._timeago = true;
|
||||||
|
resolve();
|
||||||
|
}).fail(reject);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
app.showMessages = function () {
|
app.showMessages = function () {
|
||||||
var messages = {
|
var messages = {
|
||||||
login: {
|
login: {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ var plugins = require('../plugins');
|
|||||||
var navigation = require('../navigation');
|
var navigation = require('../navigation');
|
||||||
var translator = require('../translator');
|
var translator = require('../translator');
|
||||||
var privileges = require('../privileges');
|
var privileges = require('../privileges');
|
||||||
var languages = require('../languages');
|
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
var helpers = require('./helpers');
|
var helpers = require('./helpers');
|
||||||
|
|
||||||
@@ -188,25 +187,8 @@ module.exports = function (middleware) {
|
|||||||
templateValues: templateValues,
|
templateValues: templateValues,
|
||||||
});
|
});
|
||||||
|
|
||||||
const results = await utils.promiseParallel({
|
const scripts = await plugins.fireHook('filter:scripts.get', []);
|
||||||
scripts: plugins.fireHook('filter:scripts.get', []),
|
data.templateValues.scripts = scripts.map(function (script) {
|
||||||
timeagoLocale: (async () => {
|
|
||||||
const languageCodes = await languages.listCodes();
|
|
||||||
const userLang = res.locals.config.userLang;
|
|
||||||
const timeagoCode = utils.userLangToTimeagoCode(userLang);
|
|
||||||
|
|
||||||
if (languageCodes.includes(userLang) && languages.timeagoCodes.includes(timeagoCode)) {
|
|
||||||
const pathToLocaleFile = '/vendor/jquery/timeago/locales/jquery.timeago.' + timeagoCode + '.js';
|
|
||||||
return nconf.get('relative_path') + '/assets' + pathToLocaleFile;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
})(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (results.timeagoLocale) {
|
|
||||||
results.scripts.push(results.timeagoLocale);
|
|
||||||
}
|
|
||||||
data.templateValues.scripts = results.scripts.map(function (script) {
|
|
||||||
return { src: script };
|
return { src: script };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user