mirror of
https://github.com/discourse/discourse.git
synced 2025-03-29 06:46:39 +08:00

* FIX: Add aria-labels to topic list items Before this fix you could navigate the topic list using a screen reader and a keyboard but some of the items were not as descriptive as they could be. The newly added labels make it easier to understand what you are tabbing over. context: https://meta.discourse.org/t/accessibility-aria-attributes-are-not-defined-for-links-under-replies-category/142539 * Update app/assets/javascripts/discourse/lib/utilities.js.es6 Co-Authored-By: Régis Hanol <regis@hanol.fr> * Multiline fix * Fix more tests Co-authored-by: Régis Hanol <regis@hanol.fr>
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import { registerUnbound } from "discourse-common/lib/helpers";
|
|
import {
|
|
longDate,
|
|
autoUpdatingRelativeAge,
|
|
number
|
|
} from "discourse/lib/formatter";
|
|
|
|
const safe = Handlebars.SafeString;
|
|
|
|
registerUnbound("raw-date", dt => longDate(new Date(dt)));
|
|
|
|
registerUnbound(
|
|
"age-with-tooltip",
|
|
dt => new safe(autoUpdatingRelativeAge(new Date(dt), { title: true }))
|
|
);
|
|
|
|
registerUnbound("number", (orig, params) => {
|
|
orig = Math.round(parseFloat(orig));
|
|
if (isNaN(orig)) {
|
|
orig = 0;
|
|
}
|
|
|
|
let title = I18n.toNumber(orig, { precision: 0 });
|
|
if (params.numberKey) {
|
|
title = I18n.t(params.numberKey, {
|
|
number: title,
|
|
count: parseInt(orig, 10)
|
|
});
|
|
}
|
|
|
|
let classNames = "number";
|
|
if (params["class"]) {
|
|
classNames += " " + params["class"];
|
|
}
|
|
|
|
let result = "<span class='" + classNames + "'";
|
|
let addTitle = params.noTitle ? false : true;
|
|
|
|
// Round off the thousands to one decimal place
|
|
const n = number(orig);
|
|
if (n.toString() !== title.toString() && addTitle) {
|
|
result += " title='" + Handlebars.Utils.escapeExpression(title) + "'";
|
|
}
|
|
if (params.ariaLabel) {
|
|
const ariaLabel = Handlebars.Utils.escapeExpression(params.ariaLabel);
|
|
result += ` aria-label='${ariaLabel}'`;
|
|
}
|
|
|
|
result += ">" + n + "</span>";
|
|
|
|
return new safe(result);
|
|
});
|