mirror of
https://github.com/flarum/core.git
synced 2025-08-08 01:16:52 +02:00
chore: improve group mentions parsing (#3723)
* chore: improve group mentions color handling * Avoid storing the `GroupMention--dark` and light classes on the database. * Avoid recreating YIQ logic on the backend. * Improve text color flexibility through CSS variables. * Apply fixes from StyleCI * chore: tweak tests * chre: unused import Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
@@ -2,6 +2,8 @@ import { extend } from 'flarum/common/extend';
|
||||
import app from 'flarum/forum/app';
|
||||
import NotificationGrid from 'flarum/forum/components/NotificationGrid';
|
||||
import { getPlainContent } from 'flarum/common/utils/string';
|
||||
import textContrastClass from 'flarum/common/helpers/textContrastClass';
|
||||
import Post from 'flarum/forum/components/Post';
|
||||
|
||||
import addPostMentionPreviews from './addPostMentionPreviews';
|
||||
import addMentionedByList from './addMentionedByList';
|
||||
@@ -84,6 +86,13 @@ app.initializers.add('flarum-mentions', function () {
|
||||
|
||||
// Remove post mentions when rendering post previews.
|
||||
getPlainContent.removeSelectors.push('a.PostMention');
|
||||
|
||||
// Apply color contrast fix on group mentions.
|
||||
extend(Post.prototype, 'oncreate', function () {
|
||||
this.$('.GroupMention--colored').each(function () {
|
||||
this.classList.add(textContrastClass(getComputedStyle(this).getPropertyValue('--group-color')));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
export * from './utils/textFormatter';
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import app from 'flarum/forum/app';
|
||||
import username from 'flarum/common/helpers/username';
|
||||
import extractText from 'flarum/common/utils/extractText';
|
||||
import isDark from 'flarum/common/utils/isDark';
|
||||
|
||||
export function filterUserMentions(tag) {
|
||||
let user;
|
||||
@@ -41,7 +40,6 @@ export function filterGroupMentions(tag) {
|
||||
tag.setAttribute('groupname', extractText(group.namePlural()));
|
||||
tag.setAttribute('icon', group.icon());
|
||||
tag.setAttribute('color', group.color());
|
||||
tag.setAttribute('class', isDark(group.color()) ? 'GroupMention--light' : 'GroupMention--dark');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user